Commit f8fb05e2 authored by Alex Elder's avatar Alex Elder Committed by Greg Kroah-Hartman

greybus: add an incoming request receive method

Define a new protocol method intended to handle the receipt of an
incoming operation request.  Most protocols have no expected
incoming requests and can leave this null.  If a request arrives for
a protocol with no request receive handler an error is reported and
the request fails.

Get rid of the previous fixed array of receive handlers, it's
no longer needed.
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 5d9fd7e1
...@@ -406,6 +406,7 @@ static struct gb_protocol battery_protocol = { ...@@ -406,6 +406,7 @@ static struct gb_protocol battery_protocol = {
.minor = 1, .minor = 1,
.connection_init = gb_battery_connection_init, .connection_init = gb_battery_connection_init,
.connection_exit = gb_battery_connection_exit, .connection_exit = gb_battery_connection_exit,
.request_recv = NULL, /* no incoming requests */
}; };
bool gb_battery_protocol_init(void) bool gb_battery_protocol_init(void)
......
...@@ -798,6 +798,7 @@ static struct gb_protocol gpio_protocol = { ...@@ -798,6 +798,7 @@ static struct gb_protocol gpio_protocol = {
.minor = 1, .minor = 1,
.connection_init = gb_gpio_connection_init, .connection_init = gb_gpio_connection_init,
.connection_exit = gb_gpio_connection_exit, .connection_exit = gb_gpio_connection_exit,
.request_recv = NULL, /* no incoming requests */
}; };
bool gb_gpio_protocol_init(void) bool gb_gpio_protocol_init(void)
......
...@@ -524,6 +524,7 @@ static struct gb_protocol i2c_protocol = { ...@@ -524,6 +524,7 @@ static struct gb_protocol i2c_protocol = {
.minor = 1, .minor = 1,
.connection_init = gb_i2c_connection_init, .connection_init = gb_i2c_connection_init,
.connection_exit = gb_i2c_connection_exit, .connection_exit = gb_i2c_connection_exit,
.request_recv = NULL, /* no incoming requests */
}; };
bool gb_i2c_protocol_init(void) bool gb_i2c_protocol_init(void)
......
...@@ -176,46 +176,25 @@ int gb_operation_wait(struct gb_operation *operation) ...@@ -176,46 +176,25 @@ int gb_operation_wait(struct gb_operation *operation)
} }
/*
* This handler is used if no operation response messages are ever
* expected for a given protocol.
*/
static void gb_operation_recv_none(struct gb_operation *operation)
{
/* Nothing to do! */
}
typedef void (*gb_operation_recv_handler)(struct gb_operation *operation);
static gb_operation_recv_handler gb_operation_recv_handlers[] = {
[GREYBUS_PROTOCOL_CONTROL] = NULL,
[GREYBUS_PROTOCOL_AP] = NULL,
[GREYBUS_PROTOCOL_GPIO] = NULL,
[GREYBUS_PROTOCOL_I2C] = gb_operation_recv_none,
[GREYBUS_PROTOCOL_UART] = NULL,
[GREYBUS_PROTOCOL_HID] = NULL,
[GREYBUS_PROTOCOL_BATTERY] = gb_operation_recv_none,
[GREYBUS_PROTOCOL_LED] = NULL,
[GREYBUS_PROTOCOL_VENDOR] = NULL,
};
static void gb_operation_request_handle(struct gb_operation *operation) static void gb_operation_request_handle(struct gb_operation *operation)
{ {
u8 protocol_id = operation->connection->protocol->id; struct gb_protocol *protocol = operation->connection->protocol;
struct gb_operation_msg_hdr *header;
/* Subtract one from array size to stay within u8 range */
if (protocol_id <= (u8)(ARRAY_SIZE(gb_operation_recv_handlers) - 1)) {
gb_operation_recv_handler handler;
handler = gb_operation_recv_handlers[protocol_id]; /*
if (handler) { * If the protocol has no incoming request handler, report
handler(operation); /* Handle the request */ * an error and mark the request bad.
return; */
} if (protocol->request_recv) {
protocol->request_recv(operation);
goto out;
} }
header = operation->request->transfer_buffer;
gb_connection_err(operation->connection, gb_connection_err(operation->connection,
"unrecognized protocol id %hhu\n", protocol_id); "unexpected incoming request type 0x%02hhx\n", header->type);
operation->result = GB_OP_PROTOCOL_BAD; operation->result = GB_OP_PROTOCOL_BAD;
out:
gb_operation_complete(operation); gb_operation_complete(operation);
} }
......
...@@ -11,8 +11,11 @@ ...@@ -11,8 +11,11 @@
#include "greybus.h" #include "greybus.h"
struct gb_operation;
typedef int (*gb_connection_init_t)(struct gb_connection *); typedef int (*gb_connection_init_t)(struct gb_connection *);
typedef void (*gb_connection_exit_t)(struct gb_connection *); typedef void (*gb_connection_exit_t)(struct gb_connection *);
typedef void (*gb_request_recv_t)(struct gb_operation *);
/* /*
* Protocols having the same id but different major and/or minor * Protocols having the same id but different major and/or minor
...@@ -29,6 +32,7 @@ struct gb_protocol { ...@@ -29,6 +32,7 @@ struct gb_protocol {
gb_connection_init_t connection_init; gb_connection_init_t connection_init;
gb_connection_exit_t connection_exit; gb_connection_exit_t connection_exit;
gb_request_recv_t request_recv;
}; };
bool gb_protocol_register(struct gb_protocol *protocol); bool gb_protocol_register(struct gb_protocol *protocol);
......
...@@ -83,6 +83,7 @@ static struct gb_protocol sdio_protocol = { ...@@ -83,6 +83,7 @@ static struct gb_protocol sdio_protocol = {
.minor = 1, .minor = 1,
.connection_init = gb_sdio_connection_init, .connection_init = gb_sdio_connection_init,
.connection_exit = gb_sdio_connection_exit, .connection_exit = gb_sdio_connection_exit,
.request_recv = NULL, /* no incoming requests */
}; };
bool gb_sdio_protocol_init(void) bool gb_sdio_protocol_init(void)
......
...@@ -526,6 +526,7 @@ static struct gb_protocol uart_protocol = { ...@@ -526,6 +526,7 @@ static struct gb_protocol uart_protocol = {
.minor = 1, .minor = 1,
.connection_init = gb_uart_connection_init, .connection_init = gb_uart_connection_init,
.connection_exit = gb_uart_connection_exit, .connection_exit = gb_uart_connection_exit,
.request_recv = NULL, /* no incoming requests */
}; };
bool gb_uart_protocol_init(void) bool gb_uart_protocol_init(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment