Commit c939c2f8 authored by Alex Elder's avatar Alex Elder Committed by Greg Kroah-Hartman

greybus: define the invalid operation type symbolically

Use a symbolic constant (rather than just "0") to represent an
explicitly invalid operation type.  The protocols have all reserved
that value for that purpose--this just makes it explicit in the core
code (since we now leverage its existence).  Fix the code so it uses
the new symbolic value.

Define it in "operation.h" for all to see.  Move the common
definition of the GB_OPERATION_TYPE_RESPONSE flag mask there
as well.
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 6cd6ec55
...@@ -13,12 +13,6 @@ ...@@ -13,12 +13,6 @@
#include "greybus.h" #include "greybus.h"
/*
* The top bit of the type in an operation message header indicates
* whether the message is a request (bit clear) or response (bit set)
*/
#define GB_OPERATION_TYPE_RESPONSE 0x80
#define OPERATION_TIMEOUT_DEFAULT 1000 /* milliseconds */ #define OPERATION_TIMEOUT_DEFAULT 1000 /* milliseconds */
/* /*
...@@ -329,7 +323,7 @@ static void gb_operation_message_init(struct greybus_host_device *hd, ...@@ -329,7 +323,7 @@ static void gb_operation_message_init(struct greybus_host_device *hd,
* 0x00. Such buffers will be overwritten by arriving data * 0x00. Such buffers will be overwritten by arriving data
* so there's no need to initialize the message header. * so there's no need to initialize the message header.
*/ */
if (type) { if (type != GB_OPERATION_TYPE_INVALID) {
/* /*
* For a request, the operation id gets filled in * For a request, the operation id gets filled in
* when the message is sent. For a response, it * when the message is sent. For a response, it
...@@ -527,8 +521,17 @@ gb_operation_create_common(struct gb_connection *connection, u8 type, ...@@ -527,8 +521,17 @@ gb_operation_create_common(struct gb_connection *connection, u8 type,
{ {
struct greybus_host_device *hd = connection->hd; struct greybus_host_device *hd = connection->hd;
struct gb_operation *operation; struct gb_operation *operation;
gfp_t gfp_flags = type ? GFP_KERNEL : GFP_ATOMIC; gfp_t gfp_flags;
/*
* An incoming request will pass an invalid operation type,
* because the header will get overwritten anyway. These
* occur in interrupt context, so we must use GFP_ATOMIC.
*/
if (type == GB_OPERATION_TYPE_INVALID)
gfp_flags = GFP_ATOMIC;
else
gfp_flags = GFP_KERNEL;
operation = kmem_cache_zalloc(gb_operation_cache, gfp_flags); operation = kmem_cache_zalloc(gb_operation_cache, gfp_flags);
if (!operation) if (!operation)
return NULL; return NULL;
...@@ -541,7 +544,7 @@ gb_operation_create_common(struct gb_connection *connection, u8 type, ...@@ -541,7 +544,7 @@ gb_operation_create_common(struct gb_connection *connection, u8 type,
operation->request->operation = operation; operation->request->operation = operation;
/* Allocate the response buffer for outgoing operations */ /* Allocate the response buffer for outgoing operations */
if (type) if (type != GB_OPERATION_TYPE_INVALID)
if (!gb_operation_response_alloc(operation, response_size)) if (!gb_operation_response_alloc(operation, response_size))
goto err_request; goto err_request;
operation->errno = -EBADR; /* Initial value--means "never set" */ operation->errno = -EBADR; /* Initial value--means "never set" */
...@@ -578,7 +581,7 @@ struct gb_operation *gb_operation_create(struct gb_connection *connection, ...@@ -578,7 +581,7 @@ struct gb_operation *gb_operation_create(struct gb_connection *connection,
u8 type, size_t request_size, u8 type, size_t request_size,
size_t response_size) size_t response_size)
{ {
if (WARN_ON_ONCE(!type)) if (WARN_ON_ONCE(type == GB_OPERATION_TYPE_INVALID))
return NULL; return NULL;
if (WARN_ON_ONCE(type & GB_OPERATION_TYPE_RESPONSE)) if (WARN_ON_ONCE(type & GB_OPERATION_TYPE_RESPONSE))
type &= ~GB_OPERATION_TYPE_RESPONSE; type &= ~GB_OPERATION_TYPE_RESPONSE;
...@@ -593,7 +596,9 @@ gb_operation_create_incoming(struct gb_connection *connection, u16 id, ...@@ -593,7 +596,9 @@ gb_operation_create_incoming(struct gb_connection *connection, u16 id,
{ {
struct gb_operation *operation; struct gb_operation *operation;
operation = gb_operation_create_common(connection, 0, request_size, 0); operation = gb_operation_create_common(connection,
GB_OPERATION_TYPE_INVALID,
request_size, 0);
if (operation) { if (operation) {
operation->id = id; operation->id = id;
memcpy(operation->request->header, data, request_size); memcpy(operation->request->header, data, request_size);
......
...@@ -13,6 +13,18 @@ ...@@ -13,6 +13,18 @@
struct gb_operation; struct gb_operation;
/*
* No protocol may define an operation that has numeric value 0x00.
* It is reserved as an explicitly invalid value.
*/
#define GB_OPERATION_TYPE_INVALID ((u8)0x00)
/*
* The top bit of the type in an operation message header indicates
* whether the message is a request (bit clear) or response (bit set)
*/
#define GB_OPERATION_TYPE_RESPONSE ((u8)0x80)
enum gb_operation_result { enum gb_operation_result {
GB_OP_SUCCESS = 0x00, GB_OP_SUCCESS = 0x00,
GB_OP_INTERRUPTED = 0x01, GB_OP_INTERRUPTED = 0x01,
......
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