From: Alex Elder Date: Wed, 5 Nov 2014 22:12:55 +0000 (-0600) Subject: greybus: add an incoming request receive method X-Git-Tag: v4.13~2185^2~378^2~21^2~1932 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=f8fb05e2b89eddaadce319fb55a532731393e630;p=mirror_ubuntu-bionic-kernel.git 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/battery-gb.c b/drivers/staging/greybus/battery-gb.c index a4015673bf4c..4bd7aed0a27b 100644 --- a/drivers/staging/greybus/battery-gb.c +++ b/drivers/staging/greybus/battery-gb.c @@ -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) diff --git a/drivers/staging/greybus/gpio-gb.c b/drivers/staging/greybus/gpio-gb.c index a4ee35671434..40833fa69efe 100644 --- a/drivers/staging/greybus/gpio-gb.c +++ b/drivers/staging/greybus/gpio-gb.c @@ -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) diff --git a/drivers/staging/greybus/i2c-gb.c b/drivers/staging/greybus/i2c-gb.c index 60db15ee364d..c179078b8a2e 100644 --- a/drivers/staging/greybus/i2c-gb.c +++ b/drivers/staging/greybus/i2c-gb.c @@ -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) diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c index 9cb9c9d590d2..24707f67622c 100644 --- a/drivers/staging/greybus/operation.c +++ b/drivers/staging/greybus/operation.c @@ -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; - - /* 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; + struct gb_protocol *protocol = operation->connection->protocol; + struct gb_operation_msg_hdr *header; - 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); } diff --git a/drivers/staging/greybus/protocol.h b/drivers/staging/greybus/protocol.h index 32178f1f2671..a236401b48ab 100644 --- a/drivers/staging/greybus/protocol.h +++ b/drivers/staging/greybus/protocol.h @@ -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); diff --git a/drivers/staging/greybus/sdio-gb.c b/drivers/staging/greybus/sdio-gb.c index 9e5fb8f26425..4775ed0c7bea 100644 --- a/drivers/staging/greybus/sdio-gb.c +++ b/drivers/staging/greybus/sdio-gb.c @@ -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) diff --git a/drivers/staging/greybus/uart-gb.c b/drivers/staging/greybus/uart-gb.c index 56db8911d800..9638d0e8aa0d 100644 --- a/drivers/staging/greybus/uart-gb.c +++ b/drivers/staging/greybus/uart-gb.c @@ -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)