blob: d5ec582e21a2b2a44a627c6c92c91d68b589576e [file] [log] [blame]
Alex Eldere88afa52014-10-01 21:54:15 -05001/*
2 * Greybus operations
3 *
4 * Copyright 2014 Google Inc.
5 *
6 * Released under the GPLv2 only.
7 */
8
9#ifndef __OPERATION_H
10#define __OPERATION_H
11
12#include <linux/completion.h>
13
14enum gb_operation_status {
15 GB_OP_SUCCESS = 0,
16 GB_OP_INVALID = 1,
17 GB_OP_NO_MEMORY = 2,
18 GB_OP_INTERRUPTED = 3,
Alex Elder2eb585f2014-10-16 06:35:34 -050019 GB_OP_PROTOCOL_BAD = 4,
Alex Eldere88afa52014-10-01 21:54:15 -050020};
21
22/*
23 * A Greybus operation is a remote procedure call performed over a
24 * connection between the AP and a function on Greybus module.
25 * Every operation consists of a request message sent to the other
26 * end of the connection coupled with a reply returned to the
27 * sender.
28 *
29 * The state for managing active requests on a connection is held in
30 * the connection structure.
31 *
32 * YADA YADA
33 *
34 * submitting each request and providing its matching response to
35 * the caller when it arrives. Operations normally complete
36 * asynchronously, and when an operation's response arrives its
37 * callback function is executed. The callback pointer is supplied
38 * at the time the operation is submitted; a null callback pointer
39 * causes synchronous operation--the caller is blocked until
40 * the response arrives. In addition, it is possible to await
41 * the completion of a submitted asynchronous operation.
42 *
43 * A Greybus device operation includes a Greybus buffer to hold the
44 * data sent to the device. The only field within a Greybus
45 * operation that should be used by a caller is the payload pointer,
46 * which should be used to populate the request data. This pointer
47 * is guaranteed to be 64-bit aligned.
48 * XXX and callback?
49 */
50struct gb_operation;
51typedef void (*gb_operation_callback)(struct gb_operation *);
52struct gb_operation {
53 struct gb_connection *connection;
Alex Elder22b320f2014-10-16 06:35:31 -050054 struct gbuf *request;
55 struct gbuf *response;
Alex Elder84d148b2014-10-16 06:35:32 -050056 u16 id;
Alex Elder22b320f2014-10-16 06:35:31 -050057
Alex Elder84d148b2014-10-16 06:35:32 -050058 u8 result;
Alex Elder2eb585f2014-10-16 06:35:34 -050059 struct work_struct recv_work;
Alex Eldere88afa52014-10-01 21:54:15 -050060 gb_operation_callback callback; /* If asynchronous */
61 struct completion completion; /* Used if no callback */
Alex Eldere88afa52014-10-01 21:54:15 -050062
63 struct list_head links; /* connection->operations */
Alex Elder84d148b2014-10-16 06:35:32 -050064 struct rb_node node; /* connection->pending */
Alex Elder22b320f2014-10-16 06:35:31 -050065
66 /* These are what's used by caller */
67 void *request_payload;
68 void *response_payload;
Alex Eldere88afa52014-10-01 21:54:15 -050069};
70
Alex Elderd90c25b2014-10-16 06:35:33 -050071void gb_connection_operation_recv(struct gb_connection *connection,
72 void *data, size_t size);
73
Alex Eldere88afa52014-10-01 21:54:15 -050074struct gb_operation *gb_operation_create(struct gb_connection *connection,
Alex Elder22b320f2014-10-16 06:35:31 -050075 u8 type, size_t request_size,
76 size_t response_size);
Alex Eldere88afa52014-10-01 21:54:15 -050077void gb_operation_destroy(struct gb_operation *operation);
78
Alex Elderd90c25b2014-10-16 06:35:33 -050079int gb_operation_request_send(struct gb_operation *operation,
80 gb_operation_callback callback);
81int gb_operation_response_send(struct gb_operation *operation);
82
Alex Eldere88afa52014-10-01 21:54:15 -050083int gb_operation_wait(struct gb_operation *operation);
84void gb_operation_complete(struct gb_operation *operation);
85
Alex Elder2eb585f2014-10-16 06:35:34 -050086int gb_operation_init(void);
87void gb_operation_exit(void);
88
Alex Eldere88afa52014-10-01 21:54:15 -050089#endif /* !__OPERATION_H */