2014-10-01 20:54:15 -06:00
|
|
|
/*
|
|
|
|
* Greybus operations
|
|
|
|
*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Released under the GPLv2 only.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __OPERATION_H
|
|
|
|
#define __OPERATION_H
|
|
|
|
|
|
|
|
#include <linux/completion.h>
|
|
|
|
|
2014-11-17 17:08:30 -07:00
|
|
|
struct gb_operation;
|
|
|
|
|
2014-11-21 18:29:12 -07:00
|
|
|
enum gb_operation_result {
|
2014-12-01 06:53:09 -07:00
|
|
|
GB_OP_SUCCESS = 0x00,
|
|
|
|
GB_OP_INTERRUPTED = 0x01,
|
|
|
|
GB_OP_TIMEOUT = 0x02,
|
|
|
|
GB_OP_NO_MEMORY = 0x03,
|
|
|
|
GB_OP_PROTOCOL_BAD = 0x04,
|
|
|
|
GB_OP_OVERFLOW = 0x05,
|
|
|
|
GB_OP_INVALID = 0x06,
|
|
|
|
GB_OP_RETRY = 0x07,
|
|
|
|
GB_OP_UNKNOWN_ERROR = 0xfe,
|
|
|
|
GB_OP_MALFUNCTION = 0xff,
|
2014-10-01 20:54:15 -06:00
|
|
|
};
|
|
|
|
|
2014-11-17 17:08:31 -07:00
|
|
|
struct gb_message {
|
2014-11-20 15:09:14 -07:00
|
|
|
struct gb_operation_msg_hdr *header;
|
|
|
|
void *payload;
|
|
|
|
size_t size; /* header + payload */
|
|
|
|
struct gb_operation *operation;
|
2014-11-18 12:26:52 -07:00
|
|
|
|
2014-11-20 15:09:14 -07:00
|
|
|
void *cookie;
|
2014-11-20 15:09:16 -07:00
|
|
|
|
|
|
|
u8 buffer[];
|
2014-11-17 17:08:31 -07:00
|
|
|
};
|
|
|
|
|
2014-10-01 20:54:15 -06: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 15:09:15 -07:00
|
|
|
struct gb_message *request;
|
|
|
|
struct gb_message *response;
|
2014-10-16 05:35:32 -06:00
|
|
|
u16 id;
|
2014-10-16 05:35:31 -06:00
|
|
|
|
2014-11-21 18:29:12 -07:00
|
|
|
int errno; /* Operation result */
|
|
|
|
|
2014-11-21 18:29:13 -07:00
|
|
|
struct work_struct work;
|
2014-10-01 20:54:15 -06:00
|
|
|
gb_operation_callback callback; /* If asynchronous */
|
|
|
|
struct completion completion; /* Used if no callback */
|
2014-10-27 01:40:09 -06:00
|
|
|
struct delayed_work timeout_work;
|
2014-10-01 20:54:15 -06:00
|
|
|
|
2014-11-17 07:08:40 -07:00
|
|
|
struct kref kref;
|
2014-11-12 14:17:53 -07:00
|
|
|
struct list_head links; /* connection->{operations,pending} */
|
2014-10-01 20:54:15 -06:00
|
|
|
};
|
|
|
|
|
2014-11-18 12:26:50 -07:00
|
|
|
void gb_connection_recv(struct gb_connection *connection,
|
2014-10-16 05:35:33 -06:00
|
|
|
void *data, size_t size);
|
|
|
|
|
2014-11-25 10:33:13 -07:00
|
|
|
int gb_operation_result(struct gb_operation *operation);
|
|
|
|
|
2014-10-01 20:54:15 -06:00
|
|
|
struct gb_operation *gb_operation_create(struct gb_connection *connection,
|
2014-10-16 05:35:31 -06:00
|
|
|
u8 type, size_t request_size,
|
|
|
|
size_t response_size);
|
2014-11-21 18:29:15 -07:00
|
|
|
void gb_operation_get(struct gb_operation *operation);
|
2014-11-17 07:08:40 -07: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-01 20:54:15 -06:00
|
|
|
|
2014-10-16 05:35:33 -06:00
|
|
|
int gb_operation_request_send(struct gb_operation *operation,
|
|
|
|
gb_operation_callback callback);
|
|
|
|
int gb_operation_response_send(struct gb_operation *operation);
|
|
|
|
|
2014-11-21 18:29:17 -07:00
|
|
|
void gb_operation_cancel(struct gb_operation *operation, int errno);
|
2014-10-01 20:54:15 -06:00
|
|
|
|
2014-11-19 16:55:04 -07:00
|
|
|
int gb_operation_status_map(u8 status);
|
|
|
|
|
2014-11-20 15:09:17 -07:00
|
|
|
void greybus_data_sent(struct greybus_host_device *hd,
|
|
|
|
void *header, int status);
|
|
|
|
|
2014-11-24 12:19:13 -07:00
|
|
|
int gb_operation_sync(struct gb_connection *connection, int type,
|
|
|
|
void *request, int request_size,
|
|
|
|
void *response, int response_size);
|
|
|
|
|
2014-10-16 05:35:34 -06:00
|
|
|
int gb_operation_init(void);
|
|
|
|
void gb_operation_exit(void);
|
|
|
|
|
2014-10-01 20:54:15 -06:00
|
|
|
#endif /* !__OPERATION_H */
|