2014-10-02 02:54:15 +00:00
|
|
|
/*
|
|
|
|
* Greybus operations
|
|
|
|
*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Released under the GPLv2 only.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __OPERATION_H
|
|
|
|
#define __OPERATION_H
|
|
|
|
|
|
|
|
#include <linux/completion.h>
|
|
|
|
|
2014-11-18 00:08:30 +00:00
|
|
|
struct gb_operation;
|
|
|
|
|
2014-11-22 01:29:12 +00:00
|
|
|
enum gb_operation_result {
|
2014-10-02 02:54:15 +00:00
|
|
|
GB_OP_SUCCESS = 0,
|
|
|
|
GB_OP_INVALID = 1,
|
|
|
|
GB_OP_NO_MEMORY = 2,
|
|
|
|
GB_OP_INTERRUPTED = 3,
|
2014-10-17 10:09:21 +00:00
|
|
|
GB_OP_RETRY = 4,
|
|
|
|
GB_OP_PROTOCOL_BAD = 5,
|
2014-11-17 14:08:39 +00:00
|
|
|
GB_OP_OVERFLOW = 6,
|
2014-10-27 07:40:09 +00:00
|
|
|
GB_OP_TIMEOUT = 0xff,
|
2014-10-02 02:54:15 +00:00
|
|
|
};
|
|
|
|
|
2014-11-18 00:08:31 +00:00
|
|
|
struct gb_message {
|
2014-11-20 22:09:14 +00:00
|
|
|
struct gb_operation_msg_hdr *header;
|
|
|
|
void *payload;
|
|
|
|
size_t size; /* header + payload */
|
|
|
|
struct gb_operation *operation;
|
2014-11-18 19:26:52 +00:00
|
|
|
|
2014-11-20 22:09:14 +00:00
|
|
|
void *cookie;
|
2014-11-20 22:09:16 +00:00
|
|
|
|
|
|
|
u8 buffer[];
|
2014-11-18 00:08:31 +00:00
|
|
|
};
|
|
|
|
|
2014-10-02 02:54:15 +00:00
|
|
|
/*
|
|
|
|
* A Greybus operation is a remote procedure call performed over a
|
|
|
|
* connection between the AP and a function on Greybus module.
|
|
|
|
* Every operation consists of a request message sent to the other
|
|
|
|
* end of the connection coupled with a reply returned to the
|
|
|
|
* sender.
|
|
|
|
*
|
|
|
|
* The state for managing active requests on a connection is held in
|
|
|
|
* the connection structure.
|
|
|
|
*
|
|
|
|
* YADA YADA
|
|
|
|
*
|
|
|
|
* submitting each request and providing its matching response to
|
|
|
|
* the caller when it arrives. Operations normally complete
|
|
|
|
* asynchronously, and when an operation's response arrives its
|
|
|
|
* callback function is executed. The callback pointer is supplied
|
|
|
|
* at the time the operation is submitted; a null callback pointer
|
|
|
|
* causes synchronous operation--the caller is blocked until
|
|
|
|
* the response arrives. In addition, it is possible to await
|
|
|
|
* the completion of a submitted asynchronous operation.
|
|
|
|
*
|
|
|
|
* A Greybus device operation includes a Greybus buffer to hold the
|
|
|
|
* data sent to the device. The only field within a Greybus
|
|
|
|
* operation that should be used by a caller is the payload pointer,
|
|
|
|
* which should be used to populate the request data. This pointer
|
|
|
|
* is guaranteed to be 64-bit aligned.
|
|
|
|
* XXX and callback?
|
|
|
|
*/
|
|
|
|
typedef void (*gb_operation_callback)(struct gb_operation *);
|
|
|
|
struct gb_operation {
|
|
|
|
struct gb_connection *connection;
|
2014-11-20 22:09:15 +00:00
|
|
|
struct gb_message *request;
|
|
|
|
struct gb_message *response;
|
2014-10-16 11:35:32 +00:00
|
|
|
u16 id;
|
2014-10-22 07:04:29 +00:00
|
|
|
bool canceled;
|
2014-10-16 11:35:31 +00:00
|
|
|
|
2014-11-22 01:29:12 +00:00
|
|
|
int errno; /* Operation result */
|
|
|
|
|
2014-11-22 01:29:13 +00:00
|
|
|
struct work_struct work;
|
2014-10-02 02:54:15 +00:00
|
|
|
gb_operation_callback callback; /* If asynchronous */
|
|
|
|
struct completion completion; /* Used if no callback */
|
2014-10-27 07:40:09 +00:00
|
|
|
struct delayed_work timeout_work;
|
2014-10-02 02:54:15 +00:00
|
|
|
|
2014-11-17 14:08:40 +00:00
|
|
|
struct kref kref;
|
2014-11-12 21:17:53 +00:00
|
|
|
struct list_head links; /* connection->{operations,pending} */
|
2014-10-02 02:54:15 +00:00
|
|
|
};
|
|
|
|
|
2014-11-18 19:26:50 +00:00
|
|
|
void gb_connection_recv(struct gb_connection *connection,
|
2014-10-16 11:35:33 +00:00
|
|
|
void *data, size_t size);
|
|
|
|
|
2014-10-02 02:54:15 +00:00
|
|
|
struct gb_operation *gb_operation_create(struct gb_connection *connection,
|
2014-10-16 11:35:31 +00:00
|
|
|
u8 type, size_t request_size,
|
|
|
|
size_t response_size);
|
2014-11-22 01:29:15 +00:00
|
|
|
void gb_operation_get(struct gb_operation *operation);
|
2014-11-17 14:08:40 +00:00
|
|
|
void gb_operation_put(struct gb_operation *operation);
|
|
|
|
static inline void gb_operation_destroy(struct gb_operation *operation)
|
|
|
|
{
|
|
|
|
gb_operation_put(operation);
|
|
|
|
}
|
2014-10-02 02:54:15 +00:00
|
|
|
|
2014-10-16 11:35:33 +00:00
|
|
|
int gb_operation_request_send(struct gb_operation *operation,
|
|
|
|
gb_operation_callback callback);
|
|
|
|
int gb_operation_response_send(struct gb_operation *operation);
|
|
|
|
|
2014-10-22 07:04:29 +00:00
|
|
|
void gb_operation_cancel(struct gb_operation *operation);
|
2014-10-02 02:54:15 +00:00
|
|
|
int gb_operation_wait(struct gb_operation *operation);
|
|
|
|
|
2014-11-19 23:55:04 +00:00
|
|
|
int gb_operation_status_map(u8 status);
|
|
|
|
|
2014-11-20 22:09:17 +00:00
|
|
|
void greybus_data_sent(struct greybus_host_device *hd,
|
|
|
|
void *header, int status);
|
|
|
|
|
2014-10-16 11:35:34 +00:00
|
|
|
int gb_operation_init(void);
|
|
|
|
void gb_operation_exit(void);
|
|
|
|
|
2014-10-02 02:54:15 +00:00
|
|
|
#endif /* !__OPERATION_H */
|