greybus: op_cycle doesn't need to be atomic

We can update a connection's operation id counter under spinlock,
and thereby avoid the need to maintain it in an atomic variable.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Alex Elder 2014-11-12 15:17:54 -06:00 committed by Greg Kroah-Hartman
parent b8616da875
commit 360a8779d9
3 changed files with 9 additions and 16 deletions

View file

@ -210,7 +210,6 @@ struct gb_connection *gb_connection_create(struct gb_interface *interface,
INIT_LIST_HEAD(&connection->operations);
INIT_LIST_HEAD(&connection->pending);
atomic_set(&connection->op_cycle, 0);
return connection;
}
@ -244,11 +243,6 @@ void gb_connection_destroy(struct gb_connection *connection)
device_del(&connection->dev);
}
u16 gb_connection_operation_id(struct gb_connection *connection)
{
return (u16)(atomic_inc_return(&connection->op_cycle) & (int)U16_MAX);
}
void gb_connection_err(struct gb_connection *connection, const char *fmt, ...)
{
struct va_format vaf;

View file

@ -35,9 +35,9 @@ struct gb_connection {
enum gb_connection_state state;
u16 op_cycle;
struct list_head operations;
struct list_head pending; /* awaiting reponse */
atomic_t op_cycle;
void *private;
};
@ -53,8 +53,6 @@ void gb_connection_exit(struct gb_connection *connection);
struct gb_connection *gb_hd_connection_find(struct greybus_host_device *hd,
u16 cport_id);
u16 gb_connection_operation_id(struct gb_connection *connection);
__printf(2, 3)
void gb_connection_err(struct gb_connection *connection, const char *fmt, ...);

View file

@ -61,17 +61,18 @@ static void gb_pending_operation_insert(struct gb_operation *operation)
struct gb_connection *connection = operation->connection;
struct gb_operation_msg_hdr *header;
/* Assign the operation's id, and store it in the header of
* the request message header.
/*
* Assign the operation's id and move it into its
* connection's pending list.
*/
operation->id = gb_connection_operation_id(connection);
header = operation->request->transfer_buffer;
header->id = cpu_to_le16(operation->id);
/* Insert the operation into its connection's pending list */
spin_lock_irq(&gb_operations_lock);
operation->id = ++connection->op_cycle;
list_move_tail(&operation->links, &connection->pending);
spin_unlock_irq(&gb_operations_lock);
/* Store the operation id in the request header */
header = operation->request->transfer_buffer;
header->id = cpu_to_le16(operation->id);
}
static void gb_pending_operation_remove(struct gb_operation *operation)