1
0
Fork 0

greybus: connection: add unidirectional enabled state

Add a new connection state ENABLED_TX in which only outgoing operations
are allowed.

This allows drivers to query the device during probe before allocating
their state containers without having to worry about racing incoming
requests.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
hifive-unleashed-5.1
Johan Hovold 2016-01-19 12:51:07 +01:00 committed by Greg Kroah-Hartman
parent 23268785b2
commit 570dfa7c55
3 changed files with 29 additions and 4 deletions

View File

@ -396,6 +396,18 @@ int gb_connection_enable(struct gb_connection *connection,
if (connection->state == GB_CONNECTION_STATE_ENABLED)
goto out_unlock;
if (connection->state == GB_CONNECTION_STATE_ENABLED_TX) {
if (!handler)
goto out_unlock;
spin_lock_irq(&connection->lock);
connection->handler = handler;
connection->state = GB_CONNECTION_STATE_ENABLED;
spin_unlock_irq(&connection->lock);
goto out_unlock;
}
ret = gb_connection_hd_cport_enable(connection);
if (ret)
goto err_unlock;
@ -406,7 +418,10 @@ int gb_connection_enable(struct gb_connection *connection,
spin_lock_irq(&connection->lock);
connection->handler = handler;
connection->state = GB_CONNECTION_STATE_ENABLED;
if (handler)
connection->state = GB_CONNECTION_STATE_ENABLED;
else
connection->state = GB_CONNECTION_STATE_ENABLED_TX;
spin_unlock_irq(&connection->lock);
ret = gb_connection_control_connected(connection);
@ -422,6 +437,7 @@ err_svc_destroy:
spin_lock_irq(&connection->lock);
connection->state = GB_CONNECTION_STATE_DISABLED;
gb_connection_cancel_operations(connection, -ESHUTDOWN);
connection->handler = NULL;
spin_unlock_irq(&connection->lock);
gb_connection_svc_connection_destroy(connection);
@ -446,6 +462,7 @@ void gb_connection_disable(struct gb_connection *connection)
spin_lock_irq(&connection->lock);
connection->state = GB_CONNECTION_STATE_DISABLED;
gb_connection_cancel_operations(connection, -ESHUTDOWN);
connection->handler = NULL;
spin_unlock_irq(&connection->lock);
gb_connection_svc_connection_destroy(connection);

View File

@ -16,7 +16,8 @@
enum gb_connection_state {
GB_CONNECTION_STATE_INVALID = 0,
GB_CONNECTION_STATE_DISABLED = 1,
GB_CONNECTION_STATE_ENABLED = 2,
GB_CONNECTION_STATE_ENABLED_TX = 2,
GB_CONNECTION_STATE_ENABLED = 3,
};
struct gb_operation;
@ -70,6 +71,10 @@ static inline bool gb_connection_is_static(struct gb_connection *connection)
int gb_connection_enable(struct gb_connection *connection,
gb_request_handler_t handler);
static inline int gb_connection_enable_tx(struct gb_connection *connection)
{
return gb_connection_enable(connection, NULL);
}
void gb_connection_disable(struct gb_connection *connection);
int gb_connection_legacy_init(struct gb_connection *connection);

View File

@ -47,7 +47,9 @@ static int gb_operation_get_active(struct gb_operation *operation)
spin_lock_irqsave(&connection->lock, flags);
if (connection->state != GB_CONNECTION_STATE_ENABLED) {
if (connection->state != GB_CONNECTION_STATE_ENABLED &&
connection->state != GB_CONNECTION_STATE_ENABLED_TX &&
!gb_operation_is_incoming(operation)) {
spin_unlock_irqrestore(&connection->lock, flags);
return -ENOTCONN;
}
@ -906,7 +908,8 @@ void gb_connection_recv(struct gb_connection *connection,
size_t msg_size;
u16 operation_id;
if (connection->state != GB_CONNECTION_STATE_ENABLED) {
if (connection->state != GB_CONNECTION_STATE_ENABLED &&
connection->state != GB_CONNECTION_STATE_ENABLED_TX) {
dev_warn(dev, "%s: dropping %zu received bytes\n",
connection->name, size);
return;