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: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This commit is contained in:
Alex Elder 2014-11-05 16:12:55 -06:00 committed by Greg Kroah-Hartman
parent 5d9fd7e1ba
commit f8fb05e2b8
7 changed files with 21 additions and 33 deletions

View file

@ -406,6 +406,7 @@ static struct gb_protocol battery_protocol = {
.minor = 1,
.connection_init = gb_battery_connection_init,
.connection_exit = gb_battery_connection_exit,
.request_recv = NULL, /* no incoming requests */
};
bool gb_battery_protocol_init(void)

View file

@ -798,6 +798,7 @@ static struct gb_protocol gpio_protocol = {
.minor = 1,
.connection_init = gb_gpio_connection_init,
.connection_exit = gb_gpio_connection_exit,
.request_recv = NULL, /* no incoming requests */
};
bool gb_gpio_protocol_init(void)

View file

@ -524,6 +524,7 @@ static struct gb_protocol i2c_protocol = {
.minor = 1,
.connection_init = gb_i2c_connection_init,
.connection_exit = gb_i2c_connection_exit,
.request_recv = NULL, /* no incoming requests */
};
bool gb_i2c_protocol_init(void)

View file

@ -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)
{
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) {
handler(operation); /* Handle the request */
return;
}
/*
* If the protocol has no incoming request handler, report
* an error and mark the request bad.
*/
if (protocol->request_recv) {
protocol->request_recv(operation);
goto out;
}
header = operation->request->transfer_buffer;
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;
out:
gb_operation_complete(operation);
}

View file

@ -11,8 +11,11 @@
#include "greybus.h"
struct gb_operation;
typedef int (*gb_connection_init_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
@ -29,6 +32,7 @@ struct gb_protocol {
gb_connection_init_t connection_init;
gb_connection_exit_t connection_exit;
gb_request_recv_t request_recv;
};
bool gb_protocol_register(struct gb_protocol *protocol);

View file

@ -83,6 +83,7 @@ static struct gb_protocol sdio_protocol = {
.minor = 1,
.connection_init = gb_sdio_connection_init,
.connection_exit = gb_sdio_connection_exit,
.request_recv = NULL, /* no incoming requests */
};
bool gb_sdio_protocol_init(void)

View file

@ -526,6 +526,7 @@ static struct gb_protocol uart_protocol = {
.minor = 1,
.connection_init = gb_uart_connection_init,
.connection_exit = gb_uart_connection_exit,
.request_recv = NULL, /* no incoming requests */
};
bool gb_uart_protocol_init(void)