Skip to content

Commit e46f187

Browse files
Tomas Winklergregkh
authored andcommitted
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>
1 parent cd51ed6 commit e46f187

File tree

5 files changed

+108
-105
lines changed

5 files changed

+108
-105
lines changed

drivers/misc/mei/amthif.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -432,34 +432,33 @@ unsigned int mei_amthif_poll(struct mei_device *dev,
432432
int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
433433
struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list)
434434
{
435-
struct mei_msg_hdr *mei_hdr;
435+
struct mei_msg_hdr mei_hdr;
436436
struct mei_cl *cl = cb->cl;
437437
size_t len = dev->iamthif_msg_buf_size - dev->iamthif_msg_buf_index;
438438
size_t msg_slots = mei_data2slots(len);
439439

440-
mei_hdr = (struct mei_msg_hdr *)&dev->wr_msg_buf[0];
441-
mei_hdr->host_addr = cl->host_client_id;
442-
mei_hdr->me_addr = cl->me_client_id;
443-
mei_hdr->reserved = 0;
440+
mei_hdr.host_addr = cl->host_client_id;
441+
mei_hdr.me_addr = cl->me_client_id;
442+
mei_hdr.reserved = 0;
444443

445444
if (*slots >= msg_slots) {
446-
mei_hdr->length = len;
447-
mei_hdr->msg_complete = 1;
445+
mei_hdr.length = len;
446+
mei_hdr.msg_complete = 1;
448447
/* Split the message only if we can write the whole host buffer */
449448
} else if (*slots == dev->hbuf_depth) {
450449
msg_slots = *slots;
451450
len = (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
452-
mei_hdr->length = len;
453-
mei_hdr->msg_complete = 0;
451+
mei_hdr.length = len;
452+
mei_hdr.msg_complete = 0;
454453
} else {
455454
/* wait for next time the host buffer is empty */
456455
return 0;
457456
}
458457

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));
460459

