aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/mei
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2012-12-25 12:06:10 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-01-07 13:31:29 -0500
commite46f187487a8c28e64417e51ba628746a5397838 (patch)
tree484cc0102c738d7aae646822baabd71ad715eaf9 /drivers/misc/mei
parentcd51ed649fa4bd55c6a78db52b57260797ed56b4 (diff)
mei: use structured buffer for the write buffer
We can drop useless castings and use proper types. We remove the casting in mei_hbm_hdr function and add new function mei_hbm_stop_request_prepare that utilize the new structure 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/amthif.c25
-rw-r--r--drivers/misc/mei/hbm.c134
-rw-r--r--drivers/misc/mei/interrupt.c25
-rw-r--r--drivers/misc/mei/mei_dev.h12
-rw-r--r--drivers/misc/mei/wd.c17
5 files changed, 108 insertions, 105 deletions
diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c
index bb613f733309..f9d458cced21 100644
--- a/drivers/misc/mei/amthif.c
+++ b/drivers/misc/mei/amthif.c
@@ -432,34 +432,33 @@ unsigned int mei_amthif_poll(struct mei_device *dev,
432int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots, 432int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
433 struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list) 433 struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list)
434{ 434{
435 struct mei_msg_hdr *mei_hdr; 435 struct mei_msg_hdr mei_hdr;
436 struct mei_cl *cl = cb->cl; 436 struct mei_cl *cl = cb->cl;
437 size_t len = dev->iamthif_msg_buf_size - dev->iamthif_msg_buf_index; 437 size_t len = dev->iamthif_msg_buf_size - dev->iamthif_msg_buf_index;
438 size_t msg_slots = mei_data2slots(len); 438 size_t msg_slots = mei_data2slots(len);
439 439
440 mei_hdr = (struct mei_msg_hdr *)&dev->wr_msg_buf[0]; 440 mei_hdr.host_addr = cl->host_client_id;
441 mei_hdr->host_addr = cl->host_client_id; 441 mei_hdr.me_addr = cl->me_client_id;
442 mei_hdr->me_addr = cl->me_client_id; 442 mei_hdr.reserved = 0;
443 mei_hdr->reserved = 0;
444 443
445 if (*slots >= msg_slots) { 444 if (*slots >= msg_slots) {
446 mei_hdr->length = len; 445 mei_hdr.length = len;
447 mei_hdr->msg_complete = 1; 446 mei_hdr.msg_complete = 1;
448 /* Split the message only if we can write the whole host buffer */ 447 /* Split the message only if we can write the whole host buffer */
449 } else if (*slots == dev->hbuf_depth) { 448 } else if (*slots == dev->hbuf_depth) {
450 msg_slots = *slots; 449 msg_slots = *slots;
451 len = (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr); 450 len = (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
452 mei_hdr->length = len; 451 mei_hdr.length = len;
453 mei_hdr->msg_complete = 0; 452 mei_hdr.msg_complete = 0;
454 } else { 453 } else {
455 /* wait for next time the host buffer is empty */ 454 /* wait for next time the host buffer is empty */
456 return 0; 455 return 0;
457 } 456 }
458 457
459 dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr)); 458 dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(&mei_hdr));
460 459
461 *slots -= msg_slots; 460 *slots -= msg_slots;
462 if (mei_write_message(dev, mei_hdr, 461 if (mei_write_message(dev, &mei_hdr,
463 dev->iamthif_msg_buf + dev->iamthif_msg_buf_index)) { 462 dev->iamthif_msg_buf + dev->iamthif_msg_buf_index)) {
464 dev->iamthif_state = MEI_IAMTHIF_IDLE; 463 dev->iamthif_state = MEI_IAMTHIF_IDLE;
465 cl->status = -ENODEV; 464 cl->status = -ENODEV;
@@ -470,10 +469,10 @@ int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
470 if (mei_flow_ctrl_reduce(dev, cl)) 469 if (mei_flow_ctrl_reduce(dev, cl))
471 return -ENODEV; 470 return -ENODEV;
472 471
473 dev->iamthif_msg_buf_index += mei_hdr->length; 472 dev->iamthif_msg_buf_index += mei_hdr.length;
474 cl->status = 0; 473 cl->status = 0;
475 474
476 if (mei_hdr->msg_complete) { 475 if (mei_hdr.msg_complete) {
477 dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL; 476 dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL;
478 dev->iamthif_flow_control_pending = true; 477 dev->iamthif_flow_control_pending = true;
479 478
diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c
index bc36c23cd2db..e9ba51d5a46c 100644
--- a/drivers/misc/mei/hbm.c
+++ b/drivers/misc/mei/hbm.c
@@ -67,21 +67,21 @@ bool mei_hbm_cl_addr_equal(struct mei_cl *cl, void *buf)
67 */ 67 */
68void mei_host_start_message(struct mei_device *dev) 68void mei_host_start_message(struct mei_device *dev)
69{ 69{
70 struct mei_msg_hdr *mei_hdr; 70 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
71 struct hbm_host_version_request *start_req; 71 struct hbm_host_version_request *start_req;
72 const size_t len = sizeof(struct hbm_host_version_request); 72 const size_t len = sizeof(struct hbm_host_version_request);
73 73
74 mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 74 mei_hbm_hdr(mei_hdr, len);
75 75
76 /* host start message */ 76 /* host start message */
77 start_req = (struct hbm_host_version_request *)&dev->wr_msg_buf[1]; 77 start_req = (struct hbm_host_version_request *)dev->wr_msg.data;
78 memset(start_req, 0, len); 78 memset(start_req, 0, len);
79 start_req->hbm_cmd = HOST_START_REQ_CMD; 79 start_req->hbm_cmd = HOST_START_REQ_CMD;
80 start_req->host_version.major_version = HBM_MAJOR_VERSION; 80 start_req->host_version.major_version = HBM_MAJOR_VERSION;
81 start_req->host_version.minor_version = HBM_MINOR_VERSION; 81 start_req->host_version.minor_version = HBM_MINOR_VERSION;
82 82
83 dev->recvd_msg = false; 83 dev->recvd_msg = false;
84 if (mei_write_message(dev, mei_hdr, (unsigned char *)start_req)) { 84 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
85 dev_dbg(&dev->pdev->dev, "write send version message to FW fail.\n"); 85 dev_dbg(&dev->pdev->dev, "write send version message to FW fail.\n");
86 dev->dev_state = MEI_DEV_RESETING; 86 dev->dev_state = MEI_DEV_RESETING;
87 mei_reset(dev, 1); 87 mei_reset(dev, 1);
@@ -100,17 +100,17 @@ void mei_host_start_message(struct mei_device *dev)
100 */ 100 */
101void mei_host_enum_clients_message(struct mei_device *dev) 101void mei_host_enum_clients_message(struct mei_device *dev)
102{ 102{
103 struct mei_msg_hdr *mei_hdr; 103 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
104 struct hbm_host_enum_request *enum_req; 104 struct hbm_host_enum_request *enum_req;
105 const size_t len = sizeof(struct hbm_host_enum_request); 105 const size_t len = sizeof(struct hbm_host_enum_request);
106 /* enumerate clients */ 106 /* enumerate clients */
107 mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 107 mei_hbm_hdr(mei_hdr, len);
108 108
109 enum_req = (struct hbm_host_enum_request *) &dev->wr_msg_buf[1]; 109 enum_req = (struct hbm_host_enum_request *)dev->wr_msg.data;
110 memset(enum_req, 0, sizeof(struct hbm_host_enum_request)); 110 memset(enum_req, 0, len);
111 enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; 111 enum_req->hbm_cmd = HOST_ENUM_REQ_CMD;
112 112
113 if (mei_write_message(dev, mei_hdr, (unsigned char *)enum_req)) { 113 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
114 dev->dev_state = MEI_DEV_RESETING; 114 dev->dev_state = MEI_DEV_RESETING;
115 dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n"); 115 dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n");
116 mei_reset(dev, 1); 116 mei_reset(dev, 1);
@@ -124,7 +124,7 @@ void mei_host_enum_clients_message(struct mei_device *dev)
124int mei_host_client_enumerate(struct mei_device *dev) 124int mei_host_client_enumerate(struct mei_device *dev)
125{ 125{
126 126
127 struct mei_msg_hdr *mei_hdr; 127 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
128 struct hbm_props_request *prop_req; 128 struct hbm_props_request *prop_req;
129 const size_t len = sizeof(struct hbm_props_request); 129 const size_t len = sizeof(struct hbm_props_request);
130 unsigned long next_client_index; 130 unsigned long next_client_index;
@@ -146,8 +146,8 @@ int mei_host_client_enumerate(struct mei_device *dev)
146 dev->me_clients[client_num].client_id = next_client_index; 146 dev->me_clients[client_num].client_id = next_client_index;
147 dev->me_clients[client_num].mei_flow_ctrl_creds = 0; 147 dev->me_clients[client_num].mei_flow_ctrl_creds = 0;
148 148
149 mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 149 mei_hbm_hdr(mei_hdr, len);
150 prop_req = (struct hbm_props_request *)&dev->wr_msg_buf[1]; 150 prop_req = (struct hbm_props_request *)dev->wr_msg.data;
151 151
152 memset(prop_req, 0, sizeof(struct hbm_props_request)); 152 memset(prop_req, 0, sizeof(struct hbm_props_request));
153 153
@@ -155,7 +155,7 @@ int mei_host_client_enumerate(struct mei_device *dev)
155 prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; 155 prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD;
156 prop_req->address = next_client_index; 156 prop_req->address = next_client_index;
157 157
158 if (mei_write_message(dev, mei_hdr, (unsigned char *) prop_req)) { 158 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
159 dev->dev_state = MEI_DEV_RESETING; 159 dev->dev_state = MEI_DEV_RESETING;
160 dev_err(&dev->pdev->dev, "Properties request command failed\n"); 160 dev_err(&dev->pdev->dev, "Properties request command failed\n");
161 mei_reset(dev, 1); 161 mei_reset(dev, 1);
@@ -170,6 +170,27 @@ int mei_host_client_enumerate(struct mei_device *dev)
170} 170}
171 171
172/** 172/**
173 * mei_hbm_stop_req_prepare - perpare stop request message
174 *
175 * @dev - mei device
176 * @mei_hdr - mei message header
177 * @data - hbm message body buffer
178 */
179static void mei_hbm_stop_req_prepare(struct mei_device *dev,
180 struct mei_msg_hdr *mei_hdr, unsigned char *data)
181{
182 struct hbm_host_stop_request *req =
183 (struct hbm_host_stop_request *)data;
184 const size_t len = sizeof(struct hbm_host_stop_request);
185
186 mei_hbm_hdr(mei_hdr, len);
187
188 memset(req, 0, len);
189 req->hbm_cmd = HOST_STOP_REQ_CMD;
190 req->reason = DRIVER_STOP_REQUEST;
191}
192
193/**
173 * mei_send_flow_control - sends flow control to fw. 194 * mei_send_flow_control - sends flow control to fw.
174 * 195 *
175 * @dev: the device structure 196 * @dev: the device structure
@@ -179,17 +200,16 @@ int mei_host_client_enumerate(struct mei_device *dev)
179 */ 200 */
180int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl) 201int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl)
181{ 202{
182 struct mei_msg_hdr *mei_hdr; 203 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
183 unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
184 const size_t len = sizeof(struct hbm_flow_control); 204 const size_t len = sizeof(struct hbm_flow_control);
185 205
186 mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 206 mei_hbm_hdr(mei_hdr, len);
187 mei_hbm_cl_hdr(cl, MEI_FLOW_CONTROL_CMD, buf, len); 207 mei_hbm_cl_hdr(cl, MEI_FLOW_CONTROL_CMD, dev->wr_msg.data, len);
188 208
189 dev_dbg(&dev->pdev->dev, "sending flow control host client = %d, ME client = %d\n", 209 dev_dbg(&dev->pdev->dev, "sending flow control host client = %d, ME client = %d\n",
190 cl->host_client_id, cl->me_client_id); 210 cl->host_client_id, cl->me_client_id);
191 211
192 return mei_write_message(dev, mei_hdr, buf); 212 return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
193} 213}
194 214
195/** 215/**
@@ -202,14 +222,13 @@ int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl)
202 */ 222 */
203int mei_disconnect(struct mei_device *dev, struct mei_cl *cl) 223int mei_disconnect(struct mei_device *dev, struct mei_cl *cl)
204{ 224{
205 struct mei_msg_hdr *hdr; 225 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
206 unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
207 const size_t len = sizeof(struct hbm_client_connect_request); 226 const size_t len = sizeof(struct hbm_client_connect_request);
208 227
209 hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 228 mei_hbm_hdr(mei_hdr, len);
210 mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, buf, len); 229 mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, dev->wr_msg.data, len);
211 230
212 return mei_write_message(dev, hdr, buf); 231 return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
213} 232}
214 233
215/** 234/**
@@ -222,14 +241,13 @@ int mei_disconnect(struct mei_device *dev, struct mei_cl *cl)
222 */ 241 */
223int mei_connect(struct mei_device *dev, struct mei_cl *cl) 242int mei_connect(struct mei_device *dev, struct mei_cl *cl)
224{ 243{
225 struct mei_msg_hdr *hdr; 244 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
226 unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
227 const size_t len = sizeof(struct hbm_client_connect_request); 245 const size_t len = sizeof(struct hbm_client_connect_request);
228 246
229 hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 247 mei_hbm_hdr(mei_hdr, len);
230 mei_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, buf, len); 248 mei_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, dev->wr_msg.data, len);
231 249
232 return mei_write_message(dev, hdr, buf); 250 return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
233} 251}
234 252
235/** 253/**
@@ -257,9 +275,9 @@ static void mei_client_disconnect_request(struct mei_device *dev,
257 dev->iamthif_timer = 0; 275 dev->iamthif_timer = 0;
258 276
259 /* prepare disconnect response */ 277 /* prepare disconnect response */
260 (void)mei_hbm_hdr((u32 *)&dev->wr_ext_msg.hdr, len); 278 mei_hbm_hdr(&dev->wr_ext_msg.hdr, len);
261 mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_RES_CMD, 279 mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_RES_CMD,
262 &dev->wr_ext_msg.data, len); 280 dev->wr_ext_msg.data, len);
263 break; 281 break;
264 } 282 }
265 } 283 }
@@ -284,7 +302,6 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
284 struct hbm_flow_control *flow_control; 302 struct hbm_flow_control *flow_control;
285 struct hbm_props_response *props_res; 303 struct hbm_props_response *props_res;
286 struct hbm_host_enum_response *enum_res; 304 struct hbm_host_enum_response *enum_res;
287 struct hbm_host_stop_request *stop_req;
288 305
289 /* read the message to our buffer */ 306 /* read the message to our buffer */
290 BUG_ON(hdr->length >= sizeof(dev->rd_msg_buf)); 307 BUG_ON(hdr->length >= sizeof(dev->rd_msg_buf));
@@ -294,34 +311,27 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
294 switch (mei_msg->hbm_cmd) { 311 switch (mei_msg->hbm_cmd) {
295 case HOST_START_RES_CMD: 312 case HOST_START_RES_CMD:
296 version_res = (struct hbm_host_version_response *)mei_msg; 313 version_res = (struct hbm_host_version_response *)mei_msg;
297 if (version_res->host_version_supported) { 314 if (!version_res->host_version_supported) {
298 dev->version.major_version = HBM_MAJOR_VERSION;
299 dev->version.minor_version = HBM_MINOR_VERSION;
300 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
301 dev->init_clients_state == MEI_START_MESSAGE) {
302 dev->init_clients_timer = 0;
303 mei_host_enum_clients_message(dev);
304 } else {
305 dev->recvd_msg = false;
306 dev_dbg(&dev->pdev->dev, "IMEI reset due to received host start response bus message.\n");
307 mei_reset(dev, 1);
308 return;
309 }
310 } else {
311 u32 *buf = dev->wr_msg_buf;
312 const size_t len = sizeof(struct hbm_host_stop_request);
313
314 dev->version = version_res->me_max_version; 315 dev->version = version_res->me_max_version;
316 dev_dbg(&dev->pdev->dev, "version mismatch.\n");
315 317
316 /* send stop message */ 318 mei_hbm_stop_req_prepare(dev, &dev->wr_msg.hdr,
317 hdr = mei_hbm_hdr(&buf[0], len); 319 dev->wr_msg.data);
318 stop_req = (struct hbm_host_stop_request *)&buf[1]; 320 mei_write_message(dev, &dev->wr_msg.hdr,
319 memset(stop_req, 0, len); 321 dev->wr_msg.data);
320 stop_req->hbm_cmd = HOST_STOP_REQ_CMD; 322 return;
321 stop_req->reason = DRIVER_STOP_REQUEST; 323 }
322 324
323 mei_write_message(dev, hdr, (unsigned char *)stop_req); 325 dev->version.major_version = HBM_MAJOR_VERSION;
324 dev_dbg(&dev->pdev->dev, "version mismatch.\n"); 326 dev->version.minor_version = HBM_MINOR_VERSION;
327 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
328 dev->init_clients_state == MEI_START_MESSAGE) {
329 dev->init_clients_timer = 0;
330 mei_host_enum_clients_message(dev);
331 } else {
332 dev->recvd_msg = false;
333 dev_dbg(&dev->pdev->dev, "reset due to received hbm: host start\n");
334 mei_reset(dev, 1);
325 return; 335 return;
326 } 336 }
327 337
@@ -417,18 +427,10 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
417 break; 427 break;
418 428
419 case ME_STOP_REQ_CMD: 429 case ME_STOP_REQ_CMD:
420 {
421 /* prepare stop request: sent in next interrupt event */
422 430
423 const size_t len = sizeof(struct hbm_host_stop_request); 431 mei_hbm_stop_req_prepare(dev, &dev->wr_ext_msg.hdr,
424 432 dev->wr_ext_msg.data);
425 hdr = mei_hbm_hdr((u32 *)&dev->wr_ext_msg.hdr, len);
426 stop_req = (struct hbm_host_stop_request *)&dev->wr_ext_msg.data;
427 memset(stop_req, 0, len);
428 stop_req->hbm_cmd = HOST_STOP_REQ_CMD;
429 stop_req->reason = DRIVER_STOP_REQUEST;
430 break; 433 break;
431 }
432 default: 434 default:
433 BUG(); 435 BUG();
434 break; 436 break;
diff --git a/drivers/misc/mei/interrupt.c b/drivers/misc/mei/interrupt.c
index d4312a8e139a..9cbf148e02e0 100644
--- a/drivers/misc/mei/interrupt.c
+++ b/drivers/misc/mei/interrupt.c
@@ -469,25 +469,24 @@ static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots,
469static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots, 469static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots,
470 struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list) 470 struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list)
471{ 471{
472 struct mei_msg_hdr *mei_hdr; 472 struct mei_msg_hdr mei_hdr;
473 struct mei_cl *cl = cb->cl; 473 struct mei_cl *cl = cb->cl;
474 size_t len = cb->request_buffer.size - cb->buf_idx; 474 size_t len = cb->request_buffer.size - cb->buf_idx;
475 size_t msg_slots = mei_data2slots(len); 475 size_t msg_slots = mei_data2slots(len);
476 476
477 mei_hdr = (struct mei_msg_hdr *)&dev->wr_msg_buf[0]; 477 mei_hdr.host_addr = cl->host_client_id;
478 mei_hdr->host_addr = cl->host_client_id; 478 mei_hdr.me_addr = cl->me_client_id;
479 mei_hdr->me_addr = cl->me_client_id; 479 mei_hdr.reserved = 0;
480 mei_hdr->reserved = 0;
481 480
482 if (*slots >= msg_slots) { 481 if (*slots >= msg_slots) {
483 mei_hdr->length = len; 482 mei_hdr.length = len;
484 mei_hdr->msg_complete = 1; 483 mei_hdr.msg_complete = 1;
485 /* Split the message only if we can write the whole host buffer */ 484 /* Split the message only if we can write the whole host buffer */
486 } else if (*slots == dev->hbuf_depth) { 485 } else if (*slots == dev->hbuf_depth) {
487 msg_slots = *slots; 486 msg_slots = *slots;
488 len = (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr); 487 len = (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
489 mei_hdr->length = len; 488 mei_hdr.length = len;
490 mei_hdr->msg_complete = 0; 489 mei_hdr.msg_complete = 0;
491 } else { 490 } else {
492 /* wait for next time the host buffer is empty */ 491 /* wait for next time the host buffer is empty */
493 return 0; 492 return 0;
@@ -495,10 +494,10 @@ static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots,
495 494
496 dev_dbg(&dev->pdev->dev, "buf: size = %d idx = %lu\n", 495 dev_dbg(&dev->pdev->dev, "buf: size = %d idx = %lu\n",
497 cb->request_buffer.size, cb->buf_idx); 496 cb->request_buffer.size, cb->buf_idx);
498 dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr)); 497 dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(&mei_hdr));
499 498
500 *slots -= msg_slots; 499 *slots -= msg_slots;
501 if (mei_write_message(dev, mei_hdr, 500 if (mei_write_message(dev, &mei_hdr,
502 cb->request_buffer.data + cb->buf_idx)) { 501 cb->request_buffer.data + cb->buf_idx)) {
503 cl->status = -ENODEV; 502 cl->status = -ENODEV;
504 list_move_tail(&cb->list, &cmpl_list->list); 503 list_move_tail(&cb->list, &cmpl_list->list);
@@ -509,8 +508,8 @@ static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots,
509 return -ENODEV; 508 return -ENODEV;
510 509
511 cl->status = 0; 510 cl->status = 0;
512 cb->buf_idx += mei_hdr->length; 511 cb->buf_idx += mei_hdr.length;
513 if (mei_hdr->msg_complete) 512 if (mei_hdr.msg_complete)
514 list_move_tail(&cb->list, &dev->write_waiting_list.list); 513 list_move_tail(&cb->list, &dev->write_waiting_list.list);
515 514
516 return 0; 515 return 0;
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index 107a820a6ba4..1ea331ac2463 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -265,7 +265,13 @@ struct mei_device {
265 265
266 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */ 266 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */
267 u32 rd_msg_hdr; 267 u32 rd_msg_hdr;
268 u32 wr_msg_buf[128]; /* used for control messages */ 268
269 /* used for control messages */
270 struct {
271 struct mei_msg_hdr hdr;
272 unsigned char data[128];
273 } wr_msg;
274
269 struct { 275 struct {
270 struct mei_msg_hdr hdr; 276 struct mei_msg_hdr hdr;
271 unsigned char data[4]; /* All HBM messages are 4 bytes */ 277 unsigned char data[4]; /* All HBM messages are 4 bytes */
@@ -459,15 +465,13 @@ void mei_disable_interrupts(struct mei_device *dev);
459 465
460void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr); 466void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr);
461 467
462static inline struct mei_msg_hdr *mei_hbm_hdr(u32 *buf, size_t length) 468static inline void mei_hbm_hdr(struct mei_msg_hdr *hdr, size_t length)
463{ 469{
464 struct mei_msg_hdr *hdr = (struct mei_msg_hdr *)buf;
465 hdr->host_addr = 0; 470 hdr->host_addr = 0;
466 hdr->me_addr = 0; 471 hdr->me_addr = 0;
467 hdr->length = length; 472 hdr->length = length;
468 hdr->msg_complete = 1; 473 hdr->msg_complete = 1;
469 hdr->reserved = 0; 474 hdr->reserved = 0;
470 return hdr;
471} 475}
472 476
473#define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d comp=%1d" 477#define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d comp=%1d"
diff --git a/drivers/misc/mei/wd.c b/drivers/misc/mei/wd.c
index 9c3738a4eb08..3997a630847f 100644
--- a/drivers/misc/mei/wd.c
+++ b/drivers/misc/mei/wd.c
@@ -101,22 +101,21 @@ int mei_wd_host_init(struct mei_device *dev)
101 */ 101 */
102int mei_wd_send(struct mei_device *dev) 102int mei_wd_send(struct mei_device *dev)
103{ 103{
104 struct mei_msg_hdr *hdr; 104 struct mei_msg_hdr hdr;
105 105
106 hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; 106 hdr.host_addr = dev->wd_cl.host_client_id;
107 hdr->host_addr = dev->wd_cl.host_client_id; 107 hdr.me_addr = dev->wd_cl.me_client_id;
108 hdr->me_addr = dev->wd_cl.me_client_id; 108 hdr.msg_complete = 1;
109 hdr->msg_complete = 1; 109 hdr.reserved = 0;
110 hdr->reserved = 0;
111 110
112 if (!memcmp(dev->wd_data, mei_start_wd_params, MEI_WD_HDR_SIZE)) 111 if (!memcmp(dev->wd_data, mei_start_wd_params, MEI_WD_HDR_SIZE))
113 hdr->length = MEI_WD_START_MSG_SIZE; 112 hdr.length = MEI_WD_START_MSG_SIZE;
114 else if (!memcmp(dev->wd_data, mei_stop_wd_params, MEI_WD_HDR_SIZE)) 113 else if (!memcmp(dev->wd_data, mei_stop_wd_params, MEI_WD_HDR_SIZE))
115 hdr->length = MEI_WD_STOP_MSG_SIZE; 114 hdr.length = MEI_WD_STOP_MSG_SIZE;
116 else 115 else
117 return -EINVAL; 116 return -EINVAL;
118 117
119 return mei_write_message(dev, hdr, dev->wd_data); 118 return mei_write_message(dev, &hdr, dev->wd_data);
120} 119}
121 120
122/** 121/**