Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mei: drop wr_msg from the mei_dev structure

The control messages are usually small, around 8 bytes, and can be
allocated on the stack.
Using on stack allocation allows us to drop 'wr_msg' a rather large
buffer reserved in the mei_dev structure and relax contention
of this device global buffer.

Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alexander Usyskin and committed by
Greg Kroah-Hartman
c0ff9019 dc139272

+68 -79
+67 -70
drivers/misc/mei/hbm.c
··· 132 132 hdr->length = length; 133 133 hdr->msg_complete = 1; 134 134 hdr->reserved = 0; 135 + hdr->internal = 0; 135 136 } 136 137 137 138 /** ··· 166 165 * Return: 0 on success, <0 on failure. 167 166 */ 168 167 static inline 169 - int mei_hbm_cl_write(struct mei_device *dev, 170 - struct mei_cl *cl, u8 hbm_cmd, size_t len) 168 + int mei_hbm_cl_write(struct mei_device *dev, struct mei_cl *cl, 169 + u8 hbm_cmd, u8 *buf, size_t len) 171 170 { 172 - struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; 171 + struct mei_msg_hdr mei_hdr; 173 172 174 - mei_hbm_hdr(mei_hdr, len); 175 - mei_hbm_cl_hdr(cl, hbm_cmd, dev->wr_msg.data, len); 173 + mei_hbm_hdr(&mei_hdr, len); 174 + mei_hbm_cl_hdr(cl, hbm_cmd, buf, len); 176 175 177 - return mei_write_message(dev, mei_hdr, dev->wr_msg.data); 176 + return mei_write_message(dev, &mei_hdr, buf); 178 177 } 179 178 180 179 /** ··· 251 250 */ 252 251 int mei_hbm_start_req(struct mei_device *dev) 253 252 { 254 - struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; 255 - struct hbm_host_version_request *start_req; 253 + struct mei_msg_hdr mei_hdr; 254 + struct hbm_host_version_request start_req; 256 255 const size_t len = sizeof(struct hbm_host_version_request); 257 256 int ret; 258 257 259 258 mei_hbm_reset(dev); 260 259 261 - mei_hbm_hdr(mei_hdr, len); 260 + mei_hbm_hdr(&mei_hdr, len); 262 261 263 262 /* host start message */ 264 - start_req = (struct hbm_host_version_request *)dev->wr_msg.data; 265 - memset(start_req, 0, len); 266 - start_req->hbm_cmd = HOST_START_REQ_CMD; 267 - start_req->host_version.major_version = HBM_MAJOR_VERSION; 268 - start_req->host_version.minor_version = HBM_MINOR_VERSION; 263 + memset(&start_req, 0, len); 264 + start_req.hbm_cmd = HOST_START_REQ_CMD; 265 + start_req.host_version.major_version = HBM_MAJOR_VERSION; 266 + start_req.host_version.minor_version = HBM_MINOR_VERSION; 269 267 270 268 dev->hbm_state = MEI_HBM_IDLE; 271 - ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data); 269 + ret = mei_write_message(dev, &mei_hdr, &start_req); 272 270 if (ret) { 273 271 dev_err(dev->dev, "version message write failed: ret = %d\n", 274 272 ret); ··· 288 288 */ 289 289 static int mei_hbm_enum_clients_req(struct mei_device *dev) 290 290 { 291 - struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; 292 - struct hbm_host_enum_request *enum_req; 291 + struct mei_msg_hdr mei_hdr; 292 + struct hbm_host_enum_request enum_req; 293 293 const size_t len = sizeof(struct hbm_host_enum_request); 294 294 int ret; 295 295 296 296 /* enumerate clients */ 297 - mei_hbm_hdr(mei_hdr, len); 297 + mei_hbm_hdr(&mei_hdr, len); 298 298 299 - enum_req = (struct hbm_host_enum_request *)dev->wr_msg.data; 300 - memset(enum_req, 0, len); 301 - enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; 302 - enum_req->flags |= dev->hbm_f_dc_supported ? 303 - MEI_HBM_ENUM_F_ALLOW_ADD : 0; 304 - enum_req->flags |= dev->hbm_f_ie_supported ? 305 - MEI_HBM_ENUM_F_IMMEDIATE_ENUM : 0; 299 + memset(&enum_req, 0, len); 300 + enum_req.hbm_cmd = HOST_ENUM_REQ_CMD; 301 + enum_req.flags |= dev->hbm_f_dc_supported ? 302 + MEI_HBM_ENUM_F_ALLOW_ADD : 0; 303 + enum_req.flags |= dev->hbm_f_ie_supported ? 304 + MEI_HBM_ENUM_F_IMMEDIATE_ENUM : 0; 306 305 307 - ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data); 306 + ret = mei_write_message(dev, &mei_hdr, &enum_req); 308 307 if (ret) { 309 308 dev_err(dev->dev, "enumeration request write failed: ret = %d.\n", 310 309 ret); ··· 357 358 */ 358 359 static int mei_hbm_add_cl_resp(struct mei_device *dev, u8 addr, u8 status) 359 360 { 360 - struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; 361 - struct hbm_add_client_response *resp; 361 + struct mei_msg_hdr mei_hdr; 362 + struct hbm_add_client_response resp; 362 363 const size_t len = sizeof(struct hbm_add_client_response); 363 364 int ret; 364 365 365 366 dev_dbg(dev->dev, "adding client response\n"); 366 367 367 - resp = (struct hbm_add_client_response *)dev->wr_msg.data; 368 + mei_hbm_hdr(&mei_hdr, len); 368 369 369 - mei_hbm_hdr(mei_hdr, len); 370 - memset(resp, 0, sizeof(struct hbm_add_client_response)); 370 + memset(&resp, 0, sizeof(struct hbm_add_client_response)); 371 + resp.hbm_cmd = MEI_HBM_ADD_CLIENT_RES_CMD; 372 + resp.me_addr = addr; 373 + resp.status = status; 371 374 372 - resp->hbm_cmd = MEI_HBM_ADD_CLIENT_RES_CMD; 373 - resp->me_addr = addr; 374 - resp->status = status; 375 - 376 - ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data); 375 + ret = mei_write_message(dev, &mei_hdr, &resp); 377 376 if (ret) 378 377 dev_err(dev->dev, "add client response write failed: ret = %d\n", 379 378 ret); ··· 418 421 struct mei_cl *cl, u8 start) 419 422 { 420 423 421 - struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; 422 - struct hbm_notification_request *req; 424 + struct mei_msg_hdr mei_hdr; 425 + struct hbm_notification_request req; 423 426 const size_t len = sizeof(struct hbm_notification_request); 424 427 int ret; 425 428 426 - mei_hbm_hdr(mei_hdr, len); 427 - mei_hbm_cl_hdr(cl, MEI_HBM_NOTIFY_REQ_CMD, dev->wr_msg.data, len); 429 + mei_hbm_hdr(&mei_hdr, len); 430 + mei_hbm_cl_hdr(cl, MEI_HBM_NOTIFY_REQ_CMD, &req, len); 428 431 429 - req = (struct hbm_notification_request *)dev->wr_msg.data; 430 - req->start = start; 432 + req.start = start; 431 433 432 - ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data); 434 + ret = mei_write_message(dev, &mei_hdr, &req); 433 435 if (ret) 434 436 dev_err(dev->dev, "notify request failed: ret = %d\n", ret); 435 437 ··· 530 534 */ 531 535 static int mei_hbm_prop_req(struct mei_device *dev, unsigned long start_idx) 532 536 { 533 - struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; 534 - struct hbm_props_request *prop_req; 537 + struct mei_msg_hdr mei_hdr; 538 + struct hbm_props_request prop_req; 535 539 const size_t len = sizeof(struct hbm_props_request); 536 540 unsigned long addr; 537 541 int ret; ··· 546 550 return 0; 547 551 } 548 552 549 - mei_hbm_hdr(mei_hdr, len); 550 - prop_req = (struct hbm_props_request *)dev->wr_msg.data; 553 + mei_hbm_hdr(&mei_hdr, len); 551 554 552 - memset(prop_req, 0, sizeof(struct hbm_props_request)); 555 + memset(&prop_req, 0, sizeof(struct hbm_props_request)); 553 556 554 - prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; 555 - prop_req->me_addr = addr; 557 + prop_req.hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; 558 + prop_req.me_addr = addr; 556 559 557 - ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data); 560 + ret = mei_write_message(dev, &mei_hdr, &prop_req); 558 561 if (ret) { 559 562 dev_err(dev->dev, "properties request write failed: ret = %d\n", 560 563 ret); ··· 576 581 */ 577 582 int mei_hbm_pg(struct mei_device *dev, u8 pg_cmd) 578 583 { 579 - struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; 580 - struct hbm_power_gate *req; 584 + struct mei_msg_hdr mei_hdr; 585 + struct hbm_power_gate req; 581 586 const size_t len = sizeof(struct hbm_power_gate); 582 587 int ret; 583 588 584 589 if (!dev->hbm_f_pg_supported) 585 590 return -EOPNOTSUPP; 586 591 587 - mei_hbm_hdr(mei_hdr, len); 592 + mei_hbm_hdr(&mei_hdr, len); 588 593 589 - req = (struct hbm_power_gate *)dev->wr_msg.data; 590 - memset(req, 0, len); 591 - req->hbm_cmd = pg_cmd; 594 + memset(&req, 0, len); 595 + req.hbm_cmd = pg_cmd; 592 596 593 - ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data); 597 + ret = mei_write_message(dev, &mei_hdr, &req); 594 598 if (ret) 595 599 dev_err(dev->dev, "power gate command write failed.\n"); 596 600 return ret; ··· 605 611 */ 606 612 static int mei_hbm_stop_req(struct mei_device *dev) 607 613 { 608 - struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; 609 - struct hbm_host_stop_request *req = 610 - (struct hbm_host_stop_request *)dev->wr_msg.data; 614 + struct mei_msg_hdr mei_hdr; 615 + struct hbm_host_stop_request req; 611 616 const size_t len = sizeof(struct hbm_host_stop_request); 612 617 613 - mei_hbm_hdr(mei_hdr, len); 618 + mei_hbm_hdr(&mei_hdr, len); 614 619 615 - memset(req, 0, len); 616 - req->hbm_cmd = HOST_STOP_REQ_CMD; 617 - req->reason = DRIVER_STOP_REQUEST; 620 + memset(&req, 0, len); 621 + req.hbm_cmd = HOST_STOP_REQ_CMD; 622 + req.reason = DRIVER_STOP_REQUEST; 618 623 619 - return mei_write_message(dev, mei_hdr, dev->wr_msg.data); 624 + return mei_write_message(dev, &mei_hdr, &req); 620 625 } 621 626 622 627 /** ··· 629 636 int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl) 630 637 { 631 638 const size_t len = sizeof(struct hbm_flow_control); 639 + u8 buf[len]; 632 640 633 641 cl_dbg(dev, cl, "sending flow control\n"); 634 - return mei_hbm_cl_write(dev, cl, MEI_FLOW_CONTROL_CMD, len); 642 + return mei_hbm_cl_write(dev, cl, MEI_FLOW_CONTROL_CMD, buf, len); 635 643 } 636 644 637 645 /** ··· 708 714 int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl) 709 715 { 710 716 const size_t len = sizeof(struct hbm_client_connect_request); 717 + u8 buf[len]; 711 718 712 - return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_REQ_CMD, len); 719 + return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_REQ_CMD, buf, len); 713 720 } 714 721 715 722 /** ··· 724 729 int mei_hbm_cl_disconnect_rsp(struct mei_device *dev, struct mei_cl *cl) 725 730 { 726 731 const size_t len = sizeof(struct hbm_client_connect_response); 732 + u8 buf[len]; 727 733 728 - return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_RES_CMD, len); 734 + return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_RES_CMD, buf, len); 729 735 } 730 736 731 737 /** ··· 761 765 int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl) 762 766 { 763 767 const size_t len = sizeof(struct hbm_client_connect_request); 768 + u8 buf[len]; 764 769 765 - return mei_hbm_cl_write(dev, cl, CLIENT_CONNECT_REQ_CMD, len); 770 + return mei_hbm_cl_write(dev, cl, CLIENT_CONNECT_REQ_CMD, buf, len); 766 771 } 767 772 768 773 /**
+1 -9
drivers/misc/mei/mei_dev.h
··· 382 382 * 383 383 * @hbuf_depth : depth of hardware host/write buffer is slots 384 384 * @hbuf_is_ready : query if the host host/write buffer is ready 385 - * @wr_msg : the buffer for hbm control messages 386 385 * 387 386 * @version : HBM protocol version in use 388 387 * @hbm_f_pg_supported : hbm feature pgi protocol ··· 465 466 /* write buffer */ 466 467 u8 hbuf_depth; 467 468 bool hbuf_is_ready; 468 - 469 - /* used for control messages */ 470 - struct { 471 - struct mei_msg_hdr hdr; 472 - unsigned char data[128]; 473 - } wr_msg; 474 469 475 470 struct hbm_version version; 476 471 unsigned int hbm_f_pg_supported:1; ··· 663 670 } 664 671 665 672 static inline int mei_write_message(struct mei_device *dev, 666 - struct mei_msg_hdr *hdr, 667 - unsigned char *buf) 673 + struct mei_msg_hdr *hdr, void *buf) 668 674 { 669 675 return dev->ops->write(dev, hdr, buf); 670 676 }