461460
*slots -= msg_slots;
462-
if (mei_write_message(dev, mei_hdr,
461+
if (mei_write_message(dev, &mei_hdr,
463462
dev->iamthif_msg_buf + dev->iamthif_msg_buf_index)) {
464463
dev->iamthif_state = MEI_IAMTHIF_IDLE;
465464
cl->status = -ENODEV;
@@ -470,10 +469,10 @@ int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
470469
if (mei_flow_ctrl_reduce(dev, cl))
471470
return -ENODEV;
472471

473-
dev->iamthif_msg_buf_index += mei_hdr->length;
472+
dev->iamthif_msg_buf_index += mei_hdr.length;
474473
cl->status = 0;
475474

476-
if (mei_hdr->msg_complete) {
475+
if (mei_hdr.msg_complete) {
477476
dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL;
478477
dev->iamthif_flow_control_pending = true;
479478

drivers/misc/mei/hbm.c

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,21 @@ bool mei_hbm_cl_addr_equal(struct mei_cl *cl, void *buf)
6767
*/
6868
void mei_host_start_message(struct mei_device *dev)
6969
{
70-
struct mei_msg_hdr *mei_hdr;
70+
struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
7171
struct hbm_host_version_request *start_req;
7272
const size_t len = sizeof(struct hbm_host_version_request);
7373

74-
mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len);
74+
mei_hbm_hdr(mei_hdr, len);
7575

7676
/* 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;
7878
memset(start_req, 0, len);
7979
start_req->hbm_cmd = HOST_START_REQ_CMD;
8080
start_req->host_version.major_version = HBM_MAJOR_VERSION;
8181
start_req->host_version.minor_version = HBM_MINOR_VERSION;
8282

8383
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)) {
8585
dev_dbg(&dev->pdev->dev, "write send version message to FW fail.\n");
8686
dev->dev_state = MEI_DEV_RESETING;
8787
mei_reset(dev, 1);
@@ -100,17 +100,17 @@ void mei_host_start_message(struct mei_device *dev)
100100
*/
101101
void mei_host_enum_clients_message(struct mei_device *dev)
102102
{
103-
struct mei_msg_hdr *mei_hdr;
103+
struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
104104
struct hbm_host_enum_request *enum_req;
105105
const size_t len = sizeof(struct hbm_host_enum_request);
106106
/* enumerate clients */
107-
mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len);
107+
mei_hbm_hdr(mei_hdr, len);
108108

109-
enum_req = (struct hbm_host_enum_request *) &dev->wr_msg_buf[1];
110-
memset(enum_req, 0, sizeof(struct hbm_host_enum_request));
109+
enum_req = (struct hbm_host_enum_request *)dev->wr_msg.data;
110+
memset(enum_req, 0, len);
111111
enum_req->hbm_cmd = HOST_ENUM_REQ_CMD;
112112

113-
if (mei_write_message(dev, mei_hdr, (unsigned char *)enum_req)) {
113+
if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
114114
dev->dev_state = MEI_DEV_RESETING;
115115
dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n");
116116
mei_reset(dev, 1);
@@ -124,7 +124,7 @@ void mei_host_enum_clients_message(struct mei_device *dev)
124124
int mei_host_client_enumerate(struct mei_device *dev)
125125
{
126126

127-
struct mei_msg_hdr *mei_hdr;
127+
struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
128128
struct hbm_props_request *prop_req;
129129
const size_t len = sizeof(struct hbm_props_request);
130130
unsigned long next_client_index;
@@ -146,16 +146,16 @@ int mei_host_client_enumerate(struct mei_device *dev)
146146
dev->me_clients[client_num].client_id = next_client_index;
147147
dev->me_clients[client_num].mei_flow_ctrl_creds = 0;
148148

149-
mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len);
150-
prop_req = (struct hbm_props_request *)&dev->wr_msg_buf[1];
149+
mei_hbm_hdr(mei_hdr, len);
150+
prop_req = (struct hbm_props_request *)dev->wr_msg.data;
151151

152152
memset(prop_req, 0, sizeof(struct hbm_props_request));
153153

154154

155155
prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD;
156156
prop_req->address = next_client_index;
157157

158-
if (mei_write_message(dev, mei_hdr, (unsigned char *) prop_req)) {
158+
if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
159159
dev->dev_state = MEI_DEV_RESETING;
160160
dev_err(&dev->pdev->dev, "Properties request command failed\n");
161161
mei_reset(dev, 1);
@@ -169,6 +169,27 @@ int mei_host_client_enumerate(struct mei_device *dev)
169169
return 0;
170170
}
171171

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+
*/
179+
static 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+
172193
/**
173194
* mei_send_flow_control - sends flow control to fw.
174195
*
@@ -179,17 +200,16 @@ int mei_host_client_enumerate(struct mei_device *dev)
179200
*/
180201
int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl)
181202
{
182-
struct mei_msg_hdr *mei_hdr;
183-
unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
203+
struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
184204
const size_t len = sizeof(struct hbm_flow_control);
185205

186-
mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len);
187-
mei_hbm_cl_hdr(cl, MEI_FLOW_CONTROL_CMD, buf, len);
206+
mei_hbm_hdr(mei_hdr, len);
207+
mei_hbm_cl_hdr(cl, MEI_FLOW_CONTROL_CMD, dev->wr_msg.data, len);
188208

189209
dev_dbg(&dev->pdev->dev, "sending flow control host client = %d, ME client = %d\n",
190210
cl->host_client_id, cl->me_client_id);
191211

192-
return mei_write_message(dev, mei_hdr, buf);
212+
return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
193213
}
194214

195215
/**
@@ -202,14 +222,13 @@ int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl)
202222
*/
203223
int mei_disconnect(struct mei_device *dev, struct mei_cl *cl)
204224
{
205-
struct mei_msg_hdr *hdr;
206-
unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
225+
struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
207226
const size_t len = sizeof(struct hbm_client_connect_request);
208227

209-
hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len);
210-
mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, buf, len);
228+
mei_hbm_hdr(mei_hdr, len);
229+
mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, dev->wr_msg.data, len);
211230

212-
return mei_write_message(dev, hdr, buf);
231+
return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
213232
}
214233

215234
/**
@@ -222,14 +241,13 @@ int mei_disconnect(struct mei_device *dev, struct mei_cl *cl)
222241
*/
223242
int mei_connect(struct mei_device *dev, struct mei_cl *cl)
224243
{
225-
struct mei_msg_hdr *hdr;
226-
unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
244+
struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
227245
const size_t len = sizeof(struct hbm_client_connect_request);
228246

229-
hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len);
230-
mei_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, buf, len);
247+
mei_hbm_hdr(mei_hdr, len);
248+
mei_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, dev->wr_msg.data, len);
231249

232-
return mei_write_message(dev, hdr, buf);
250+
return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
233251
}
234252

235253
/**
@@ -257,9 +275,9 @@ static void mei_client_disconnect_request(struct mei_device *dev,
257275
dev->iamthif_timer = 0;
258276

259277
/* 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);
261279
mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_RES_CMD,
262-
&dev->wr_ext_msg.data, len);
280+
dev->wr_ext_msg.data, len);
263281
break;
264282
}
265283
}
@@ -284,7 +302,6 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
284302
struct hbm_flow_control *flow_control;
285303
struct hbm_props_response *props_res;
286304
struct hbm_host_enum_response *enum_res;
287-
struct hbm_host_stop_request *stop_req;
288305

289306
/* read the message to our buffer */
290307
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)
294311
switch (mei_msg->hbm_cmd) {
295312
case HOST_START_RES_CMD:
296313
version_res = (struct hbm_host_version_response *)mei_msg;
297-
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+
if (!version_res->host_version_supported) {
314315
dev->version = version_res->me_max_version;
316+
dev_dbg(&dev->pdev->dev, "version mismatch.\n");
315317

316-
/* send stop message */
317-
hdr = mei_hbm_hdr(&buf[0], len);
318-
stop_req = (struct hbm_host_stop_request *)&buf[1];
319-
memset(stop_req, 0, len);
320-
stop_req->hbm_cmd = HOST_STOP_REQ_CMD;
321-
stop_req->reason = DRIVER_STOP_REQUEST;
318+
mei_hbm_stop_req_prepare(dev, &dev->wr_msg.hdr,
319+
dev->wr_msg.data);
320+
mei_write_message(dev, &dev->wr_msg.hdr,
321+
dev->wr_msg.data);
322+
return;
323+
}
322324

323-
mei_write_message(dev, hdr, (unsigned char *)stop_req);
324-
dev_dbg(&dev->pdev->dev, "version mismatch.\n");
325+
dev->version.major_version = HBM_MAJOR_VERSION;
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);
325335
return;
326336
}
327337

@@ -417,18 +427,10 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
417427
break;
418428

419429
case ME_STOP_REQ_CMD:
420-
{
421-
/* prepare stop request: sent in next interrupt event */
422430

423-
const size_t len = sizeof(struct hbm_host_stop_request);
424-
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;
431+
mei_hbm_stop_req_prepare(dev, &dev->wr_ext_msg.hdr,
432+
dev->wr_ext_msg.data);
430433
break;
431-
}
432434
default:
433435
BUG();
434436
break;

drivers/misc/mei/interrupt.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -469,36 +469,35 @@ static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots,
469469
static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots,
470470
struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list)
471471
{
472-
struct mei_msg_hdr *mei_hdr;
472+
struct mei_msg_hdr mei_hdr;
473473
struct mei_cl *cl = cb->cl;
474474
size_t len = cb->request_buffer.size - cb->buf_idx;
475475
size_t msg_slots = mei_data2slots(len);
476476

477-
mei_hdr = (struct mei_msg_hdr *)&dev->wr_msg_buf[0];
478-
mei_hdr->host_addr = cl->host_client_id;
479-
mei_hdr->me_addr = cl->me_client_id;
480-
mei_hdr->reserved = 0;
477+
mei_hdr.host_addr = cl->host_client_id;
478+
mei_hdr.me_addr = cl->me_client_id;
479+
mei_hdr.reserved = 0;
481480

482481
if (*slots >= msg_slots) {
483-
mei_hdr->length = len;
484-
mei_hdr->msg_complete = 1;
482+
mei_hdr.length = len;
483+
mei_hdr.msg_complete = 1;
485484
/* Split the message only if we can write the whole host buffer */
486485
} else if (*slots == dev->hbuf_depth) {
487486
msg_slots = *slots;
488487
len = (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
489-
mei_hdr->length = len;
490-
mei_hdr->msg_complete = 0;
488+
mei_hdr.length = len;
489+
mei_hdr.msg_complete = 0;
491490
} else {
492491
/* wait for next time the host buffer is empty */
493492
return 0;
494493
}
495494

496495
dev_dbg(&dev->pdev->dev, "buf: size = %d idx = %lu\n",
497496
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));
499498

500499
*slots -= msg_slots;
501-
if (mei_write_message(dev, mei_hdr,
500+
if (mei_write_message(dev, &mei_hdr,
502501
cb->request_buffer.data + cb->buf_idx)) {
503502
cl->status = -ENODEV;
504503
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,
509508
return -ENODEV;
510509

511510
cl->status = 0;
512-
cb->buf_idx += mei_hdr->length;
513-
if (mei_hdr->msg_complete)
511+
cb->buf_idx += mei_hdr.length;
512+
if (mei_hdr.msg_complete)
514513
list_move_tail(&cb->list, &dev->write_waiting_list.list);
515514

516515
return 0;

0 commit comments

Comments
 (0)