operation->result);
} else {
/* Good response, so copy to the caller's buffer */
- memcpy(response, operation->response.payload, response_size);
+ memcpy(response, operation->response->payload, response_size);
}
out:
gb_operation_destroy(operation);
gb_connection_err(connection, "version result %hhu",
operation->result);
} else {
- response = operation->response.payload;
+ response = operation->response->payload;
if (response->major > GB_GPIO_VERSION_MAJOR) {
pr_err("unsupported major version (%hhu > %hhu)\n",
response->major, GB_GPIO_VERSION_MAJOR);
gb_connection_err(connection, "line count result %hhu",
operation->result);
} else {
- response = operation->response.payload;
+ response = operation->response->payload;
gb_gpio_controller->line_max = response->count;
pr_debug("%s: count = %u\n", __func__,
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
/* Synchronous operation--no callback */
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
/* Synchronous operation--no callback */
sizeof(*request), sizeof(*response));
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
/* Synchronous operation--no callback */
} else {
u8 direction;
- response = operation->response.payload;
+ response = operation->response->payload;
direction = response->direction;
if (direction && direction != 1)
pr_warn("gpio %u direction was %u (should be 0 or 1)\n",
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
/* Synchronous operation--no callback */
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
request->value = value_high ? 1 : 0;
sizeof(*request), sizeof(*response));
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
/* Synchronous operation--no callback */
} else {
u8 value;
- response = operation->response.payload;
+ response = operation->response->payload;
value = response->value;
if (value && value != 1)
pr_warn("gpio %u value was %u (should be 0 or 1)\n",
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
request->value = value_high ? 1 : 0;
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
request->usec = cpu_to_le16(debounce_usec);
gb_connection_err(connection, "version result %hhu",
operation->result);
} else {
- response = operation->response.payload;
+ response = operation->response->payload;
if (response->major > GB_I2C_VERSION_MAJOR) {
pr_err("unsupported major version (%hhu > %hhu)\n",
response->major, GB_I2C_VERSION_MAJOR);
gb_connection_err(connection, "functionality result %hhu",
operation->result);
} else {
- response = operation->response.payload;
+ response = operation->response->payload;
functionality = le32_to_cpu(response->functionality);
gb_i2c_dev->functionality =
gb_i2c_functionality_map(functionality);
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->msec = cpu_to_le16(msec);
/* Synchronous operation--no callback */
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->retries = retries;
/* Synchronous operation--no callback */
if (!operation)
return NULL;
- request = operation->request.payload;
+ request = operation->request->payload;
request->op_count = cpu_to_le16(op_count);
/* Fill in the ops array */
op = &request->ops[0];
operation->result);
}
} else {
- response = operation->response.payload;
+ response = operation->response->payload;
gb_i2c_transfer_response(msgs, msg_count, response->data);
ret = msg_count;
}
spin_unlock_irq(&gb_operations_lock);
/* Store the operation id in the request header */
- header = operation->request.header;
+ header = operation->request->header;
header->operation_id = cpu_to_le16(operation->id);
}
ret = wait_for_completion_interruptible(&operation->completion);
/* If interrupted, cancel the in-flight buffer */
if (ret < 0)
- gb_message_cancel(&operation->request);
+ gb_message_cancel(operation->request);
return ret;
}
struct gb_protocol *protocol = operation->connection->protocol;
struct gb_operation_msg_hdr *header;
- header = operation->request.header;
+ header = operation->request->header;
/*
* If the protocol has no incoming request handler, report
bool incoming_request;
operation = container_of(recv_work, struct gb_operation, recv_work);
- incoming_request = operation->response.header == NULL;
+ incoming_request = operation->response->header == NULL;
if (incoming_request)
gb_operation_request_handle(operation);
gb_operation_complete(operation);
}
/*
- * Allocate a buffer to be used for an operation request or response
- * message. For outgoing messages, both types of message contain a
+ * Allocate a message to be used for an operation request or
+ * response. For outgoing messages, both types of message contain a
* common header, which is filled in here. Incoming requests or
* responses also contain the same header, but there's no need to
* initialize it here (it'll be overwritten by the incoming
* message).
*/
-static int gb_operation_message_init(struct gb_operation *operation,
- u8 type, size_t size,
- bool request, gfp_t gfp_flags)
+static struct gb_message *
+gb_operation_message_alloc(struct greybus_host_device *hd, u8 type,
+ size_t size, gfp_t gfp_flags)
{
- struct gb_connection *connection = operation->connection;
- struct greybus_host_device *hd = connection->hd;
struct gb_message *message;
struct gb_operation_msg_hdr *header;
size += sizeof(*header);
if (size > hd->buffer_size_max)
- return -E2BIG;
+ return NULL;
- if (request) {
- message = &operation->request;
- } else {
- message = &operation->response;
- type |= GB_OPERATION_TYPE_RESPONSE;
- }
+ message = kzalloc(sizeof(*message), gfp_flags);
+ if (!message)
+ return NULL;
- message->header = gb_buffer_alloc(hd, size, gfp_flags);
- if (!message->header)
- return -ENOMEM;
- message->size = size;
+ header = gb_buffer_alloc(hd, size, gfp_flags);
+ if (!header) {
+ kfree(message);
+ return NULL;
+ }
/* Fill in the header structure */
- header = message->header;
header->size = cpu_to_le16(size);
header->operation_id = 0; /* Filled in when submitted */
header->type = type;
+ message->header = header;
message->payload = header + 1;
- message->operation = operation;
+ message->size = size;
- return 0;
+ return message;
}
-static void gb_operation_message_exit(struct gb_message *message)
+static void gb_operation_message_free(struct gb_message *message)
{
struct greybus_host_device *hd;
hd = message->operation->connection->hd;
gb_buffer_free(hd, message->header);
-
- message->operation = NULL;
- message->payload = NULL;
- message->header = NULL;
- message->size = 0;
+ kfree(message);
}
/*
u8 type, size_t request_size,
size_t response_size)
{
+ struct greybus_host_device *hd = connection->hd;
struct gb_operation *operation;
gfp_t gfp_flags = response_size ? GFP_KERNEL : GFP_ATOMIC;
- int ret;
operation = kmem_cache_zalloc(gb_operation_cache, gfp_flags);
if (!operation)
return NULL;
operation->connection = connection;
- ret = gb_operation_message_init(operation, type, request_size,
- true, gfp_flags);
- if (ret)
+ operation->request = gb_operation_message_alloc(hd, type, request_size,
+ gfp_flags);
+ if (!operation->request)
goto err_cache;
+ operation->request->operation = operation;
if (outgoing) {
- ret = gb_operation_message_init(operation, type, response_size,
- false, GFP_KERNEL);
- if (ret)
+ type |= GB_OPERATION_TYPE_RESPONSE;
+ operation->response = gb_operation_message_alloc(hd, type,
+ response_size, GFP_KERNEL);
+ if (!operation->response)
goto err_request;
+ operation->response->operation = operation;
}
INIT_WORK(&operation->recv_work, gb_operation_recv_work);
return operation;
err_request:
- gb_operation_message_exit(&operation->request);
+ gb_operation_message_free(operation->request);
err_cache:
kmem_cache_free(gb_operation_cache, operation);
list_del(&operation->links);
spin_unlock_irq(&gb_operations_lock);
- gb_operation_message_exit(&operation->response);
- gb_operation_message_exit(&operation->request);
+ gb_operation_message_free(operation->response);
+ gb_operation_message_free(operation->request);
kmem_cache_free(gb_operation_cache, operation);
}
schedule_delayed_work(&operation->timeout_work, timeout);
/* All set, send the request */
- ret = gb_message_send(&operation->request, GFP_KERNEL);
+ ret = gb_message_send(operation->request, GFP_KERNEL);
if (ret)
return ret;
return; /* XXX Respond with pre-allocated ENOMEM */
}
operation->id = operation_id;
- memcpy(operation->request.header, data, size);
+ memcpy(operation->request->header, data, size);
/* The rest will be handled in work queue context */
queue_work(gb_operation_recv_workqueue, &operation->recv_work);
cancel_delayed_work(&operation->timeout_work);
gb_pending_operation_remove(operation);
- message = &operation->response;
+ message = operation->response;
if (size <= message->size) {
/* Transfer the operation result from the response header */
header = message->header;
void gb_operation_cancel(struct gb_operation *operation)
{
operation->canceled = true;
- gb_message_cancel(&operation->request);
- if (operation->response.header)
- gb_message_cancel(&operation->response);
+ gb_message_cancel(operation->request);
+ if (operation->response->header)
+ gb_message_cancel(operation->response);
}
int gb_operation_init(void)
typedef void (*gb_operation_callback)(struct gb_operation *);
struct gb_operation {
struct gb_connection *connection;
- struct gb_message request;
- struct gb_message response;
+ struct gb_message *request;
+ struct gb_message *response;
u16 id;
bool canceled;
gb_connection_err(connection, "version result %hhu",
operation->result);
} else {
- response = operation->response.payload;
+ response = operation->response->payload;
if (response->major > GB_PWM_VERSION_MAJOR) {
pr_err("unsupported major version (%hhu > %hhu)\n",
response->major, GB_PWM_VERSION_MAJOR);
gb_connection_err(connection, "pwm count result %hhu",
operation->result);
} else {
- response = operation->response.payload;
+ response = operation->response->payload;
pwmc->pwm_max = response->count;
}
out:
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
/* Synchronous operation--no callback */
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
/* Synchronous operation--no callback */
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
request->duty = duty;
request->period = period;
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
request->polarity = polarity;
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
/* Synchronous operation--no callback */
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->which = which;
/* Synchronous operation--no callback */
gb_connection_err(tty->connection, "result %hhu",
operation->result);
} else {
- response = operation->response.payload;
+ response = operation->response->payload;
if (response->major > GB_UART_VERSION_MAJOR) {
pr_err("unsupported major version (%hhu > %hhu)\n",
response->major, GB_UART_VERSION_MAJOR);
sizeof(*request) + size, 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->size = cpu_to_le16(size);
memcpy(&request->data[0], data, size);
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
memcpy(&request->line_coding, line_coding, sizeof(*line_coding));
/* Synchronous operation--no callback */
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->control = cpu_to_le16(control);
/* Synchronous operation--no callback */
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->state = state;
/* Synchronous operation--no callback */
} else {
/* Good request, so copy to the caller's buffer */
if (response_size && response)
- memcpy(response, operation->response.payload,
+ memcpy(response, operation->response->payload,
response_size);
}
out:
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
- request = operation->request.payload;
+ request = operation->request->payload;
request->timeout_ms = cpu_to_le16(timeout_ms);
/* Synchronous operation--no callback */