aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2012-10-11 10:35:08 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-10-24 18:37:31 -0400
commit664df38b3c74656261d4227b4dd380cfa453f78f (patch)
tree35d05f657d0cd04d562edea962bc9122179caf64 /drivers/misc
parent601a1efa630aab0ca72bf8d638c441a09654b250 (diff)
mei: use mei_io_cb_ warppers also for control flows
move the mei_io_cb_ wrappers to to iorw.c for global use and use them also for handling control flows Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/mei/init.c4
-rw-r--r--drivers/misc/mei/iorw.c117
-rw-r--r--drivers/misc/mei/main.c78
-rw-r--r--drivers/misc/mei/mei_dev.h4
4 files changed, 94 insertions, 109 deletions
diff --git a/drivers/misc/mei/init.c b/drivers/misc/mei/init.c
index 4666f0ba350a..1f13eb97a10a 100644
--- a/drivers/misc/mei/init.c
+++ b/drivers/misc/mei/init.c
@@ -668,12 +668,10 @@ int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl)
668 if (cl->state != MEI_FILE_DISCONNECTING) 668 if (cl->state != MEI_FILE_DISCONNECTING)
669 return 0; 669 return 0;
670 670
671 cb = kzalloc(sizeof(struct mei_cl_cb), GFP_KERNEL); 671 cb = mei_io_cb_init(cl, NULL);
672 if (!cb) 672 if (!cb)
673 return -ENOMEM; 673 return -ENOMEM;
674 674
675 mei_io_list_init(cb);
676 cb->file_private = cl;
677 cb->major_file_operations = MEI_CLOSE; 675 cb->major_file_operations = MEI_CLOSE;
678 if (dev->mei_host_buffer_is_empty) { 676 if (dev->mei_host_buffer_is_empty) {
679 dev->mei_host_buffer_is_empty = false; 677 dev->mei_host_buffer_is_empty = false;
diff --git a/drivers/misc/mei/iorw.c b/drivers/misc/mei/iorw.c
index 2891bc44f9d4..541c157f325a 100644
--- a/drivers/misc/mei/iorw.c
+++ b/drivers/misc/mei/iorw.c
@@ -52,6 +52,80 @@ void mei_io_cb_free(struct mei_cl_cb *cb)
52 kfree(cb->response_buffer.data); 52 kfree(cb->response_buffer.data);
53 kfree(cb); 53 kfree(cb);
54} 54}
55/**
56 * mei_io_cb_init - allocate and initialize io callback
57 *
58 * @cl - mei client
59 * @file: pointer to file structure
60 *
61 * returns mei_cl_cb pointer or NULL;
62 */
63struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp)
64{
65 struct mei_cl_cb *cb;
66
67 cb = kzalloc(sizeof(struct mei_cl_cb), GFP_KERNEL);
68 if (!cb)
69 return NULL;
70
71 mei_io_list_init(cb);
72
73 cb->file_object = fp;
74 cb->file_private = cl;
75 cb->buf_idx = 0;
76 return cb;
77}
78
79
80/**
81 * mei_io_cb_alloc_req_buf - allocate request buffer
82 *
83 * @cb - io callback structure
84 * @size: size of the buffer
85 *
86 * returns 0 on success
87 * -EINVAL if cb is NULL
88 * -ENOMEM if allocation failed
89 */
90int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length)
91{
92 if (!cb)
93 return -EINVAL;
94
95 if (length == 0)
96 return 0;
97
98 cb->request_buffer.data = kmalloc(length, GFP_KERNEL);
99 if (!cb->request_buffer.data)
100 return -ENOMEM;
101 cb->request_buffer.size = length;
102 return 0;
103}
104/**
105 * mei_io_cb_alloc_req_buf - allocate respose buffer
106 *
107 * @cb - io callback structure
108 * @size: size of the buffer
109 *
110 * returns 0 on success
111 * -EINVAL if cb is NULL
112 * -ENOMEM if allocation failed
113 */
114int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length)
115{
116 if (!cb)
117 return -EINVAL;
118
119 if (length == 0)
120 return 0;
121
122 cb->response_buffer.data = kmalloc(length, GFP_KERNEL);
123 if (!cb->response_buffer.data)
124 return -ENOMEM;
125 cb->response_buffer.size = length;
126 return 0;
127}
128
55 129
56/** 130/**
57 * mei_me_cl_by_id return index to me_clients for client_id 131 * mei_me_cl_by_id return index to me_clients for client_id
@@ -112,14 +186,12 @@ int mei_ioctl_connect_client(struct file *file,
112 186
113 dev_dbg(&dev->pdev->dev, "mei_ioctl_connect_client() Entry\n"); 187 dev_dbg(&dev->pdev->dev, "mei_ioctl_connect_client() Entry\n");
114 188
115
116 /* buffered ioctl cb */ 189 /* buffered ioctl cb */
117 cb = kzalloc(sizeof(struct mei_cl_cb), GFP_KERNEL); 190 cb = mei_io_cb_init(cl, file);
118 if (!cb) { 191 if (!cb) {
119 rets = -ENOMEM; 192 rets = -ENOMEM;
120 goto end; 193 goto end;
121 } 194 }
122 mei_io_list_init(cb);
123 195
124 cb->major_file_operations = MEI_IOCTL; 196 cb->major_file_operations = MEI_IOCTL;
125 197
@@ -207,14 +279,12 @@ int mei_ioctl_connect_client(struct file *file,
207 } else { 279 } else {
208 dev_dbg(&dev->pdev->dev, "Sending connect message - succeeded\n"); 280 dev_dbg(&dev->pdev->dev, "Sending connect message - succeeded\n");
209 cl->timer_count = MEI_CONNECT_TIMEOUT; 281 cl->timer_count = MEI_CONNECT_TIMEOUT;
210 cb->file_private = cl;
211 list_add_tail(&cb->list, &dev->ctrl_rd_list.list); 282 list_add_tail(&cb->list, &dev->ctrl_rd_list.list);
212 } 283 }
213 284
214 285
215 } else { 286 } else {
216 dev_dbg(&dev->pdev->dev, "Queuing the connect request due to device busy\n"); 287 dev_dbg(&dev->pdev->dev, "Queuing the connect request due to device busy\n");
217 cb->file_private = cl;
218 dev_dbg(&dev->pdev->dev, "add connect cb to control write list.\n"); 288 dev_dbg(&dev->pdev->dev, "add connect cb to control write list.\n");
219 list_add_tail(&cb->list, &dev->ctrl_wr_list.list); 289 list_add_tail(&cb->list, &dev->ctrl_wr_list.list);
220 } 290 }
@@ -407,7 +477,7 @@ out:
407int mei_start_read(struct mei_device *dev, struct mei_cl *cl) 477int mei_start_read(struct mei_device *dev, struct mei_cl *cl)
408{ 478{
409 struct mei_cl_cb *cb; 479 struct mei_cl_cb *cb;
410 int rets = 0; 480 int rets;
411 int i; 481 int i;
412 482
413 if (cl->state != MEI_FILE_CONNECTED) 483 if (cl->state != MEI_FILE_CONNECTED)
@@ -416,49 +486,40 @@ int mei_start_read(struct mei_device *dev, struct mei_cl *cl)
416 if (dev->dev_state != MEI_DEV_ENABLED) 486 if (dev->dev_state != MEI_DEV_ENABLED)
417 return -ENODEV; 487 return -ENODEV;
418 488
419 dev_dbg(&dev->pdev->dev, "check if read is pending.\n");
420 if (cl->read_pending || cl->read_cb) { 489 if (cl->read_pending || cl->read_cb) {
421 dev_dbg(&dev->pdev->dev, "read is pending.\n"); 490 dev_dbg(&dev->pdev->dev, "read is pending.\n");
422 return -EBUSY; 491 return -EBUSY;
423 } 492 }
493 i = mei_me_cl_by_id(dev, cl->me_client_id);
494 if (i < 0) {
495 dev_err(&dev->pdev->dev, "no such me client %d\n",
496 cl->me_client_id);
497 return -ENODEV;
498 }
424 499
425 cb = kzalloc(sizeof(struct mei_cl_cb), GFP_KERNEL); 500 cb = mei_io_cb_init(cl, NULL);
426 if (!cb) 501 if (!cb)
427 return -ENOMEM; 502 return -ENOMEM;
428 503
429 dev_dbg(&dev->pdev->dev, "allocation call back successful. host client = %d, ME client = %d\n", 504 rets = mei_io_cb_alloc_resp_buf(cb,
430 cl->host_client_id, cl->me_client_id); 505 dev->me_clients[i].props.max_msg_length);
431 i = mei_me_cl_by_id(dev, cl->me_client_id); 506 if (rets)
432 if (i < 0) { 507 goto err;
433 rets = -ENODEV;
434 goto unlock;
435 }
436 508
437 cb->response_buffer.size = dev->me_clients[i].props.max_msg_length;
438 cb->response_buffer.data =
439 kmalloc(cb->response_buffer.size, GFP_KERNEL);
440 if (!cb->response_buffer.data) {
441 rets = -ENOMEM;
442 goto unlock;
443 }
444 dev_dbg(&dev->pdev->dev, "allocation call back data success.\n");
445 cb->major_file_operations = MEI_READ; 509 cb->major_file_operations = MEI_READ;
446 /* make sure buffer index is zero before we start */
447 cb->buf_idx = 0;
448 cb->file_private = (void *) cl;
449 cl->read_cb = cb; 510 cl->read_cb = cb;
450 if (dev->mei_host_buffer_is_empty) { 511 if (dev->mei_host_buffer_is_empty) {
451 dev->mei_host_buffer_is_empty = false; 512 dev->mei_host_buffer_is_empty = false;
452 if (mei_send_flow_control(dev, cl)) { 513 if (mei_send_flow_control(dev, cl)) {
453 rets = -ENODEV; 514 rets = -ENODEV;
454 goto unlock; 515 goto err;
455 } 516 }
456 list_add_tail(&cb->list, &dev->read_list.list); 517 list_add_tail(&cb->list, &dev->read_list.list);
457 } else { 518 } else {
458 list_add_tail(&cb->list, &dev->ctrl_wr_list.list); 519 list_add_tail(&cb->list, &dev->ctrl_wr_list.list);
459 } 520 }
460 return rets; 521 return rets;
461unlock: 522err:
462 mei_io_cb_free(cb); 523 mei_io_cb_free(cb);
463 return rets; 524 return rets;
464} 525}
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index 518e07eb1075..ed4943f6b6c2 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -513,84 +513,6 @@ out:
513 mutex_unlock(&dev->device_lock); 513 mutex_unlock(&dev->device_lock);
514 return rets; 514 return rets;
515} 515}
516
517/**
518 * mei_io_cb_init - allocate and initialize io callback
519 *
520 * @cl - mei client
521 * @file: pointer to file structure
522 *
523 * returns mei_cl_cb pointer or NULL;
524 */
525static struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp)
526{
527 struct mei_cl_cb *cb;
528 struct mei_device *dev;
529
530 dev = cl->dev;
531
532 cb = kzalloc(sizeof(struct mei_cl_cb), GFP_KERNEL);
533 if (!cb)
534 return NULL;
535
536 mei_io_list_init(cb);
537
538 cb->file_object = fp;
539 cb->file_private = cl;
540 cb->buf_idx = 0;
541 return cb;
542}
543
544
545/**
546 * mei_io_cb_alloc_req_buf - allocate request buffer
547 *
548 * @cb - io callback structure
549 * @size: size of the buffer
550 *
551 * returns 0 on success
552 * -EINVAL if cb is NULL
553 * -ENOMEM if allocation failed
554 */
555static int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length)
556{
557 if (!cb)
558 return -EINVAL;
559
560 if (length == 0)
561 return 0;
562
563 cb->request_buffer.data = kmalloc(length, GFP_KERNEL);
564 if (!cb->request_buffer.data)
565 return -ENOMEM;
566 cb->request_buffer.size = length;
567 return 0;
568}
569/**
570 * mei_io_cb_alloc_req_buf - allocate respose buffer
571 *
572 * @cb - io callback structure
573 * @size: size of the buffer
574 *
575 * returns 0 on success
576 * -EINVAL if cb is NULL
577 * -ENOMEM if allocation failed
578 */
579static int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length)
580{
581 if (!cb)
582 return -EINVAL;
583
584 if (length == 0)
585 return 0;
586
587 cb->response_buffer.data = kmalloc(length, GFP_KERNEL);
588 if (!cb->response_buffer.data)
589 return -ENOMEM;
590 cb->response_buffer.size = length;
591 return 0;
592}
593
594/** 516/**
595 * mei_write - the write function. 517 * mei_write - the write function.
596 * 518 *
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index 4545a9ebd79f..6adcb3f6621a 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -293,7 +293,11 @@ int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
293/* 293/*
294 * MEI IO Functions 294 * MEI IO Functions
295 */ 295 */
296struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp);
296void mei_io_cb_free(struct mei_cl_cb *priv_cb); 297void mei_io_cb_free(struct mei_cl_cb *priv_cb);
298int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length);
299int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length);
300
297 301
298/** 302/**
299 * mei_io_list_init - Sets up a queue list. 303 * mei_io_list_init - Sets up a queue list.