Commit bfa9a5e2 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

greybus: connection: add per-connection request handlers

Add a connection request-handler field to struct gb_connection that is
set when the connection is enabled.

This is a step towards removing the legacy protocol abstraction from
core, and will also be used to implement unidirectional connection
states (e.g. only outgoing operations are allowed).
Reviewed-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarJohan Hovold <johan@hovoldconsulting.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 1cbfab38
...@@ -387,7 +387,8 @@ static int gb_connection_protocol_get_version(struct gb_connection *connection) ...@@ -387,7 +387,8 @@ static int gb_connection_protocol_get_version(struct gb_connection *connection)
return 0; return 0;
} }
int gb_connection_enable(struct gb_connection *connection) int gb_connection_enable(struct gb_connection *connection,
gb_request_handler_t handler)
{ {
int ret; int ret;
...@@ -400,6 +401,7 @@ int gb_connection_enable(struct gb_connection *connection) ...@@ -400,6 +401,7 @@ int gb_connection_enable(struct gb_connection *connection)
goto err_hd_cport_disable; goto err_hd_cport_disable;
spin_lock_irq(&connection->lock); spin_lock_irq(&connection->lock);
connection->handler = handler;
connection->state = GB_CONNECTION_STATE_ENABLED; connection->state = GB_CONNECTION_STATE_ENABLED;
spin_unlock_irq(&connection->lock); spin_unlock_irq(&connection->lock);
...@@ -435,15 +437,28 @@ void gb_connection_disable(struct gb_connection *connection) ...@@ -435,15 +437,28 @@ void gb_connection_disable(struct gb_connection *connection)
} }
EXPORT_SYMBOL_GPL(gb_connection_disable); EXPORT_SYMBOL_GPL(gb_connection_disable);
static int gb_legacy_request_handler(struct gb_operation *operation)
{
struct gb_protocol *protocol = operation->connection->protocol;
return protocol->request_recv(operation->type, operation);
}
int gb_connection_legacy_init(struct gb_connection *connection) int gb_connection_legacy_init(struct gb_connection *connection)
{ {
gb_request_handler_t handler;
int ret; int ret;
ret = gb_connection_bind_protocol(connection); ret = gb_connection_bind_protocol(connection);
if (ret) if (ret)
return ret; return ret;
ret = gb_connection_enable(connection); if (connection->protocol->request_recv)
handler = gb_legacy_request_handler;
else
handler = NULL;
ret = gb_connection_enable(connection, handler);
if (ret) if (ret)
goto err_unbind_protocol; goto err_unbind_protocol;
......
...@@ -20,6 +20,10 @@ enum gb_connection_state { ...@@ -20,6 +20,10 @@ enum gb_connection_state {
GB_CONNECTION_STATE_DESTROYING = 3, GB_CONNECTION_STATE_DESTROYING = 3,
}; };
struct gb_operation;
typedef int (*gb_request_handler_t)(struct gb_operation *);
struct gb_connection { struct gb_connection {
struct gb_host_device *hd; struct gb_host_device *hd;
struct gb_interface *intf; struct gb_interface *intf;
...@@ -31,6 +35,8 @@ struct gb_connection { ...@@ -31,6 +35,8 @@ struct gb_connection {
struct list_head hd_links; struct list_head hd_links;
struct list_head bundle_links; struct list_head bundle_links;
gb_request_handler_t handler;
struct gb_protocol *protocol; struct gb_protocol *protocol;
u8 protocol_id; u8 protocol_id;
u8 major; u8 major;
...@@ -62,7 +68,8 @@ static inline bool gb_connection_is_static(struct gb_connection *connection) ...@@ -62,7 +68,8 @@ static inline bool gb_connection_is_static(struct gb_connection *connection)
return !connection->intf; return !connection->intf;
} }
int gb_connection_enable(struct gb_connection *connection); int gb_connection_enable(struct gb_connection *connection,
gb_request_handler_t handler);
void gb_connection_disable(struct gb_connection *connection); void gb_connection_disable(struct gb_connection *connection);
int gb_connection_legacy_init(struct gb_connection *connection); int gb_connection_legacy_init(struct gb_connection *connection);
......
...@@ -218,15 +218,11 @@ static void gb_message_cancel(struct gb_message *message) ...@@ -218,15 +218,11 @@ static void gb_message_cancel(struct gb_message *message)
static void gb_operation_request_handle(struct gb_operation *operation) static void gb_operation_request_handle(struct gb_operation *operation)
{ {
struct gb_connection *connection = operation->connection; struct gb_connection *connection = operation->connection;
struct gb_protocol *protocol = connection->protocol;
int status; int status;
int ret; int ret;
if (!protocol) if (connection->handler) {
return; status = connection->handler(operation);
if (protocol->request_recv) {
status = protocol->request_recv(operation->type, operation);
} else { } else {
dev_err(&connection->hd->dev, dev_err(&connection->hd->dev,
"%s: unexpected incoming request of type 0x%02x\n", "%s: unexpected incoming request of type 0x%02x\n",
......
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