aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/mei
diff options
context:
space:
mode:
authorAlexander Usyskin <alexander.usyskin@intel.com>2014-02-17 08:13:23 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-02-18 13:05:33 -0500
commit12d0066526f386538de80b4d86d2008461b36674 (patch)
treefcde1b185663b1fecbb9ffc683c59baf2e6ca3ee /drivers/misc/mei
parenta27a76d3c07de08a0d0d298b6bc280c5b820e997 (diff)
mei: use helper function to find me client by id
We already have a helper to find me client by id, let's use it in all relevant places. 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>
Diffstat (limited to 'drivers/misc/mei')
-rw-r--r--drivers/misc/mei/client.c62
-rw-r--r--drivers/misc/mei/hbm.c42
2 files changed, 56 insertions, 48 deletions
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index 539e861abc1e..3e62176a19a5 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -552,7 +552,8 @@ out:
552int mei_cl_flow_ctrl_creds(struct mei_cl *cl) 552int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
553{ 553{
554 struct mei_device *dev; 554 struct mei_device *dev;
555 int i; 555 struct mei_me_client *me_cl;
556 int id;
556 557
557 if (WARN_ON(!cl || !cl->dev)) 558 if (WARN_ON(!cl || !cl->dev))
558 return -EINVAL; 559 return -EINVAL;
@@ -565,19 +566,19 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
565 if (cl->mei_flow_ctrl_creds > 0) 566 if (cl->mei_flow_ctrl_creds > 0)
566 return 1; 567 return 1;
567 568
568 for (i = 0; i < dev->me_clients_num; i++) { 569 id = mei_me_cl_by_id(dev, cl->me_client_id);
569 struct mei_me_client *me_cl = &dev->me_clients[i]; 570 if (id < 0) {
570 if (me_cl->client_id == cl->me_client_id) { 571 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
571 if (me_cl->mei_flow_ctrl_creds) { 572 return id;
572 if (WARN_ON(me_cl->props.single_recv_buf == 0))
573 return -EINVAL;
574 return 1;
575 } else {
576 return 0;
577 }
578 }
579 } 573 }
580 return -ENOENT; 574
575 me_cl = &dev->me_clients[id];
576 if (me_cl->mei_flow_ctrl_creds) {
577 if (WARN_ON(me_cl->props.single_recv_buf == 0))
578 return -EINVAL;
579 return 1;
580 }
581 return 0;
581} 582}
582 583
583/** 584/**
@@ -593,32 +594,31 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
593int mei_cl_flow_ctrl_reduce(struct mei_cl *cl) 594int mei_cl_flow_ctrl_reduce(struct mei_cl *cl)
594{ 595{
595 struct mei_device *dev; 596 struct mei_device *dev;
596 int i; 597 struct mei_me_client *me_cl;
598 int id;
597 599
598 if (WARN_ON(!cl || !cl->dev)) 600 if (WARN_ON(!cl || !cl->dev))
599 return -EINVAL; 601 return -EINVAL;
600 602
601 dev = cl->dev; 603 dev = cl->dev;
602 604
603 if (!dev->me_clients_num) 605 id = mei_me_cl_by_id(dev, cl->me_client_id);
604 return -ENOENT; 606 if (id < 0) {
607 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
608 return id;
609 }
605 610
606 for (i = 0; i < dev->me_clients_num; i++) { 611 me_cl = &dev->me_clients[id];
607 struct mei_me_client *me_cl = &dev->me_clients[i]; 612 if (me_cl->props.single_recv_buf != 0) {
608 if (me_cl->client_id == cl->me_client_id) { 613 if (WARN_ON(me_cl->mei_flow_ctrl_creds <= 0))
609 if (me_cl->props.single_recv_buf != 0) { 614 return -EINVAL;
610 if (WARN_ON(me_cl->mei_flow_ctrl_creds <= 0)) 615 me_cl->mei_flow_ctrl_creds--;
611 return -EINVAL; 616 } else {
612 dev->me_clients[i].mei_flow_ctrl_creds--; 617 if (WARN_ON(cl->mei_flow_ctrl_creds <= 0))
613 } else { 618 return -EINVAL;
614 if (WARN_ON(cl->mei_flow_ctrl_creds <= 0)) 619 cl->mei_flow_ctrl_creds--;
615 return -EINVAL;
616 cl->mei_flow_ctrl_creds--;
617 }
618 return 0;
619 }
620 } 620 }
621 return -ENOENT; 621 return 0;
622} 622}
623 623
624/** 624/**
diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c
index 46743e2349b1..7e99e4149626 100644
--- a/drivers/misc/mei/hbm.c
+++ b/drivers/misc/mei/hbm.c
@@ -22,6 +22,7 @@
22#include "mei_dev.h" 22#include "mei_dev.h"
23#include "hbm.h" 23#include "hbm.h"
24#include "hw-me.h" 24#include "hw-me.h"
25#include "client.h"
25 26
26static const char *mei_cl_conn_status_str(enum mei_cl_connect_status status) 27static const char *mei_cl_conn_status_str(enum mei_cl_connect_status status)
27{ 28{
@@ -340,27 +341,34 @@ int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl)
340 * 341 *
341 * @dev: the device structure 342 * @dev: the device structure
342 * @flow: flow control. 343 * @flow: flow control.
344 *
345 * return 0 on success, < 0 otherwise
343 */ 346 */
344static void mei_hbm_add_single_flow_creds(struct mei_device *dev, 347static int mei_hbm_add_single_flow_creds(struct mei_device *dev,
345 struct hbm_flow_control *flow) 348 struct hbm_flow_control *flow)
346{ 349{
347 struct mei_me_client *client; 350 struct mei_me_client *me_cl;
348 int i; 351 int id;
349 352
350 for (i = 0; i < dev->me_clients_num; i++) { 353 id = mei_me_cl_by_id(dev, flow->me_addr);
351 client = &dev->me_clients[i]; 354 if (id < 0) {
352 if (client && flow->me_addr == client->client_id) { 355 dev_err(&dev->pdev->dev, "no such me client %d\n",
353 if (client->props.single_recv_buf) { 356 flow->me_addr);
354 client->mei_flow_ctrl_creds++; 357 return id;
355 dev_dbg(&dev->pdev->dev, "recv flow ctrl msg ME %d (single).\n",
356 flow->me_addr);
357 dev_dbg(&dev->pdev->dev, "flow control credentials =%d.\n",
358 client->mei_flow_ctrl_creds);
359 } else {
360 BUG(); /* error in flow control */
361 }
362 }
363 } 358 }
359
360 me_cl = &dev->me_clients[id];
361 if (me_cl->props.single_recv_buf) {
362 me_cl->mei_flow_ctrl_creds++;
363 dev_dbg(&dev->pdev->dev, "recv flow ctrl msg ME %d (single).\n",
364 flow->me_addr);
365 dev_dbg(&dev->pdev->dev, "flow control credentials =%d.\n",
366 me_cl->mei_flow_ctrl_creds);
367 } else {
368 BUG(); /* error in flow control */
369 }
370
371 return 0;
364} 372}
365 373
366/** 374/**