2019-08-25 13:54:21 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2014-10-02 10:54:15 +08:00
|
|
|
/*
|
|
|
|
* Greybus operations
|
|
|
|
*
|
|
|
|
* Copyright 2014 Google Inc.
|
2014-12-13 02:08:42 +08:00
|
|
|
* Copyright 2014 Linaro Ltd.
|
2014-10-02 10:54:15 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __OPERATION_H
|
|
|
|
#define __OPERATION_H
|
|
|
|
|
|
|
|
#include <linux/completion.h>
|
staging: greybus: add missing includes
Before moving greybus core out of staging and moving header files to
include/linux some greybus header files were missing the necessary
includes. This would trigger compilation faillures with some example
errors logged bellow for with CONFIG_KERNEL_HEADER_TEST=y.
So, add the necessary headers to compile clean before relocating the
header files.
./include/linux/greybus/hd.h:23:50: error: unknown type name 'u16'
int (*cport_disable)(struct gb_host_device *hd, u16 cport_id); ^~~
./include/linux/greybus/greybus_protocols.h:1314:2: error: unknown type name '__u8'
__u8 data[0];
^~~~
./include/linux/greybus/hd.h:24:52: error: unknown type name 'u16'
int (*cport_connected)(struct gb_host_device *hd, u16 cport_id); ^~~
./include/linux/greybus/hd.h:25:48: error: unknown type name 'u16'
int (*cport_flush)(struct gb_host_device *hd, u16 cport_id); ^~~
./include/linux/greybus/hd.h:26:51: error: unknown type name 'u16'
int (*cport_shutdown)(struct gb_host_device *hd, u16 cport_id, ^~~
./include/linux/greybus/hd.h:27:5: error: unknown type name 'u8'
u8 phase, unsigned int timeout);
^~
./include/linux/greybus/hd.h:28:50: error: unknown type name 'u16'
int (*cport_quiesce)(struct gb_host_device *hd, u16 cport_id, ^~~
./include/linux/greybus/hd.h:29:5: error: unknown type name 'size_t'
size_t peer_space, unsigned int timeout);
^~~~~~
./include/linux/greybus/hd.h:29:5: note: 'size_t' is defined in header '<stddef.h>'; did you forget to '#include <stddef.h>'?
./include/linux/greybus/hd.h:1:1:
+#include <stddef.h>
/* SPDX-License-Identifier: GPL-2.0 */
./include/linux/greybus/hd.h:29:5:
size_t peer_space, unsigned int timeout);
^~~~~~
./include/linux/greybus/hd.h:30:48: error: unknown type name 'u16'
int (*cport_clear)(struct gb_host_device *hd, u16 cport_id); ^~~
./include/linux/greybus/hd.h:32:49: error: unknown type name 'u16'
int (*message_send)(struct gb_host_device *hd, u16 dest_cport_id, ^~~
./include/linux/greybus/hd.h:33:32: error: unknown type name 'gfp_t'
struct gb_message *message, gfp_t gfp_mask); ^~~~~
./include/linux/greybus/hd.h:35:55: error: unknown type name 'u16'
int (*latency_tag_enable)(struct gb_host_device *hd, u16 cport_id);
Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Gao Xiang <hsiangkao@aol.com>
Signed-off-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Link: https://lore.kernel.org/r/20190827155302.25704-1-rui.silva@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-27 23:53:02 +08:00
|
|
|
#include <linux/kref.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
|
2019-08-28 20:48:25 +08:00
|
|
|
struct gb_host_device;
|
2014-11-18 08:08:30 +08:00
|
|
|
struct gb_operation;
|
|
|
|
|
2015-07-14 21:43:36 +08:00
|
|
|
/* The default amount of time a request is given to complete */
|
|
|
|
#define GB_OPERATION_TIMEOUT_DEFAULT 1000 /* milliseconds */
|
|
|
|
|
2014-12-03 07:25:11 +08:00
|
|
|
/*
|
|
|
|
* The top bit of the type in an operation message header indicates
|
|
|
|
* whether the message is a request (bit clear) or response (bit set)
|
|
|
|
*/
|
2015-05-08 02:03:52 +08:00
|
|
|
#define GB_MESSAGE_TYPE_RESPONSE ((u8)0x80)
|
2014-12-03 07:25:11 +08:00
|
|
|
|
2014-11-22 09:29:12 +08:00
|
|
|
enum gb_operation_result {
|
2014-12-01 21:53:09 +08: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,
|
2014-12-10 22:43:33 +08:00
|
|
|
GB_OP_NONEXISTENT = 0x08,
|
2014-12-01 21:53:09 +08:00
|
|
|
GB_OP_UNKNOWN_ERROR = 0xfe,
|
|
|
|
GB_OP_MALFUNCTION = 0xff,
|
2014-10-02 10:54:15 +08:00
|
|
|
};
|
|
|
|
|
2015-05-19 17:22:45 +08:00
|
|
|
#define GB_OPERATION_MESSAGE_SIZE_MIN sizeof(struct gb_operation_msg_hdr)
|
2015-05-19 17:22:44 +08:00
|
|
|
#define GB_OPERATION_MESSAGE_SIZE_MAX U16_MAX
|
2015-05-19 17:22:43 +08:00
|
|
|
|
2014-12-04 02:27:44 +08:00
|
|
|
/*
|
2015-07-01 18:37:21 +08:00
|
|
|
* Protocol code should only examine the payload and payload_size fields, and
|
|
|
|
* host-controller drivers may use the hcpriv field. All other fields are
|
|
|
|
* intended to be private to the operations core code.
|
2014-12-04 02:27:44 +08:00
|
|
|
*/
|
2014-11-18 08:08:31 +08:00
|
|
|
struct gb_message {
|
2014-11-21 06:09:14 +08:00
|
|
|
struct gb_operation *operation;
|
2014-12-04 02:27:44 +08:00
|
|
|
struct gb_operation_msg_hdr *header;
|
|
|
|
|
|
|
|
void *payload;
|
|
|
|
size_t payload_size;
|
2014-11-21 06:09:16 +08:00
|
|
|
|
2015-04-07 17:27:17 +08:00
|
|
|
void *buffer;
|
2015-07-01 18:37:21 +08:00
|
|
|
|
|
|
|
void *hcpriv;
|
2014-11-18 08:08:31 +08:00
|
|
|
};
|
|
|
|
|
2015-07-01 18:37:26 +08:00
|
|
|
#define GB_OPERATION_FLAG_INCOMING BIT(0)
|
2015-07-01 18:37:27 +08:00
|
|
|
#define GB_OPERATION_FLAG_UNIDIRECTIONAL BIT(1)
|
2016-02-25 21:40:24 +08:00
|
|
|
#define GB_OPERATION_FLAG_SHORT_RESPONSE BIT(2)
|
2016-05-27 23:26:35 +08:00
|
|
|
#define GB_OPERATION_FLAG_CORE BIT(3)
|
2016-02-25 21:40:24 +08:00
|
|
|
|
2016-04-29 23:08:32 +08:00
|
|
|
#define GB_OPERATION_FLAG_USER_MASK (GB_OPERATION_FLAG_SHORT_RESPONSE | \
|
|
|
|
GB_OPERATION_FLAG_UNIDIRECTIONAL)
|
2015-07-01 18:37:26 +08:00
|
|
|
|
2014-10-02 10:54:15 +08:00
|
|
|
/*
|
|
|
|
* A Greybus operation is a remote procedure call performed over a
|
2014-12-04 02:27:46 +08:00
|
|
|
* connection between two UniPro interfaces.
|
2014-10-02 10:54:15 +08:00
|
|
|
*
|
2014-12-04 02:27:46 +08:00
|
|
|
* Every operation consists of a request message sent to the other
|
|
|
|
* end of the connection coupled with a reply message returned to
|
|
|
|
* the sender. Every operation has a type, whose interpretation is
|
|
|
|
* dependent on the protocol associated with the connection.
|
2014-10-02 10:54:15 +08:00
|
|
|
*
|
2014-12-04 02:27:46 +08:00
|
|
|
* Only four things in an operation structure are intended to be
|
|
|
|
* directly usable by protocol handlers: the operation's connection
|
|
|
|
* pointer; the operation type; the request message payload (and
|
|
|
|
* size); and the response message payload (and size). Note that a
|
|
|
|
* message with a 0-byte payload has a null message payload pointer.
|
2014-10-02 10:54:15 +08:00
|
|
|
*
|
2014-12-04 02:27:46 +08:00
|
|
|
* In addition, every operation has a result, which is an errno
|
|
|
|
* value. Protocol handlers access the operation result using
|
|
|
|
* gb_operation_result().
|
2014-10-02 10:54:15 +08:00
|
|
|
*/
|
|
|
|
typedef void (*gb_operation_callback)(struct gb_operation *);
|
|
|
|
struct gb_operation {
|
|
|
|
struct gb_connection *connection;
|
2014-11-21 06:09:15 +08:00
|
|
|
struct gb_message *request;
|
|
|
|
struct gb_message *response;
|
2014-10-16 19:35:31 +08:00
|
|
|
|
2015-07-01 18:37:26 +08:00
|
|
|
unsigned long flags;
|
|
|
|
u8 type;
|
2014-12-04 02:27:46 +08:00
|
|
|
u16 id;
|
2014-11-22 09:29:12 +08:00
|
|
|
int errno; /* Operation result */
|
|
|
|
|
2014-11-22 09:29:13 +08:00
|
|
|
struct work_struct work;
|
2015-07-01 18:37:28 +08:00
|
|
|
gb_operation_callback callback;
|
|
|
|
struct completion completion;
|
2017-01-23 20:04:14 +08:00
|
|
|
struct timer_list timer;
|
2014-10-02 10:54:15 +08:00
|
|
|
|
2014-11-17 22:08:40 +08:00
|
|
|
struct kref kref;
|
2015-07-14 21:43:26 +08:00
|
|
|
atomic_t waiters;
|
2015-07-14 21:43:25 +08:00
|
|
|
|
2015-07-14 21:43:31 +08:00
|
|
|
int active;
|
2014-12-03 22:35:07 +08:00
|
|
|
struct list_head links; /* connection->operations */
|
2017-11-06 09:32:21 +08:00
|
|
|
|
|
|
|
void *private;
|
2014-10-02 10:54:15 +08:00
|
|
|
};
|
|
|
|
|
2015-07-01 18:37:26 +08:00
|
|
|
static inline bool
|
|
|
|
gb_operation_is_incoming(struct gb_operation *operation)
|
|
|
|
{
|
|
|
|
return operation->flags & GB_OPERATION_FLAG_INCOMING;
|
|
|
|
}
|
|
|
|
|
2015-07-01 18:37:27 +08:00
|
|
|
static inline bool
|
|
|
|
gb_operation_is_unidirectional(struct gb_operation *operation)
|
|
|
|
{
|
|
|
|
return operation->flags & GB_OPERATION_FLAG_UNIDIRECTIONAL;
|
|
|
|
}
|
|
|
|
|
2016-02-25 21:40:24 +08:00
|
|
|
static inline bool
|
|
|
|
gb_operation_short_response_allowed(struct gb_operation *operation)
|
|
|
|
{
|
|
|
|
return operation->flags & GB_OPERATION_FLAG_SHORT_RESPONSE;
|
|
|
|
}
|
|
|
|
|
2016-05-27 23:26:35 +08:00
|
|
|
static inline bool gb_operation_is_core(struct gb_operation *operation)
|
|
|
|
{
|
|
|
|
return operation->flags & GB_OPERATION_FLAG_CORE;
|
|
|
|
}
|
|
|
|
|
2014-11-19 03:26:50 +08:00
|
|
|
void gb_connection_recv(struct gb_connection *connection,
|
2014-10-16 19:35:33 +08:00
|
|
|
void *data, size_t size);
|
|
|
|
|
2014-11-26 01:33:13 +08:00
|
|
|
int gb_operation_result(struct gb_operation *operation);
|
|
|
|
|
2015-05-19 17:22:46 +08:00
|
|
|
size_t gb_operation_get_payload_size_max(struct gb_connection *connection);
|
2016-02-25 21:40:24 +08:00
|
|
|
struct gb_operation *
|
|
|
|
gb_operation_create_flags(struct gb_connection *connection,
|
|
|
|
u8 type, size_t request_size,
|
|
|
|
size_t response_size, unsigned long flags,
|
|
|
|
gfp_t gfp);
|
|
|
|
|
|
|
|
static inline struct gb_operation *
|
|
|
|
gb_operation_create(struct gb_connection *connection,
|
|
|
|
u8 type, size_t request_size,
|
|
|
|
size_t response_size, gfp_t gfp)
|
|
|
|
{
|
|
|
|
return gb_operation_create_flags(connection, type, request_size,
|
|
|
|
response_size, 0, gfp);
|
|
|
|
}
|
|
|
|
|
2016-05-27 23:26:35 +08:00
|
|
|
struct gb_operation *
|
|
|
|
gb_operation_create_core(struct gb_connection *connection,
|
|
|
|
u8 type, size_t request_size,
|
|
|
|
size_t response_size, unsigned long flags,
|
|
|
|
gfp_t gfp);
|
|
|
|
|
2014-11-22 09:29:15 +08:00
|
|
|
void gb_operation_get(struct gb_operation *operation);
|
2014-11-17 22:08:40 +08:00
|
|
|
void gb_operation_put(struct gb_operation *operation);
|
2014-10-02 10:54:15 +08:00
|
|
|
|
2014-12-02 22:30:39 +08:00
|
|
|
bool gb_operation_response_alloc(struct gb_operation *operation,
|
2015-07-18 00:50:25 +08:00
|
|
|
size_t response_size, gfp_t gfp);
|
2014-12-02 22:30:39 +08:00
|
|
|
|
2014-10-16 19:35:33 +08:00
|
|
|
int gb_operation_request_send(struct gb_operation *operation,
|
2015-07-01 18:37:23 +08:00
|
|
|
gb_operation_callback callback,
|
2017-01-23 20:04:14 +08:00
|
|
|
unsigned int timeout,
|
2015-07-01 18:37:23 +08:00
|
|
|
gfp_t gfp);
|
2015-07-14 21:43:36 +08:00
|
|
|
int gb_operation_request_send_sync_timeout(struct gb_operation *operation,
|
|
|
|
unsigned int timeout);
|
|
|
|
static inline int
|
|
|
|
gb_operation_request_send_sync(struct gb_operation *operation)
|
|
|
|
{
|
|
|
|
return gb_operation_request_send_sync_timeout(operation,
|
|
|
|
GB_OPERATION_TIMEOUT_DEFAULT);
|
|
|
|
}
|
2014-10-16 19:35:33 +08:00
|
|
|
|
2014-11-22 09:29:17 +08:00
|
|
|
void gb_operation_cancel(struct gb_operation *operation, int errno);
|
2015-07-14 21:43:35 +08:00
|
|
|
void gb_operation_cancel_incoming(struct gb_operation *operation, int errno);
|
2014-10-02 10:54:15 +08:00
|
|
|
|
2015-11-04 01:03:23 +08:00
|
|
|
void greybus_message_sent(struct gb_host_device *hd,
|
2015-04-07 17:27:16 +08:00
|
|
|
struct gb_message *message, int status);
|
2014-11-21 06:09:17 +08:00
|
|
|
|
2015-07-14 21:43:37 +08:00
|
|
|
int gb_operation_sync_timeout(struct gb_connection *connection, int type,
|
|
|
|
void *request, int request_size,
|
|
|
|
void *response, int response_size,
|
|
|
|
unsigned int timeout);
|
2016-04-29 23:08:33 +08:00
|
|
|
int gb_operation_unidirectional_timeout(struct gb_connection *connection,
|
|
|
|
int type, void *request, int request_size,
|
|
|
|
unsigned int timeout);
|
2015-07-14 21:43:37 +08:00
|
|
|
|
|
|
|
static inline int gb_operation_sync(struct gb_connection *connection, int type,
|
2014-11-25 03:19:13 +08:00
|
|
|
void *request, int request_size,
|
2015-07-14 21:43:37 +08:00
|
|
|
void *response, int response_size)
|
|
|
|
{
|
|
|
|
return gb_operation_sync_timeout(connection, type,
|
|
|
|
request, request_size, response, response_size,
|
|
|
|
GB_OPERATION_TIMEOUT_DEFAULT);
|
|
|
|
}
|
2014-11-25 03:19:13 +08:00
|
|
|
|
2016-04-29 23:08:33 +08:00
|
|
|
static inline int gb_operation_unidirectional(struct gb_connection *connection,
|
|
|
|
int type, void *request, int request_size)
|
|
|
|
{
|
|
|
|
return gb_operation_unidirectional_timeout(connection, type,
|
|
|
|
request, request_size, GB_OPERATION_TIMEOUT_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2017-11-06 09:32:21 +08:00
|
|
|
static inline void *gb_operation_get_data(struct gb_operation *operation)
|
|
|
|
{
|
|
|
|
return operation->private;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void gb_operation_set_data(struct gb_operation *operation,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
operation->private = data;
|
|
|
|
}
|
|
|
|
|
2015-06-12 00:22:51 +08:00
|
|
|
int gb_operation_init(void);
|
2015-06-10 06:42:51 +08:00
|
|
|
void gb_operation_exit(void);
|
2014-10-16 19:35:34 +08:00
|
|
|
|
2014-10-02 10:54:15 +08:00
|
|
|
#endif /* !__OPERATION_H */
|