]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/staging/greybus/operation.h
greybus: operation: create gb_operation_sync for sending "simple" messages
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / greybus / operation.h
CommitLineData
e88afa58
AE
1/*
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
3c3cef40
AE
14struct gb_operation;
15
23383def 16enum gb_operation_result {
e88afa58
AE
17 GB_OP_SUCCESS = 0,
18 GB_OP_INVALID = 1,
19 GB_OP_NO_MEMORY = 2,
20 GB_OP_INTERRUPTED = 3,
d7528685
AE
21 GB_OP_RETRY = 4,
22 GB_OP_PROTOCOL_BAD = 5,
78496db0 23 GB_OP_OVERFLOW = 6,
708971e4 24 GB_OP_TIMEOUT = 0xff,
e88afa58
AE
25};
26
3690a826 27struct gb_message {
0a4e14a8
AE
28 struct gb_operation_msg_hdr *header;
29 void *payload;
30 size_t size; /* header + payload */
31 struct gb_operation *operation;
3ed67aba 32
0a4e14a8 33 void *cookie;
87d208fe
AE
34
35 u8 buffer[];
3690a826
AE
36};
37
e88afa58
AE
38/*
39 * A Greybus operation is a remote procedure call performed over a
40 * connection between the AP and a function on Greybus module.
41 * Every operation consists of a request message sent to the other
42 * end of the connection coupled with a reply returned to the
43 * sender.
44 *
45 * The state for managing active requests on a connection is held in
46 * the connection structure.
47 *
48 * YADA YADA
49 *
50 * submitting each request and providing its matching response to
51 * the caller when it arrives. Operations normally complete
52 * asynchronously, and when an operation's response arrives its
53 * callback function is executed. The callback pointer is supplied
54 * at the time the operation is submitted; a null callback pointer
55 * causes synchronous operation--the caller is blocked until
56 * the response arrives. In addition, it is possible to await
57 * the completion of a submitted asynchronous operation.
58 *
59 * A Greybus device operation includes a Greybus buffer to hold the
60 * data sent to the device. The only field within a Greybus
61 * operation that should be used by a caller is the payload pointer,
62 * which should be used to populate the request data. This pointer
63 * is guaranteed to be 64-bit aligned.
64 * XXX and callback?
65 */
e88afa58
AE
66typedef void (*gb_operation_callback)(struct gb_operation *);
67struct gb_operation {
68 struct gb_connection *connection;
c08b1dda
AE
69 struct gb_message *request;
70 struct gb_message *response;
84d148b1 71 u16 id;
22b320f4 72
23383def
AE
73 int errno; /* Operation result */
74
ee637a9b 75 struct work_struct work;
e88afa58
AE
76 gb_operation_callback callback; /* If asynchronous */
77 struct completion completion; /* Used if no callback */
708971e4 78 struct delayed_work timeout_work;
e88afa58 79
c7d0f258 80 struct kref kref;
b8616da8 81 struct list_head links; /* connection->{operations,pending} */
e88afa58
AE
82};
83
61089e89 84void gb_connection_recv(struct gb_connection *connection,
d90c25b0
AE
85 void *data, size_t size);
86
e88afa58 87struct gb_operation *gb_operation_create(struct gb_connection *connection,
22b320f4
AE
88 u8 type, size_t request_size,
89 size_t response_size);
deb4b9ef 90void gb_operation_get(struct gb_operation *operation);
c7d0f258
AE
91void gb_operation_put(struct gb_operation *operation);
92static inline void gb_operation_destroy(struct gb_operation *operation)
93{
94 gb_operation_put(operation);
95}
e88afa58 96
d90c25b0
AE
97int gb_operation_request_send(struct gb_operation *operation,
98 gb_operation_callback callback);
99int gb_operation_response_send(struct gb_operation *operation);
100
f68c05c0 101void gb_operation_cancel(struct gb_operation *operation, int errno);
e88afa58 102
bc717fcb
AE
103int gb_operation_status_map(u8 status);
104
d98b52b0
AE
105void greybus_data_sent(struct greybus_host_device *hd,
106 void *header, int status);
107
10aa801d
GKH
108int gb_operation_sync(struct gb_connection *connection, int type,
109 void *request, int request_size,
110 void *response, int response_size);
111
2eb585f8
AE
112int gb_operation_init(void);
113void gb_operation_exit(void);
114
e88afa58 115#endif /* !__OPERATION_H */