aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2013-01-08 16:07:14 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-01-08 19:40:44 -0500
commit90e0b5f18569bdd03c5ddd1d8c99946f42af77b8 (patch)
tree2d70ede445345397032a92fe9f5e24eb8d3c4981
parent9ca9050b3df690d9d44e39424ab2a531120af936 (diff)
mei: fix client functions names
Use common prefix for function names: mei_cl_ - for host clients mei_me_ - for me clients mei_io_ - for io callback functions Because mei_cl holds mei_device back pointer we can also drop the dev argument from the client functions add client.h header to export the clients API Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/misc/mei/amthif.c9
-rw-r--r--drivers/misc/mei/client.c221
-rw-r--r--drivers/misc/mei/client.h97
-rw-r--r--drivers/misc/mei/init.c6
-rw-r--r--drivers/misc/mei/interface.h8
-rw-r--r--drivers/misc/mei/interrupt.c11
-rw-r--r--drivers/misc/mei/main.c47
-rw-r--r--drivers/misc/mei/mei_dev.h53
-rw-r--r--drivers/misc/mei/wd.c13
9 files changed, 267 insertions, 198 deletions
diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c
index add4254eb850..cbc9c4e4e321 100644
--- a/drivers/misc/mei/amthif.c
+++ b/drivers/misc/mei/amthif.c
@@ -36,6 +36,7 @@
36#include "mei_dev.h" 36#include "mei_dev.h"
37#include "hbm.h" 37#include "hbm.h"
38#include "interface.h" 38#include "interface.h"
39#include "client.h"
39 40
40const uuid_le mei_amthi_guid = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, 0xac, 41const uuid_le mei_amthi_guid = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, 0xac,
41 0xa8, 0x46, 0xe0, 0xff, 0x65, 42 0xa8, 0x46, 0xe0, 0xff, 0x65,
@@ -73,7 +74,7 @@ void mei_amthif_host_init(struct mei_device *dev)
73 dev->iamthif_cl.state = MEI_FILE_DISCONNECTED; 74 dev->iamthif_cl.state = MEI_FILE_DISCONNECTED;
74 75
75 /* find ME amthi client */ 76 /* find ME amthi client */
76 i = mei_me_cl_link(dev, &dev->iamthif_cl, 77 i = mei_cl_link_me(&dev->iamthif_cl,
77 &mei_amthi_guid, MEI_IAMTHIF_HOST_CLIENT_ID); 78 &mei_amthi_guid, MEI_IAMTHIF_HOST_CLIENT_ID);
78 if (i < 0) { 79 if (i < 0) {
79 dev_info(&dev->pdev->dev, "failed to find iamthif client.\n"); 80 dev_info(&dev->pdev->dev, "failed to find iamthif client.\n");
@@ -280,7 +281,7 @@ static int mei_amthif_send_cmd(struct mei_device *dev, struct mei_cl_cb *cb)
280 memcpy(dev->iamthif_msg_buf, cb->request_buffer.data, 281 memcpy(dev->iamthif_msg_buf, cb->request_buffer.data,
281 cb->request_buffer.size); 282 cb->request_buffer.size);
282 283
283 ret = mei_flow_ctrl_creds(dev, &dev->iamthif_cl); 284 ret = mei_cl_flow_ctrl_creds(&dev->iamthif_cl);
284 if (ret < 0) 285 if (ret < 0)
285 return ret; 286 return ret;
286 287
@@ -304,7 +305,7 @@ static int mei_amthif_send_cmd(struct mei_device *dev, struct mei_cl_cb *cb)
304 return -ENODEV; 305 return -ENODEV;
305 306
306 if (mei_hdr.msg_complete) { 307 if (mei_hdr.msg_complete) {
307 if (mei_flow_ctrl_reduce(dev, &dev->iamthif_cl)) 308 if (mei_cl_flow_ctrl_reduce(&dev->iamthif_cl))
308 return -ENODEV; 309 return -ENODEV;
309 dev->iamthif_flow_control_pending = true; 310 dev->iamthif_flow_control_pending = true;
310 dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL; 311 dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL;
@@ -467,7 +468,7 @@ int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
467 return -ENODEV; 468 return -ENODEV;
468 } 469 }
469 470
470 if (mei_flow_ctrl_reduce(dev, cl)) 471 if (mei_cl_flow_ctrl_reduce(cl))
471 return -ENODEV; 472 return -ENODEV;
472 473
473 dev->iamthif_msg_buf_index += mei_hdr.length; 474 dev->iamthif_msg_buf_index += mei_hdr.length;
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index 19f62073fa67..e300637c89ed 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -24,6 +24,54 @@
24#include "mei_dev.h" 24#include "mei_dev.h"
25#include "hbm.h" 25#include "hbm.h"
26#include "interface.h" 26#include "interface.h"
27#include "client.h"
28
29/**
30 * mei_me_cl_by_uuid - locate index of me client
31 *
32 * @dev: mei device
33 * returns me client index or -ENOENT if not found
34 */
35int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *uuid)
36{
37 int i, res = -ENOENT;
38
39 for (i = 0; i < dev->me_clients_num; ++i)
40 if (uuid_le_cmp(*uuid,
41 dev->me_clients[i].props.protocol_name) == 0) {
42 res = i;
43 break;
44 }
45
46 return res;
47}
48
49
50/**
51 * mei_me_cl_by_id return index to me_clients for client_id
52 *
53 * @dev: the device structure
54 * @client_id: me client id
55 *
56 * Locking: called under "dev->device_lock" lock
57 *
58 * returns index on success, -ENOENT on failure.
59 */
60
61int mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
62{
63 int i;
64 for (i = 0; i < dev->me_clients_num; i++)
65 if (dev->me_clients[i].client_id == client_id)
66 break;
67 if (WARN_ON(dev->me_clients[i].client_id != client_id))
68 return -ENOENT;
69
70 if (i == dev->me_clients_num)
71 return -ENOENT;
72
73 return i;
74}
27 75
28 76
29/** 77/**
@@ -141,7 +189,7 @@ int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length)
141 */ 189 */
142int mei_cl_flush_queues(struct mei_cl *cl) 190int mei_cl_flush_queues(struct mei_cl *cl)
143{ 191{
144 if (!cl || !cl->dev) 192 if (WARN_ON(!cl || !cl->dev))
145 return -EINVAL; 193 return -EINVAL;
146 194
147 dev_dbg(&cl->dev->pdev->dev, "remove list entry belonging to cl\n"); 195 dev_dbg(&cl->dev->pdev->dev, "remove list entry belonging to cl\n");
@@ -155,52 +203,6 @@ int mei_cl_flush_queues(struct mei_cl *cl)
155 return 0; 203 return 0;
156} 204}
157 205
158/**
159 * mei_me_cl_by_uuid - locate index of me client
160 *
161 * @dev: mei device
162 * returns me client index or -ENOENT if not found
163 */
164int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *uuid)
165{
166 int i, res = -ENOENT;
167
168 for (i = 0; i < dev->me_clients_num; ++i)
169 if (uuid_le_cmp(*uuid,
170 dev->me_clients[i].props.protocol_name) == 0) {
171 res = i;
172 break;
173 }
174
175 return res;
176}
177
178
179/**
180 * mei_me_cl_by_id return index to me_clients for client_id
181 *
182 * @dev: the device structure
183 * @client_id: me client id
184 *
185 * Locking: called under "dev->device_lock" lock
186 *
187 * returns index on success, -ENOENT on failure.
188 */
189
190int mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
191{
192 int i;
193 for (i = 0; i < dev->me_clients_num; i++)
194 if (dev->me_clients[i].client_id == client_id)
195 break;
196 if (WARN_ON(dev->me_clients[i].client_id != client_id))
197 return -ENOENT;
198
199 if (i == dev->me_clients_num)
200 return -ENOENT;
201
202 return i;
203}
204 206
205/** 207/**
206 * mei_cl_init - initializes intialize cl. 208 * mei_cl_init - initializes intialize cl.
@@ -239,12 +241,29 @@ struct mei_cl *mei_cl_allocate(struct mei_device *dev)
239 return cl; 241 return cl;
240} 242}
241 243
244/**
245 * mei_cl_find_read_cb - find this cl's callback in the read list
246 *
247 * @dev: device structure
248 * returns cb on success, NULL on error
249 */
250struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl)
251{
252 struct mei_device *dev = cl->dev;
253 struct mei_cl_cb *cb = NULL;
254 struct mei_cl_cb *next = NULL;
255
256 list_for_each_entry_safe(cb, next, &dev->read_list.list, list)
257 if (mei_cl_cmp_id(cl, cb->cl))
258 return cb;
259 return NULL;
260}
261
242 262
243/** 263/**
244 * mei_me_cl_link - create link between host and me clinet and add 264 * mei_me_cl_link - create link between host and me clinet and add
245 * me_cl to the list 265 * me_cl to the list
246 * 266 *
247 * @dev: the device structure
248 * @cl: link between me and host client assocated with opened file descriptor 267 * @cl: link between me and host client assocated with opened file descriptor
249 * @uuid: uuid of ME client 268 * @uuid: uuid of ME client
250 * @client_id: id of the host client 269 * @client_id: id of the host client
@@ -253,14 +272,16 @@ struct mei_cl *mei_cl_allocate(struct mei_device *dev)
253 * -EINVAL on incorrect values 272 * -EINVAL on incorrect values
254 * -ENONET if client not found 273 * -ENONET if client not found
255 */ 274 */
256int mei_me_cl_link(struct mei_device *dev, struct mei_cl *cl, 275int mei_cl_link_me(struct mei_cl *cl, const uuid_le *uuid, u8 host_cl_id)
257 const uuid_le *uuid, u8 host_cl_id)
258{ 276{
277 struct mei_device *dev;
259 int i; 278 int i;
260 279
261 if (!dev || !cl || !uuid) 280 if (WARN_ON(!cl || !cl->dev || !uuid))
262 return -EINVAL; 281 return -EINVAL;
263 282
283 dev = cl->dev;
284
264 /* check for valid client id */ 285 /* check for valid client id */
265 i = mei_me_cl_by_uuid(dev, uuid); 286 i = mei_me_cl_by_uuid(dev, uuid);
266 if (i >= 0) { 287 if (i >= 0) {
@@ -275,22 +296,30 @@ int mei_me_cl_link(struct mei_device *dev, struct mei_cl *cl,
275 return -ENOENT; 296 return -ENOENT;
276} 297}
277/** 298/**
278 * mei_me_cl_unlink - remove me_cl from the list 299 * mei_cl_unlink - remove me_cl from the list
279 * 300 *
280 * @dev: the device structure 301 * @dev: the device structure
281 * @host_client_id: host client id to be removed 302 * @host_client_id: host client id to be removed
282 */ 303 */
283void mei_me_cl_unlink(struct mei_device *dev, struct mei_cl *cl) 304int mei_cl_unlink(struct mei_cl *cl)
284{ 305{
306 struct mei_device *dev;
285 struct mei_cl *pos, *next; 307 struct mei_cl *pos, *next;
308
309 if (WARN_ON(!cl || !cl->dev))
310 return -EINVAL;
311
312 dev = cl->dev;
313
286 list_for_each_entry_safe(pos, next, &dev->file_list, link) { 314 list_for_each_entry_safe(pos, next, &dev->file_list, link) {
287 if (cl->host_client_id == pos->host_client_id) { 315 if (cl->host_client_id == pos->host_client_id) {
288 dev_dbg(&dev->pdev->dev, "remove host client = %d, ME client = %d\n", 316 dev_dbg(&dev->pdev->dev, "remove host client = %d, ME client = %d\n",
289 pos->host_client_id, pos->me_client_id); 317 pos->host_client_id, pos->me_client_id);
290 list_del_init(&pos->link); 318 list_del_init(&pos->link);
291 break; 319 break;
292 } 320 }
293 } 321 }
322 return 0;
294} 323}
295 324
296 325
@@ -330,23 +359,25 @@ void mei_host_client_init(struct work_struct *work)
330 359
331 360
332/** 361/**
333 * mei_disconnect_host_client - sends disconnect message to fw from host client. 362 * mei_cl_disconnect - disconnect host clinet form the me one
334 * 363 *
335 * @dev: the device structure 364 * @cl: host client
336 * @cl: private data of the file object
337 * 365 *
338 * Locking: called under "dev->device_lock" lock 366 * Locking: called under "dev->device_lock" lock
339 * 367 *
340 * returns 0 on success, <0 on failure. 368 * returns 0 on success, <0 on failure.
341 */ 369 */
342int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl) 370int mei_cl_disconnect(struct mei_cl *cl)
343{ 371{
372 struct mei_device *dev;
344 struct mei_cl_cb *cb; 373 struct mei_cl_cb *cb;
345 int rets, err; 374 int rets, err;
346 375
347 if (!dev || !cl) 376 if (WARN_ON(!cl || !cl->dev))
348 return -ENODEV; 377 return -ENODEV;
349 378
379 dev = cl->dev;
380
350 if (cl->state != MEI_FILE_DISCONNECTING) 381 if (cl->state != MEI_FILE_DISCONNECTING)
351 return 0; 382 return 0;
352 383
@@ -401,32 +432,36 @@ free:
401 432
402 433
403/** 434/**
404 * mei_other_client_is_connecting - checks if other 435 * mei_cl_is_other_connecting - checks if other
405 * client with the same client id is connected. 436 * client with the same me client id is connecting
406 * 437 *
407 * @dev: the device structure
408 * @cl: private data of the file object 438 * @cl: private data of the file object
409 * 439 *
410 * returns 1 if other client is connected, 0 - otherwise. 440 * returns ture if other client is connected, 0 - otherwise.
411 */ 441 */
412int mei_other_client_is_connecting(struct mei_device *dev, 442bool mei_cl_is_other_connecting(struct mei_cl *cl)
413 struct mei_cl *cl)
414{ 443{
415 struct mei_cl *cl_pos = NULL; 444 struct mei_device *dev;
416 struct mei_cl *cl_next = NULL; 445 struct mei_cl *pos;
446 struct mei_cl *next;
417 447
418 list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) { 448 if (WARN_ON(!cl || !cl->dev))
419 if ((cl_pos->state == MEI_FILE_CONNECTING) && 449 return false;
420 (cl_pos != cl) && 450
421 cl->me_client_id == cl_pos->me_client_id) 451 dev = cl->dev;
422 return 1; 452
453 list_for_each_entry_safe(pos, next, &dev->file_list, link) {
454 if ((pos->state == MEI_FILE_CONNECTING) &&
455 (pos != cl) && cl->me_client_id == pos->me_client_id)
456 return true;
423 457
424 } 458 }
425 return 0; 459
460 return false;
426} 461}
427 462
428/** 463/**
429 * mei_flow_ctrl_creds - checks flow_control credentials. 464 * mei_cl_flow_ctrl_creds - checks flow_control credits for cl.
430 * 465 *
431 * @dev: the device structure 466 * @dev: the device structure
432 * @cl: private data of the file object 467 * @cl: private data of the file object
@@ -435,10 +470,16 @@ int mei_other_client_is_connecting(struct mei_device *dev,
435 * -ENOENT if mei_cl is not present 470 * -ENOENT if mei_cl is not present
436 * -EINVAL if single_recv_buf == 0 471 * -EINVAL if single_recv_buf == 0
437 */ 472 */
438int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl) 473int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
439{ 474{
475 struct mei_device *dev;
440 int i; 476 int i;
441 477
478 if (WARN_ON(!cl || !cl->dev))
479 return -EINVAL;
480
481 dev = cl->dev;
482
442 if (!dev->me_clients_num) 483 if (!dev->me_clients_num)
443 return 0; 484 return 0;
444 485
@@ -461,7 +502,7 @@ int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl)
461} 502}
462 503
463/** 504/**
464 * mei_flow_ctrl_reduce - reduces flow_control. 505 * mei_cl_flow_ctrl_reduce - reduces flow_control.
465 * 506 *
466 * @dev: the device structure 507 * @dev: the device structure
467 * @cl: private data of the file object 508 * @cl: private data of the file object
@@ -470,10 +511,16 @@ int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl)
470 * -ENOENT when me client is not found 511 * -ENOENT when me client is not found
471 * -EINVAL when ctrl credits are <= 0 512 * -EINVAL when ctrl credits are <= 0
472 */ 513 */
473int mei_flow_ctrl_reduce(struct mei_device *dev, struct mei_cl *cl) 514int mei_cl_flow_ctrl_reduce(struct mei_cl *cl)
474{ 515{
516 struct mei_device *dev;
475 int i; 517 int i;
476 518
519 if (WARN_ON(!cl || !cl->dev))
520 return -EINVAL;
521
522 dev = cl->dev;
523
477 if (!dev->me_clients_num) 524 if (!dev->me_clients_num)
478 return -ENOENT; 525 return -ENOENT;
479 526
@@ -571,7 +618,7 @@ int mei_ioctl_connect_client(struct file *file,
571 goto end; 618 goto end;
572 } 619 }
573 clear_bit(cl->host_client_id, dev->host_clients_map); 620 clear_bit(cl->host_client_id, dev->host_clients_map);
574 mei_me_cl_unlink(dev, cl); 621 mei_cl_unlink(cl);
575 622
576 kfree(cl); 623 kfree(cl);
577 cl = NULL; 624 cl = NULL;
@@ -598,8 +645,8 @@ int mei_ioctl_connect_client(struct file *file,
598 client->max_msg_length = dev->me_clients[i].props.max_msg_length; 645 client->max_msg_length = dev->me_clients[i].props.max_msg_length;
599 client->protocol_version = dev->me_clients[i].props.protocol_version; 646 client->protocol_version = dev->me_clients[i].props.protocol_version;
600 dev_dbg(&dev->pdev->dev, "Can connect?\n"); 647 dev_dbg(&dev->pdev->dev, "Can connect?\n");
601 if (dev->mei_host_buffer_is_empty 648 if (dev->mei_host_buffer_is_empty &&
602 && !mei_other_client_is_connecting(dev, cl)) { 649 !mei_cl_is_other_connecting(cl)) {
603 dev_dbg(&dev->pdev->dev, "Sending Connect Message\n"); 650 dev_dbg(&dev->pdev->dev, "Sending Connect Message\n");
604 dev->mei_host_buffer_is_empty = false; 651 dev->mei_host_buffer_is_empty = false;
605 if (mei_hbm_cl_connect_req(dev, cl)) { 652 if (mei_hbm_cl_connect_req(dev, cl)) {
@@ -650,20 +697,24 @@ end:
650} 697}
651 698
652/** 699/**
653 * mei_start_read - the start read client message function. 700 * mei_cl_start_read - the start read client message function.
654 * 701 *
655 * @dev: the device structure 702 * @cl: host client
656 * @if_num: minor number
657 * @cl: private data of the file object
658 * 703 *
659 * returns 0 on success, <0 on failure. 704 * returns 0 on success, <0 on failure.
660 */ 705 */
661int mei_start_read(struct mei_device *dev, struct mei_cl *cl) 706int mei_cl_read_start(struct mei_cl *cl)
662{ 707{
708 struct mei_device *dev;
663 struct mei_cl_cb *cb; 709 struct mei_cl_cb *cb;
664 int rets; 710 int rets;
665 int i; 711 int i;
666 712
713 if (WARN_ON(!cl || !cl->dev))
714 return -ENODEV;
715
716 dev = cl->dev;
717
667 if (cl->state != MEI_FILE_CONNECTED) 718 if (cl->state != MEI_FILE_CONNECTED)
668 return -ENODEV; 719 return -ENODEV;
669 720
diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h
new file mode 100644
index 000000000000..8dfd052dd0e6
--- /dev/null
+++ b/drivers/misc/mei/client.h
@@ -0,0 +1,97 @@
1/*
2 *
3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2012, Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 */
16
17#ifndef _MEI_CLIENT_H_
18#define _MEI_CLIENT_H_
19
20#include <linux/types.h>
21#include <linux/watchdog.h>
22#include <linux/poll.h>
23#include <linux/mei.h>
24
25#include "mei_dev.h"
26
27int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);
28int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
29
30/*
31 * MEI IO Functions
32 */
33struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp);
34void mei_io_cb_free(struct mei_cl_cb *priv_cb);
35int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length);
36int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length);
37
38
39/**
40 * mei_io_list_init - Sets up a queue list.
41 *
42 * @list: An instance cl callback structure
43 */
44static inline void mei_io_list_init(struct mei_cl_cb *list)
45{
46 INIT_LIST_HEAD(&list->list);
47}
48void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl);
49
50/*
51 * MEI Host Client Functions
52 */
53
54struct mei_cl *mei_cl_allocate(struct mei_device *dev);
55void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
56
57
58int mei_cl_link_me(struct mei_cl *cl, const uuid_le *uuid, u8 host_cl_id);
59int mei_cl_unlink(struct mei_cl *cl);
60
61int mei_cl_flush_queues(struct mei_cl *cl);
62struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl);
63
64/**
65 * mei_cl_cmp_id - tells if file private data have same id
66 *
67 * @fe1: private data of 1. file object
68 * @fe2: private data of 2. file object
69 *
70 * returns true - if ids are the same and not NULL
71 */
72static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
73 const struct mei_cl *cl2)
74{
75 return cl1 && cl2 &&
76 (cl1->host_client_id == cl2->host_client_id) &&
77 (cl1->me_client_id == cl2->me_client_id);
78}
79
80
81int mei_cl_flow_ctrl_creds(struct mei_cl *cl);
82
83int mei_cl_flow_ctrl_reduce(struct mei_cl *cl);
84/*
85 * MEI input output function prototype
86 */
87bool mei_cl_is_other_connecting(struct mei_cl *cl);
88int mei_cl_disconnect(struct mei_cl *cl);
89
90int mei_cl_read_start(struct mei_cl *cl);
91
92int mei_cl_connect(struct mei_cl *cl, struct file *file);
93
94void mei_host_client_init(struct work_struct *work);
95
96
97#endif /* _MEI_CLIENT_H_ */
diff --git a/drivers/misc/mei/init.c b/drivers/misc/mei/init.c
index 6c1f1f838d2b..7028dbd99cf7 100644
--- a/drivers/misc/mei/init.c
+++ b/drivers/misc/mei/init.c
@@ -23,6 +23,7 @@
23 23
24#include "mei_dev.h" 24#include "mei_dev.h"
25#include "interface.h" 25#include "interface.h"
26#include "client.h"
26 27
27const char *mei_dev_state_str(int state) 28const char *mei_dev_state_str(int state)
28{ 29{
@@ -241,9 +242,8 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
241 } 242 }
242 /* remove entry if already in list */ 243 /* remove entry if already in list */
243 dev_dbg(&dev->pdev->dev, "remove iamthif and wd from the file list.\n"); 244 dev_dbg(&dev->pdev->dev, "remove iamthif and wd from the file list.\n");
244 mei_me_cl_unlink(dev, &dev->wd_cl); 245 mei_cl_unlink(&dev->wd_cl);
245 246 mei_cl_unlink(&dev->iamthif_cl);
246 mei_me_cl_unlink(dev, &dev->iamthif_cl);
247 247
248 mei_amthif_reset_params(dev); 248 mei_amthif_reset_params(dev);
249 memset(&dev->wr_ext_msg, 0, sizeof(dev->wr_ext_msg)); 249 memset(&dev->wr_ext_msg, 0, sizeof(dev->wr_ext_msg));
diff --git a/drivers/misc/mei/interface.h b/drivers/misc/mei/interface.h
index 3d06c087ddd2..01d1ef518595 100644
--- a/drivers/misc/mei/interface.h
+++ b/drivers/misc/mei/interface.h
@@ -50,7 +50,6 @@ static inline unsigned char mei_data2slots(size_t length)
50int mei_count_full_read_slots(struct mei_device *dev); 50int mei_count_full_read_slots(struct mei_device *dev);
51 51
52 52
53int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl);
54 53
55 54
56 55
@@ -69,12 +68,5 @@ void mei_watchdog_register(struct mei_device *dev);
69 */ 68 */
70void mei_watchdog_unregister(struct mei_device *dev); 69void mei_watchdog_unregister(struct mei_device *dev);
71 70
72int mei_other_client_is_connecting(struct mei_device *dev, struct mei_cl *cl);
73int mei_flow_ctrl_reduce(struct mei_device *dev, struct mei_cl *cl);
74
75void mei_host_client_init(struct work_struct *work);
76
77
78
79 71
80#endif /* _MEI_INTERFACE_H_ */ 72#endif /* _MEI_INTERFACE_H_ */
diff --git a/drivers/misc/mei/interrupt.c b/drivers/misc/mei/interrupt.c
index 2495e35ccb27..0a141afcea89 100644
--- a/drivers/misc/mei/interrupt.c
+++ b/drivers/misc/mei/interrupt.c
@@ -26,6 +26,7 @@
26#include "mei_dev.h" 26#include "mei_dev.h"
27#include "hbm.h" 27#include "hbm.h"
28#include "interface.h" 28#include "interface.h"
29#include "client.h"
29 30
30 31
31/** 32/**
@@ -297,7 +298,7 @@ static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots,
297 return -ENODEV; 298 return -ENODEV;
298 } 299 }
299 300
300 if (mei_flow_ctrl_reduce(dev, cl)) 301 if (mei_cl_flow_ctrl_reduce(cl))
301 return -ENODEV; 302 return -ENODEV;
302 303
303 cl->status = 0; 304 cl->status = 0;
@@ -478,10 +479,10 @@ static int mei_irq_thread_write_handler(struct mei_device *dev,
478 } 479 }
479 if (dev->dev_state == MEI_DEV_ENABLED) { 480 if (dev->dev_state == MEI_DEV_ENABLED) {
480 if (dev->wd_pending && 481 if (dev->wd_pending &&
481 mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) { 482 mei_cl_flow_ctrl_creds(&dev->wd_cl) > 0) {
482 if (mei_wd_send(dev)) 483 if (mei_wd_send(dev))
483 dev_dbg(&dev->pdev->dev, "wd send failed.\n"); 484 dev_dbg(&dev->pdev->dev, "wd send failed.\n");
484 else if (mei_flow_ctrl_reduce(dev, &dev->wd_cl)) 485 else if (mei_cl_flow_ctrl_reduce(&dev->wd_cl))
485 return -ENODEV; 486 return -ENODEV;
486 487
487 dev->wd_pending = false; 488 dev->wd_pending = false;
@@ -520,7 +521,7 @@ static int mei_irq_thread_write_handler(struct mei_device *dev,
520 break; 521 break;
521 case MEI_FOP_IOCTL: 522 case MEI_FOP_IOCTL:
522 /* connect message */ 523 /* connect message */
523 if (mei_other_client_is_connecting(dev, cl)) 524 if (mei_cl_is_other_connecting(cl))
524 continue; 525 continue;
525 ret = _mei_irq_thread_ioctl(dev, &slots, pos, 526 ret = _mei_irq_thread_ioctl(dev, &slots, pos,
526 cl, cmpl_list); 527 cl, cmpl_list);
@@ -540,7 +541,7 @@ static int mei_irq_thread_write_handler(struct mei_device *dev,
540 cl = pos->cl; 541 cl = pos->cl;
541 if (cl == NULL) 542 if (cl == NULL)
542 continue; 543 continue;
543 if (mei_flow_ctrl_creds(dev, cl) <= 0) { 544 if (mei_cl_flow_ctrl_creds(cl) <= 0) {
544 dev_dbg(&dev->pdev->dev, 545 dev_dbg(&dev->pdev->dev,
545 "No flow control credentials for client %d, not sending.\n", 546 "No flow control credentials for client %d, not sending.\n",
546 cl->host_client_id); 547 cl->host_client_id);
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index da9426054815..95f05d97a115 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -41,6 +41,7 @@
41 41
42#include "mei_dev.h" 42#include "mei_dev.h"
43#include "interface.h" 43#include "interface.h"
44#include "client.h"
44 45
45/* AMT device is a singleton on the platform */ 46/* AMT device is a singleton on the platform */
46static struct pci_dev *mei_pdev; 47static struct pci_dev *mei_pdev;
@@ -91,28 +92,6 @@ static DEFINE_MUTEX(mei_mutex);
91 92
92 93
93/** 94/**
94 * find_read_list_entry - find read list entry
95 *
96 * @dev: device structure
97 * @file: pointer to file structure
98 *
99 * returns cb on success, NULL on error
100 */
101static struct mei_cl_cb *find_read_list_entry(
102 struct mei_device *dev,
103 struct mei_cl *cl)
104{
105 struct mei_cl_cb *pos = NULL;
106 struct mei_cl_cb *next = NULL;
107
108 dev_dbg(&dev->pdev->dev, "remove read_list CB\n");
109 list_for_each_entry_safe(pos, next, &dev->read_list.list, list)
110 if (mei_cl_cmp_id(cl, pos->cl))
111 return pos;
112 return NULL;
113}
114
115/**
116 * mei_open - the open function 95 * mei_open - the open function
117 * 96 *
118 * @inode: pointer to inode structure 97 * @inode: pointer to inode structure
@@ -217,7 +196,7 @@ static int mei_release(struct inode *inode, struct file *file)
217 "ME client = %d\n", 196 "ME client = %d\n",
218 cl->host_client_id, 197 cl->host_client_id,
219 cl->me_client_id); 198 cl->me_client_id);
220 rets = mei_disconnect_host_client(dev, cl); 199 rets = mei_cl_disconnect(cl);
221 } 200 }
222 mei_cl_flush_queues(cl); 201 mei_cl_flush_queues(cl);
223 dev_dbg(&dev->pdev->dev, "remove client host client = %d, ME client = %d\n", 202 dev_dbg(&dev->pdev->dev, "remove client host client = %d, ME client = %d\n",
@@ -228,12 +207,12 @@ static int mei_release(struct inode *inode, struct file *file)
228 clear_bit(cl->host_client_id, dev->host_clients_map); 207 clear_bit(cl->host_client_id, dev->host_clients_map);
229 dev->open_handle_count--; 208 dev->open_handle_count--;
230 } 209 }
231 mei_me_cl_unlink(dev, cl); 210 mei_cl_unlink(cl);
232 211
233 /* free read cb */ 212 /* free read cb */
234 cb = NULL; 213 cb = NULL;
235 if (cl->read_cb) { 214 if (cl->read_cb) {
236 cb = find_read_list_entry(dev, cl); 215 cb = mei_cl_find_read_cb(cl);
237 /* Remove entry from read list */ 216 /* Remove entry from read list */
238 if (cb) 217 if (cb)
239 list_del(&cb->list); 218 list_del(&cb->list);
@@ -323,7 +302,7 @@ static ssize_t mei_read(struct file *file, char __user *ubuf,
323 goto out; 302 goto out;
324 } 303 }
325 304
326 err = mei_start_read(dev, cl); 305 err = mei_cl_read_start(cl);
327 if (err && err != -EBUSY) { 306 if (err && err != -EBUSY) {
328 dev_dbg(&dev->pdev->dev, 307 dev_dbg(&dev->pdev->dev,
329 "mei start read failure with status = %d\n", err); 308 "mei start read failure with status = %d\n", err);
@@ -394,7 +373,7 @@ copy_buffer:
394 goto out; 373 goto out;
395 374
396free: 375free:
397 cb_pos = find_read_list_entry(dev, cl); 376 cb_pos = mei_cl_find_read_cb(cl);
398 /* Remove entry from read list */ 377 /* Remove entry from read list */
399 if (cb_pos) 378 if (cb_pos)
400 list_del(&cb_pos->list); 379 list_del(&cb_pos->list);
@@ -476,7 +455,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
476 /* free entry used in read */ 455 /* free entry used in read */
477 if (cl->reading_state == MEI_READ_COMPLETE) { 456 if (cl->reading_state == MEI_READ_COMPLETE) {
478 *offset = 0; 457 *offset = 0;
479 write_cb = find_read_list_entry(dev, cl); 458 write_cb = mei_cl_find_read_cb(cl);
480 if (write_cb) { 459 if (write_cb) {
481 list_del(&write_cb->list); 460 list_del(&write_cb->list);
482 mei_io_cb_free(write_cb); 461 mei_io_cb_free(write_cb);
@@ -531,7 +510,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
531 510
532 dev_dbg(&dev->pdev->dev, "host client = %d, ME client = %d\n", 511 dev_dbg(&dev->pdev->dev, "host client = %d, ME client = %d\n",
533 cl->host_client_id, cl->me_client_id); 512 cl->host_client_id, cl->me_client_id);
534 rets = mei_flow_ctrl_creds(dev, cl); 513 rets = mei_cl_flow_ctrl_creds(cl);
535 if (rets < 0) 514 if (rets < 0)
536 goto err; 515 goto err;
537 516
@@ -565,7 +544,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
565 544
566out: 545out:
567 if (mei_hdr.msg_complete) { 546 if (mei_hdr.msg_complete) {
568 if (mei_flow_ctrl_reduce(dev, cl)) { 547 if (mei_cl_flow_ctrl_reduce(cl)) {
569 rets = -ENODEV; 548 rets = -ENODEV;
570 goto err; 549 goto err;
571 } 550 }
@@ -904,11 +883,11 @@ static void mei_remove(struct pci_dev *pdev)
904 883
905 if (dev->iamthif_cl.state == MEI_FILE_CONNECTED) { 884 if (dev->iamthif_cl.state == MEI_FILE_CONNECTED) {
906 dev->iamthif_cl.state = MEI_FILE_DISCONNECTING; 885 dev->iamthif_cl.state = MEI_FILE_DISCONNECTING;
907 mei_disconnect_host_client(dev, &dev->iamthif_cl); 886 mei_cl_disconnect(&dev->iamthif_cl);
908 } 887 }
909 if (dev->wd_cl.state == MEI_FILE_CONNECTED) { 888 if (dev->wd_cl.state == MEI_FILE_CONNECTED) {
910 dev->wd_cl.state = MEI_FILE_DISCONNECTING; 889 dev->wd_cl.state = MEI_FILE_DISCONNECTING;
911 mei_disconnect_host_client(dev, &dev->wd_cl); 890 mei_cl_disconnect(&dev->wd_cl);
912 } 891 }
913 892
914 /* Unregistering watchdog device */ 893 /* Unregistering watchdog device */
@@ -916,8 +895,8 @@ static void mei_remove(struct pci_dev *pdev)
916 895
917 /* remove entry if already in list */ 896 /* remove entry if already in list */
918 dev_dbg(&pdev->dev, "list del iamthif and wd file list.\n"); 897 dev_dbg(&pdev->dev, "list del iamthif and wd file list.\n");
919 mei_me_cl_unlink(dev, &dev->wd_cl); 898 mei_cl_unlink(&dev->wd_cl);
920 mei_me_cl_unlink(dev, &dev->iamthif_cl); 899 mei_cl_unlink(&dev->iamthif_cl);
921 900
922 dev->iamthif_current_cb = NULL; 901 dev->iamthif_current_cb = NULL;
923 dev->me_clients_num = 0; 902 dev->me_clients_num = 0;
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index 1b54e675d3f1..5a1ac9a37e10 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -329,59 +329,9 @@ void mei_reset(struct mei_device *dev, int interrupts);
329int mei_hw_init(struct mei_device *dev); 329int mei_hw_init(struct mei_device *dev);
330int mei_task_initialize_clients(void *data); 330int mei_task_initialize_clients(void *data);
331int mei_initialize_clients(struct mei_device *dev); 331int mei_initialize_clients(struct mei_device *dev);
332int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
333void mei_allocate_me_clients_storage(struct mei_device *dev); 332void mei_allocate_me_clients_storage(struct mei_device *dev);
334 333
335 334
336int mei_me_cl_link(struct mei_device *dev, struct mei_cl *cl,
337 const uuid_le *cguid, u8 host_client_id);
338void mei_me_cl_unlink(struct mei_device *dev, struct mei_cl *cl);
339int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);
340int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
341
342/*
343 * MEI IO Functions
344 */
345struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp);
346void mei_io_cb_free(struct mei_cl_cb *priv_cb);
347int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length);
348int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length);
349
350
351/**
352 * mei_io_list_init - Sets up a queue list.
353 *
354 * @list: An instance cl callback structure
355 */
356static inline void mei_io_list_init(struct mei_cl_cb *list)
357{
358 INIT_LIST_HEAD(&list->list);
359}
360void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl);
361
362/*
363 * MEI ME Client Functions
364 */
365
366struct mei_cl *mei_cl_allocate(struct mei_device *dev);
367void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
368int mei_cl_flush_queues(struct mei_cl *cl);
369/**
370 * mei_cl_cmp_id - tells if file private data have same id
371 *
372 * @fe1: private data of 1. file object
373 * @fe2: private data of 2. file object
374 *
375 * returns true - if ids are the same and not NULL
376 */
377static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
378 const struct mei_cl *cl2)
379{
380 return cl1 && cl2 &&
381 (cl1->host_client_id == cl2->host_client_id) &&
382 (cl1->me_client_id == cl2->me_client_id);
383}
384
385 335
386/* 336/*
387 * MEI interrupt functions prototype 337 * MEI interrupt functions prototype
@@ -395,9 +345,6 @@ void mei_timer(struct work_struct *work);
395 */ 345 */
396int mei_ioctl_connect_client(struct file *file, 346int mei_ioctl_connect_client(struct file *file,
397 struct mei_connect_client_data *data); 347 struct mei_connect_client_data *data);
398
399int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
400
401/* 348/*
402 * AMTHIF - AMT Host Interface Functions 349 * AMTHIF - AMT Host Interface Functions
403 */ 350 */
diff --git a/drivers/misc/mei/wd.c b/drivers/misc/mei/wd.c
index 9814bc1dba01..5ad5225ea2b9 100644
--- a/drivers/misc/mei/wd.c
+++ b/drivers/misc/mei/wd.c
@@ -26,6 +26,7 @@
26#include "mei_dev.h" 26#include "mei_dev.h"
27#include "hbm.h" 27#include "hbm.h"
28#include "interface.h" 28#include "interface.h"
29#include "client.h"
29 30
30static const u8 mei_start_wd_params[] = { 0x02, 0x12, 0x13, 0x10 }; 31static const u8 mei_start_wd_params[] = { 0x02, 0x12, 0x13, 0x10 };
31static const u8 mei_stop_wd_params[] = { 0x02, 0x02, 0x14, 0x10 }; 32static const u8 mei_stop_wd_params[] = { 0x02, 0x02, 0x14, 0x10 };
@@ -72,7 +73,7 @@ int mei_wd_host_init(struct mei_device *dev)
72 dev->wd_state = MEI_WD_IDLE; 73 dev->wd_state = MEI_WD_IDLE;
73 74
74 /* Connect WD ME client to the host client */ 75 /* Connect WD ME client to the host client */
75 id = mei_me_cl_link(dev, &dev->wd_cl, 76 id = mei_cl_link_me(&dev->wd_cl,
76 &mei_wd_guid, MEI_WD_HOST_CLIENT_ID); 77 &mei_wd_guid, MEI_WD_HOST_CLIENT_ID);
77 78
78 if (id < 0) { 79 if (id < 0) {
@@ -141,7 +142,7 @@ int mei_wd_stop(struct mei_device *dev)
141 142
142 dev->wd_state = MEI_WD_STOPPING; 143 dev->wd_state = MEI_WD_STOPPING;
143 144
144 ret = mei_flow_ctrl_creds(dev, &dev->wd_cl); 145 ret = mei_cl_flow_ctrl_creds(&dev->wd_cl);
145 if (ret < 0) 146 if (ret < 0)
146 goto out; 147 goto out;
147 148
@@ -150,7 +151,7 @@ int mei_wd_stop(struct mei_device *dev)
150 dev->mei_host_buffer_is_empty = false; 151 dev->mei_host_buffer_is_empty = false;
151 152
152 if (!mei_wd_send(dev)) { 153 if (!mei_wd_send(dev)) {
153 ret = mei_flow_ctrl_reduce(dev, &dev->wd_cl); 154 ret = mei_cl_flow_ctrl_reduce(&dev->wd_cl);
154 if (ret) 155 if (ret)
155 goto out; 156 goto out;
156 } else { 157 } else {
@@ -271,7 +272,7 @@ static int mei_wd_ops_ping(struct watchdog_device *wd_dev)
271 272
272 /* Check if we can send the ping to HW*/ 273 /* Check if we can send the ping to HW*/
273 if (dev->mei_host_buffer_is_empty && 274 if (dev->mei_host_buffer_is_empty &&
274 mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) { 275 mei_cl_flow_ctrl_creds(&dev->wd_cl) > 0) {
275 276
276 dev->mei_host_buffer_is_empty = false; 277 dev->mei_host_buffer_is_empty = false;
277 dev_dbg(&dev->pdev->dev, "wd: sending ping\n"); 278 dev_dbg(&dev->pdev->dev, "wd: sending ping\n");
@@ -282,9 +283,9 @@ static int mei_wd_ops_ping(struct watchdog_device *wd_dev)
282 goto end; 283 goto end;
283 } 284 }
284 285
285 if (mei_flow_ctrl_reduce(dev, &dev->wd_cl)) { 286 if (mei_cl_flow_ctrl_reduce(&dev->wd_cl)) {
286 dev_err(&dev->pdev->dev, 287 dev_err(&dev->pdev->dev,
287 "wd: mei_flow_ctrl_reduce() failed.\n"); 288 "wd: mei_cl_flow_ctrl_reduce() failed.\n");
288 ret = -EIO; 289 ret = -EIO;
289 goto end; 290 goto end;
290 } 291 }