]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
greybus: add an incoming request receive method
authorAlex Elder <elder@linaro.org>
Wed, 5 Nov 2014 22:12:55 +0000 (16:12 -0600)
committerGreg Kroah-Hartman <greg@kroah.com>
Wed, 5 Nov 2014 22:23:50 +0000 (14:23 -0800)
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>
drivers/staging/greybus/battery-gb.c
drivers/staging/greybus/gpio-gb.c
drivers/staging/greybus/i2c-gb.c
drivers/staging/greybus/operation.c
drivers/staging/greybus/protocol.h
drivers/staging/greybus/sdio-gb.c
drivers/staging/greybus/uart-gb.c

index a4015673bf4c593933a04f009cfb69dc15243c2e..4bd7aed0a27b581c56ef4b3889b22da0d36ce3e9 100644 (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)
index a4ee35671434fd76eec4bd8492cb02ab33ce55bc..40833fa69efee56bda528bf866e6eaa238980262 100644 (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)
index 60db15ee364d02728119ad76fe9aca0f616b07a4..c179078b8a2e2dc386c5d10198b844ecb3a7f61d 100644 (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)
index 9cb9c9d590d28dc83147589cdd91506468d34f47..24707f67622c18dae480a342f12c75d47ec5b4e2 100644 (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;
-
-       /* 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);
 }
 
index 32178f1f2671a28cef3d58b247d3544f4a47cf4b..a236401b48abfc7c433e31d6fec73064d08f1b4d 100644 (file)
 
 #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);
index 9e5fb8f26425bda9856931ebb5040f3bae16e1b6..4775ed0c7beada816539d185d288b10c110b329a 100644 (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)
index 56db8911d800ca4fd5b6ff29e3c8629442cd7e85..9638d0e8aa0d2db27a0e83de93d569ee772c7fa7 100644 (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)