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

mei: compact code for mei bus message creation

1. replace boilerplate code for filling up the bus message header
with a common wrapper function
2. shorten variable names and use temporal variables
to save some screen space

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

authored by

Tomas Winkler and committed by
Greg Kroah-Hartman
5bd64714 2c9e9fdc

+105 -141
+32 -42
drivers/misc/mei/init.c
··· 43 43 } 44 44 45 45 46 + 46 47 /** 47 48 * mei_io_list_flush - removes list entry belonging to cl. 48 49 * ··· 332 331 void mei_host_start_message(struct mei_device *dev) 333 332 { 334 333 struct mei_msg_hdr *mei_hdr; 335 - struct hbm_host_version_request *host_start_req; 334 + struct hbm_host_version_request *start_req; 335 + const size_t len = sizeof(struct hbm_host_version_request); 336 + 337 + mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 336 338 337 339 /* host start message */ 338 - mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; 339 - mei_hdr->host_addr = 0; 340 - mei_hdr->me_addr = 0; 341 - mei_hdr->length = sizeof(struct hbm_host_version_request); 342 - mei_hdr->msg_complete = 1; 343 - mei_hdr->reserved = 0; 340 + start_req = (struct hbm_host_version_request *)&dev->wr_msg_buf[1]; 341 + memset(start_req, 0, len); 342 + start_req->hbm_cmd = HOST_START_REQ_CMD; 343 + start_req->host_version.major_version = HBM_MAJOR_VERSION; 344 + start_req->host_version.minor_version = HBM_MINOR_VERSION; 344 345 345 - host_start_req = 346 - (struct hbm_host_version_request *) &dev->wr_msg_buf[1]; 347 - memset(host_start_req, 0, sizeof(struct hbm_host_version_request)); 348 - host_start_req->hbm_cmd = HOST_START_REQ_CMD; 349 - host_start_req->host_version.major_version = HBM_MAJOR_VERSION; 350 - host_start_req->host_version.minor_version = HBM_MINOR_VERSION; 351 346 dev->recvd_msg = false; 352 - if (mei_write_message(dev, mei_hdr, (unsigned char *)host_start_req, 353 - mei_hdr->length)) { 347 + if (mei_write_message(dev, mei_hdr, (unsigned char *)start_req, len)) { 354 348 dev_dbg(&dev->pdev->dev, "write send version message to FW fail.\n"); 355 349 dev->dev_state = MEI_DEV_RESETING; 356 350 mei_reset(dev, 1); ··· 365 369 void mei_host_enum_clients_message(struct mei_device *dev) 366 370 { 367 371 struct mei_msg_hdr *mei_hdr; 368 - struct hbm_host_enum_request *host_enum_req; 369 - mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; 372 + struct hbm_host_enum_request *enum_req; 373 + const size_t len = sizeof(struct hbm_host_enum_request); 370 374 /* enumerate clients */ 371 - mei_hdr->host_addr = 0; 372 - mei_hdr->me_addr = 0; 373 - mei_hdr->length = sizeof(struct hbm_host_enum_request); 374 - mei_hdr->msg_complete = 1; 375 - mei_hdr->reserved = 0; 375 + mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 376 376 377 - host_enum_req = (struct hbm_host_enum_request *) &dev->wr_msg_buf[1]; 378 - memset(host_enum_req, 0, sizeof(struct hbm_host_enum_request)); 379 - host_enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; 380 - if (mei_write_message(dev, mei_hdr, (unsigned char *)host_enum_req, 381 - mei_hdr->length)) { 377 + enum_req = (struct hbm_host_enum_request *) &dev->wr_msg_buf[1]; 378 + memset(enum_req, 0, sizeof(struct hbm_host_enum_request)); 379 + enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; 380 + 381 + if (mei_write_message(dev, mei_hdr, (unsigned char *)enum_req, len)) { 382 382 dev->dev_state = MEI_DEV_RESETING; 383 383 dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n"); 384 384 mei_reset(dev, 1); ··· 435 443 */ 436 444 int mei_host_client_properties(struct mei_device *dev) 437 445 { 438 - struct mei_msg_hdr *mei_header; 439 - struct hbm_props_request *host_cli_req; 446 + 447 + struct mei_msg_hdr *mei_hdr; 448 + struct hbm_props_request *prop_req; 449 + const size_t len = sizeof(struct hbm_props_request); 450 + 440 451 int b; 441 452 u8 client_num = dev->me_client_presentation_num; 453 + 454 + prop_req = (struct hbm_props_request *)&dev->wr_msg_buf[1]; 442 455 443 456 b = dev->me_client_index; 444 457 b = find_next_bit(dev->me_clients_map, MEI_CLIENTS_MAX, b); 445 458 if (b < MEI_CLIENTS_MAX) { 446 459 dev->me_clients[client_num].client_id = b; 447 460 dev->me_clients[client_num].mei_flow_ctrl_creds = 0; 448 - mei_header = (struct mei_msg_hdr *)&dev->wr_msg_buf[0]; 449 - mei_header->host_addr = 0; 450 - mei_header->me_addr = 0; 451 - mei_header->length = sizeof(struct hbm_props_request); 452 - mei_header->msg_complete = 1; 453 - mei_header->reserved = 0; 461 + mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 454 462 455 - host_cli_req = (struct hbm_props_request *)&dev->wr_msg_buf[1]; 456 463 457 - memset(host_cli_req, 0, sizeof(struct hbm_props_request)); 464 + memset(prop_req, 0, sizeof(struct hbm_props_request)); 458 465 459 - host_cli_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; 460 - host_cli_req->address = b; 466 + prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; 467 + prop_req->address = b; 461 468 462 - if (mei_write_message(dev, mei_header, 463 - (unsigned char *)host_cli_req, 464 - mei_header->length)) { 469 + if (mei_write_message(dev, mei_hdr, 470 + (unsigned char *)prop_req, len)) { 465 471 dev->dev_state = MEI_DEV_RESETING; 466 472 dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n"); 467 473 mei_reset(dev, 1);
+25 -42
drivers/misc/mei/interface.c
··· 292 292 int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl) 293 293 { 294 294 struct mei_msg_hdr *mei_hdr; 295 - struct hbm_flow_control *mei_flow_control; 295 + struct hbm_flow_control *flow_ctrl; 296 + const size_t len = sizeof(struct hbm_flow_control); 296 297 297 - mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; 298 - mei_hdr->host_addr = 0; 299 - mei_hdr->me_addr = 0; 300 - mei_hdr->length = sizeof(struct hbm_flow_control); 301 - mei_hdr->msg_complete = 1; 302 - mei_hdr->reserved = 0; 298 + mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 303 299 304 - mei_flow_control = (struct hbm_flow_control *) &dev->wr_msg_buf[1]; 305 - memset(mei_flow_control, 0, sizeof(*mei_flow_control)); 306 - mei_flow_control->host_addr = cl->host_client_id; 307 - mei_flow_control->me_addr = cl->me_client_id; 308 - mei_flow_control->hbm_cmd = MEI_FLOW_CONTROL_CMD; 309 - memset(mei_flow_control->reserved, 0, 310 - sizeof(mei_flow_control->reserved)); 300 + flow_ctrl = (struct hbm_flow_control *)&dev->wr_msg_buf[1]; 301 + memset(flow_ctrl, 0, len); 302 + flow_ctrl->hbm_cmd = MEI_FLOW_CONTROL_CMD; 303 + flow_ctrl->host_addr = cl->host_client_id; 304 + flow_ctrl->me_addr = cl->me_client_id; 305 + /* FIXME: reserved !? */ 306 + memset(flow_ctrl->reserved, 0, sizeof(flow_ctrl->reserved)); 311 307 dev_dbg(&dev->pdev->dev, "sending flow control host client = %d, ME client = %d\n", 312 308 cl->host_client_id, cl->me_client_id); 313 309 314 310 return mei_write_message(dev, mei_hdr, 315 - (unsigned char *) mei_flow_control, 316 - sizeof(struct hbm_flow_control)); 311 + (unsigned char *) flow_ctrl, len); 317 312 } 318 313 319 314 /** ··· 348 353 { 349 354 struct mei_msg_hdr *mei_hdr; 350 355 struct hbm_client_connect_request *req; 356 + const size_t len = sizeof(struct hbm_client_connect_request); 351 357 352 - mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; 353 - mei_hdr->host_addr = 0; 354 - mei_hdr->me_addr = 0; 355 - mei_hdr->length = sizeof(struct hbm_client_connect_request); 356 - mei_hdr->msg_complete = 1; 357 - mei_hdr->reserved = 0; 358 + mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 358 359 359 360 req = (struct hbm_client_connect_request *)&dev->wr_msg_buf[1]; 360 - memset(req, 0, sizeof(*req)); 361 + memset(req, 0, len); 362 + req->hbm_cmd = CLIENT_DISCONNECT_REQ_CMD; 361 363 req->host_addr = cl->host_client_id; 362 364 req->me_addr = cl->me_client_id; 363 - req->hbm_cmd = CLIENT_DISCONNECT_REQ_CMD; 364 365 req->reserved = 0; 365 366 366 - return mei_write_message(dev, mei_hdr, (unsigned char *)req, 367 - sizeof(struct hbm_client_connect_request)); 367 + return mei_write_message(dev, mei_hdr, (unsigned char *)req, len); 368 368 } 369 369 370 370 /** ··· 373 383 int mei_connect(struct mei_device *dev, struct mei_cl *cl) 374 384 { 375 385 struct mei_msg_hdr *mei_hdr; 376 - struct hbm_client_connect_request *mei_cli_connect; 386 + struct hbm_client_connect_request *req; 387 + const size_t len = sizeof(struct hbm_client_connect_request); 377 388 378 - mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; 379 - mei_hdr->host_addr = 0; 380 - mei_hdr->me_addr = 0; 381 - mei_hdr->length = sizeof(struct hbm_client_connect_request); 382 - mei_hdr->msg_complete = 1; 383 - mei_hdr->reserved = 0; 389 + mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 384 390 385 - mei_cli_connect = 386 - (struct hbm_client_connect_request *) &dev->wr_msg_buf[1]; 387 - mei_cli_connect->host_addr = cl->host_client_id; 388 - mei_cli_connect->me_addr = cl->me_client_id; 389 - mei_cli_connect->hbm_cmd = CLIENT_CONNECT_REQ_CMD; 390 - mei_cli_connect->reserved = 0; 391 + req = (struct hbm_client_connect_request *) &dev->wr_msg_buf[1]; 392 + req->hbm_cmd = CLIENT_CONNECT_REQ_CMD; 393 + req->host_addr = cl->host_client_id; 394 + req->me_addr = cl->me_client_id; 395 + req->reserved = 0; 391 396 392 - return mei_write_message(dev, mei_hdr, 393 - (unsigned char *) mei_cli_connect, 394 - sizeof(struct hbm_client_connect_request)); 397 + return mei_write_message(dev, mei_hdr, (unsigned char *) req, len); 395 398 }
+37 -57
drivers/misc/mei/interrupt.c
··· 429 429 static void mei_client_disconnect_request(struct mei_device *dev, 430 430 struct hbm_client_connect_request *disconnect_req) 431 431 { 432 - struct mei_msg_hdr *mei_hdr; 433 432 struct hbm_client_connect_response *disconnect_res; 434 - struct mei_cl *cl_pos = NULL; 435 - struct mei_cl *cl_next = NULL; 433 + struct mei_cl *pos, *next; 434 + const size_t len = sizeof(struct hbm_client_connect_response); 436 435 437 - list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) { 438 - if (same_disconn_addr(cl_pos, disconnect_req)) { 436 + list_for_each_entry_safe(pos, next, &dev->file_list, link) { 437 + if (same_disconn_addr(pos, disconnect_req)) { 439 438 dev_dbg(&dev->pdev->dev, "disconnect request host client %d ME client %d.\n", 440 439 disconnect_req->host_addr, 441 440 disconnect_req->me_addr); 442 - cl_pos->state = MEI_FILE_DISCONNECTED; 443 - cl_pos->timer_count = 0; 444 - if (cl_pos == &dev->wd_cl) 441 + pos->state = MEI_FILE_DISCONNECTED; 442 + pos->timer_count = 0; 443 + if (pos == &dev->wd_cl) 445 444 dev->wd_pending = false; 446 - else if (cl_pos == &dev->iamthif_cl) 445 + else if (pos == &dev->iamthif_cl) 447 446 dev->iamthif_timer = 0; 448 447 449 448 /* prepare disconnect response */ 450 - mei_hdr = 451 - (struct mei_msg_hdr *) &dev->ext_msg_buf[0]; 452 - mei_hdr->host_addr = 0; 453 - mei_hdr->me_addr = 0; 454 - mei_hdr->length = 455 - sizeof(struct hbm_client_connect_response); 456 - mei_hdr->msg_complete = 1; 457 - mei_hdr->reserved = 0; 458 - 449 + (void)mei_hbm_hdr(&dev->ext_msg_buf[0], len); 459 450 disconnect_res = 460 451 (struct hbm_client_connect_response *) 461 452 &dev->ext_msg_buf[1]; 462 - disconnect_res->host_addr = cl_pos->host_client_id; 463 - disconnect_res->me_addr = cl_pos->me_client_id; 464 453 disconnect_res->hbm_cmd = CLIENT_DISCONNECT_RES_CMD; 454 + disconnect_res->host_addr = pos->host_client_id; 455 + disconnect_res->me_addr = pos->me_client_id; 465 456 disconnect_res->status = 0; 466 457 dev->extra_write_index = 2; 467 458 break; 468 459 } 469 460 } 470 461 } 471 - 472 462 473 463 /** 474 464 * mei_irq_thread_read_bus_message - bottom half read routine after ISR to ··· 478 488 struct hbm_flow_control *flow_control; 479 489 struct hbm_props_response *props_res; 480 490 struct hbm_host_enum_response *enum_res; 481 - struct hbm_host_stop_request *host_stop_req; 491 + struct hbm_host_stop_request *stop_req; 482 492 int res; 483 493 484 494 ··· 504 514 return; 505 515 } 506 516 } else { 517 + u32 *buf = dev->wr_msg_buf; 518 + const size_t len = sizeof(struct hbm_host_stop_request); 519 + 507 520 dev->version = version_res->me_max_version; 521 + 508 522 /* send stop message */ 509 - mei_hdr = (struct mei_msg_hdr *)&dev->wr_msg_buf[0]; 510 - mei_hdr->host_addr = 0; 511 - mei_hdr->me_addr = 0; 512 - mei_hdr->length = sizeof(struct hbm_host_stop_request); 513 - mei_hdr->msg_complete = 1; 514 - mei_hdr->reserved = 0; 523 + mei_hdr = mei_hbm_hdr(&buf[0], len); 524 + stop_req = (struct hbm_host_stop_request *)&buf[1]; 525 + memset(stop_req, 0, len); 526 + stop_req->hbm_cmd = HOST_STOP_REQ_CMD; 527 + stop_req->reason = DRIVER_STOP_REQUEST; 515 528 516 - host_stop_req = (struct hbm_host_stop_request *) 517 - &dev->wr_msg_buf[1]; 518 - 519 - memset(host_stop_req, 520 - 0, 521 - sizeof(struct hbm_host_stop_request)); 522 - host_stop_req->hbm_cmd = HOST_STOP_REQ_CMD; 523 - host_stop_req->reason = DRIVER_STOP_REQUEST; 524 529 mei_write_message(dev, mei_hdr, 525 - (unsigned char *) (host_stop_req), 526 - mei_hdr->length); 530 + (unsigned char *)stop_req, len); 527 531 dev_dbg(&dev->pdev->dev, "version mismatch.\n"); 528 532 return; 529 533 } ··· 527 543 break; 528 544 529 545 case CLIENT_CONNECT_RES_CMD: 530 - connect_res = 531 - (struct hbm_client_connect_response *) mei_msg; 546 + connect_res = (struct hbm_client_connect_response *) mei_msg; 532 547 mei_client_connect_response(dev, connect_res); 533 548 dev_dbg(&dev->pdev->dev, "client connect response message received.\n"); 534 549 wake_up(&dev->wait_recvd_msg); 535 550 break; 536 551 537 552 case CLIENT_DISCONNECT_RES_CMD: 538 - disconnect_res = 539 - (struct hbm_client_connect_response *) mei_msg; 553 + disconnect_res = (struct hbm_client_connect_response *) mei_msg; 540 554 mei_client_disconnect_response(dev, disconnect_res); 541 555 dev_dbg(&dev->pdev->dev, "client disconnect response message received.\n"); 542 556 wake_up(&dev->wait_recvd_msg); ··· 640 658 break; 641 659 642 660 case ME_STOP_REQ_CMD: 643 - /* prepare stop request */ 644 - mei_hdr = (struct mei_msg_hdr *) &dev->ext_msg_buf[0]; 645 - mei_hdr->host_addr = 0; 646 - mei_hdr->me_addr = 0; 647 - mei_hdr->length = sizeof(struct hbm_host_stop_request); 648 - mei_hdr->msg_complete = 1; 649 - mei_hdr->reserved = 0; 650 - host_stop_req = 651 - (struct hbm_host_stop_request *) &dev->ext_msg_buf[1]; 652 - memset(host_stop_req, 0, sizeof(struct hbm_host_stop_request)); 653 - host_stop_req->hbm_cmd = HOST_STOP_REQ_CMD; 654 - host_stop_req->reason = DRIVER_STOP_REQUEST; 655 - host_stop_req->reserved[0] = 0; 656 - host_stop_req->reserved[1] = 0; 661 + { 662 + /* prepare stop request: sent in next interrupt event */ 663 + 664 + u32 *buf = dev->ext_msg_buf; 665 + const size_t len = sizeof(struct hbm_host_stop_request); 666 + 667 + mei_hdr = mei_hbm_hdr(&buf[0], len); 668 + stop_req = (struct hbm_host_stop_request *)&buf[1]; 669 + memset(stop_req, 0, len); 670 + stop_req->hbm_cmd = HOST_STOP_REQ_CMD; 671 + stop_req->reason = DRIVER_STOP_REQUEST; 672 + 657 673 dev->extra_write_index = 2; 658 674 break; 659 - 675 + } 660 676 default: 661 677 BUG(); 662 678 break;
+11
drivers/misc/mei/mei_dev.h
··· 491 491 void mei_enable_interrupts(struct mei_device *dev); 492 492 void mei_disable_interrupts(struct mei_device *dev); 493 493 494 + static inline struct mei_msg_hdr *mei_hbm_hdr(u32 *buf, size_t length) 495 + { 496 + struct mei_msg_hdr *hdr = (struct mei_msg_hdr *)buf; 497 + hdr->host_addr = 0; 498 + hdr->me_addr = 0; 499 + hdr->length = length; 500 + hdr->msg_complete = 1; 501 + hdr->reserved = 0; 502 + return hdr; 503 + } 504 + 494 505 #endif