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

greybus: remove status from all responses

This is a pervasive change, but not really a big one.  However:

        ==============  Pay attention to this ==============
	If you're doing any testing with "gbsim" you need to
	update that program in sync with this change, because
	it changes the protocol used between them.
        ==============  Pay attention to this ==============

The status of a request is now recorded in the header of a response
message.  The previous patch put that header status byte in place,
and this one removes the status byte from all the response
messages.

And finally, since we're modifying all these files anyway...
Use gb_operation_status_map() to come up with a return code
to use, given an operation response.  Right now most errors
simply result in -EIO getting returned.
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent bc717fcb
......@@ -40,7 +40,6 @@ struct gb_battery {
#define GB_BATTERY_TYPE_VOLTAGE 0x07
struct gb_battery_proto_version_response {
__u8 status;
__u8 major;
__u8 minor;
};
......@@ -55,7 +54,6 @@ struct gb_battery_proto_version_response {
#define GB_BATTERY_TECH_LiMn 0x0006
struct gb_battery_technology_response {
__u8 status;
__le32 technology;
};
......@@ -67,35 +65,25 @@ struct gb_battery_technology_response {
#define GB_BATTERY_STATUS_FULL 0x0004
struct gb_battery_status_response {
__u8 status;
__le16 battery_status;
};
struct gb_battery_max_voltage_response {
__u8 status;
__le32 max_voltage;
};
struct gb_battery_capacity_response {
__u8 status;
__le32 capacity;
};
struct gb_battery_temperature_response {
__u8 status;
__le32 temperature;
};
struct gb_battery_voltage_response {
__u8 status;
__le32 voltage;
};
/* Generia response structure--prefix for all other responses */
struct gb_generic_battery_response {
__u8 status;
};
/*
* None of the battery operation requests have any payload. This
* function implements all of the requests by allowing the caller to
......@@ -107,7 +95,6 @@ static int battery_operation(struct gb_battery *gb, int type,
{
struct gb_connection *connection = gb->connection;
struct gb_operation *operation;
struct gb_generic_battery_response *fake_response;
int ret;
operation = gb_operation_create(connection, type, 0, response_size);
......@@ -126,14 +113,13 @@ static int battery_operation(struct gb_battery *gb, int type,
* layout for where the status is, so cast this to a random request so
* we can see the status easier.
*/
fake_response = operation->response.payload;
if (fake_response->status) {
gb_connection_err(connection, "version response %hhu",
fake_response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "operation result %hhu",
operation->result);
} else {
/* Good response, so copy to the caller's buffer */
memcpy(response, fake_response, response_size);
memcpy(response, operation->response.payload, response_size);
}
out:
gb_operation_destroy(operation);
......
This diff is collapsed.
......@@ -43,30 +43,24 @@ struct gb_i2c_device {
/* version request has no payload */
struct gb_i2c_proto_version_response {
__u8 status;
__u8 major;
__u8 minor;
};
/* functionality request has no payload */
struct gb_i2c_functionality_response {
__u8 status;
__le32 functionality;
};
struct gb_i2c_timeout_request {
__le16 msec;
};
struct gb_i2c_timeout_response {
__u8 status;
};
/* timeout response has no payload */
struct gb_i2c_retries_request {
__u8 retries;
};
struct gb_i2c_retries_response {
__u8 status;
};
/* retries response has no payload */
/*
* Outgoing data immediately follows the op count and ops array.
......@@ -89,7 +83,6 @@ struct gb_i2c_transfer_request {
struct gb_i2c_transfer_op ops[0]; /* op_count of these */
};
struct gb_i2c_transfer_response {
__u8 status;
__u8 data[0]; /* inbound data */
};
......@@ -118,12 +111,12 @@ static int gb_i2c_proto_version_operation(struct gb_i2c_device *gb_i2c_dev)
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "version response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "version result %hhu",
operation->result);
} else {
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);
......@@ -170,12 +163,12 @@ static int gb_i2c_functionality_operation(struct gb_i2c_device *gb_i2c_dev)
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "functionality response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "functionality result %hhu",
operation->result);
} else {
response = operation->response.payload;
functionality = le32_to_cpu(response->functionality);
gb_i2c_dev->functionality =
gb_i2c_functionality_map(functionality);
......@@ -191,11 +184,10 @@ static int gb_i2c_timeout_operation(struct gb_i2c_device *gb_i2c_dev, u16 msec)
struct gb_connection *connection = gb_i2c_dev->connection;
struct gb_operation *operation;
struct gb_i2c_timeout_request *request;
struct gb_i2c_timeout_response *response;
int ret;
operation = gb_operation_create(connection, GB_I2C_TYPE_TIMEOUT,
sizeof(*request), sizeof(*response));
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
request = operation->request.payload;
......@@ -208,11 +200,10 @@ static int gb_i2c_timeout_operation(struct gb_i2c_device *gb_i2c_dev, u16 msec)
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "timeout response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "timeout result %hhu",
operation->result);
} else {
gb_i2c_dev->timeout_msec = msec;
}
......@@ -228,11 +219,10 @@ static int gb_i2c_retries_operation(struct gb_i2c_device *gb_i2c_dev,
struct gb_connection *connection = gb_i2c_dev->connection;
struct gb_operation *operation;
struct gb_i2c_retries_request *request;
struct gb_i2c_retries_response *response;
int ret;
operation = gb_operation_create(connection, GB_I2C_TYPE_RETRIES,
sizeof(*request), sizeof(*response));
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
request = operation->request.payload;
......@@ -245,11 +235,10 @@ static int gb_i2c_retries_operation(struct gb_i2c_device *gb_i2c_dev,
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "retries response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "retries result %hhu",
operation->result);
} else {
gb_i2c_dev->retries = retries;
}
......@@ -380,16 +369,14 @@ static int gb_i2c_transfer_operation(struct gb_i2c_device *gb_i2c_dev,
goto out;
}
response = operation->response.payload;
if (response->status) {
if (response->status == GB_OP_RETRY) {
ret = -EAGAIN;
} else {
gb_connection_err(connection, "transfer response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
if (ret != -EAGAIN) {
gb_connection_err(connection, "transfer result %hhu",
operation->result);
}
} else {
response = operation->response.payload;
gb_i2c_transfer_response(msgs, msg_count, response->data);
ret = msg_count;
}
......
......@@ -525,10 +525,11 @@ static void gb_connection_recv_response(struct gb_connection *connection,
return; /* XXX Should still complete operation */
}
/* Hack the status from the buffer into the header */
/* The status in the response is the result of the operation */
header = message->buffer;
header->result = *(char *)message->payload; /* Eeew. */
operation->result = header->result;
/* We must ignore the payload if a bad status is returned */
if (operation->result == GB_OP_SUCCESS)
memcpy(message->buffer, data, size);
......
......@@ -41,20 +41,14 @@ struct gb_pwm_chip {
#define GB_PWM_TYPE_DISABLE 0x08
#define GB_PWM_TYPE_RESPONSE 0x80 /* OR'd with rest */
struct gb_pwm_simple_response {
__u8 status;
};
/* version request has no payload */
struct gb_pwm_proto_version_response {
__u8 status;
__u8 major;
__u8 minor;
};
/* pwm count request has no payload */
struct gb_pwm_count_response {
__u8 status;
__u8 count;
};
......@@ -110,12 +104,12 @@ static int gb_pwm_proto_version_operation(struct gb_pwm_chip *pwmc)
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "version response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "version result %hhu",
operation->result);
} else {
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);
......@@ -151,12 +145,12 @@ static int gb_pwm_count_operation(struct gb_pwm_chip *pwmc)
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "pwm count response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "pwm count result %hhu",
operation->result);
} else
response = operation->response.payload;
pwmc->pwm_max = response->count;
out:
gb_operation_destroy(operation);
......@@ -170,7 +164,6 @@ static int gb_pwm_activate_operation(struct gb_pwm_chip *pwmc,
struct gb_connection *connection = pwmc->connection;
struct gb_operation *operation;
struct gb_pwm_activate_request *request;
struct gb_pwm_simple_response *response;
int ret;
if (which > pwmc->pwm_max)
......@@ -178,7 +171,7 @@ static int gb_pwm_activate_operation(struct gb_pwm_chip *pwmc,
/* activate response has no payload */
operation = gb_operation_create(connection, GB_PWM_TYPE_ACTIVATE,
sizeof(*request), sizeof(*response));
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
request = operation->request.payload;
......@@ -191,11 +184,10 @@ static int gb_pwm_activate_operation(struct gb_pwm_chip *pwmc,
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "activate response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "activate result %hhu",
operation->result);
}
out:
gb_operation_destroy(operation);
......@@ -209,7 +201,6 @@ static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc,
struct gb_connection *connection = pwmc->connection;
struct gb_operation *operation;
struct gb_pwm_deactivate_request *request;
struct gb_pwm_simple_response *response;
int ret;
if (which > pwmc->pwm_max)
......@@ -217,7 +208,7 @@ static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc,
/* deactivate response has no payload */
operation = gb_operation_create(connection, GB_PWM_TYPE_DEACTIVATE,
sizeof(*request), sizeof(*response));
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
request = operation->request.payload;
......@@ -230,11 +221,10 @@ static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc,
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "deactivate response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "deactivate result %hhu",
operation->result);
}
out:
gb_operation_destroy(operation);
......@@ -248,14 +238,13 @@ static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc,
struct gb_connection *connection = pwmc->connection;
struct gb_operation *operation;
struct gb_pwm_config_request *request;
struct gb_pwm_simple_response *response;
int ret;
if (which > pwmc->pwm_max)
return -EINVAL;
operation = gb_operation_create(connection, GB_PWM_TYPE_CONFIG,
sizeof(*request), sizeof(*response));
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
request = operation->request.payload;
......@@ -270,11 +259,10 @@ static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc,
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "config response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "config result %hhu",
operation->result);
}
out:
gb_operation_destroy(operation);
......@@ -289,14 +277,13 @@ static int gb_pwm_set_polarity_operation(struct gb_pwm_chip *pwmc,
struct gb_connection *connection = pwmc->connection;
struct gb_operation *operation;
struct gb_pwm_polarity_request *request;
struct gb_pwm_simple_response *response;
int ret;
if (which > pwmc->pwm_max)
return -EINVAL;
operation = gb_operation_create(connection, GB_PWM_TYPE_POLARITY,
sizeof(*request), sizeof(*response));
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
request = operation->request.payload;
......@@ -310,11 +297,10 @@ static int gb_pwm_set_polarity_operation(struct gb_pwm_chip *pwmc,
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "set polarity response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "set polarity result %hhu",
operation->result);
}
out:
gb_operation_destroy(operation);
......@@ -328,7 +314,6 @@ static int gb_pwm_enable_operation(struct gb_pwm_chip *pwmc,
struct gb_connection *connection = pwmc->connection;
struct gb_operation *operation;
struct gb_pwm_enable_request *request;
struct gb_pwm_simple_response *response;
int ret;
if (which > pwmc->pwm_max)
......@@ -336,7 +321,7 @@ static int gb_pwm_enable_operation(struct gb_pwm_chip *pwmc,
/* enable response has no payload */
operation = gb_operation_create(connection, GB_PWM_TYPE_ENABLE,
sizeof(*request), sizeof(*response));
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
request = operation->request.payload;
......@@ -349,11 +334,10 @@ static int gb_pwm_enable_operation(struct gb_pwm_chip *pwmc,
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "enable response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "enable result %hhu",
operation->result);
}
out:
gb_operation_destroy(operation);
......@@ -367,7 +351,6 @@ static int gb_pwm_disable_operation(struct gb_pwm_chip *pwmc,
struct gb_connection *connection = pwmc->connection;
struct gb_operation *operation;
struct gb_pwm_disable_request *request;
struct gb_pwm_simple_response *response;
int ret;
if (which > pwmc->pwm_max)
......@@ -375,7 +358,7 @@ static int gb_pwm_disable_operation(struct gb_pwm_chip *pwmc,
/* disable response has no payload */
operation = gb_operation_create(connection, GB_PWM_TYPE_DISABLE,
sizeof(*request), sizeof(*response));
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
request = operation->request.payload;
......@@ -388,11 +371,10 @@ static int gb_pwm_disable_operation(struct gb_pwm_chip *pwmc,
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "disable response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "disable result %hhu",
operation->result);
}
out:
gb_operation_destroy(operation);
......
......@@ -49,7 +49,6 @@
#define GB_UART_TYPE_RESPONSE 0x80 /* OR'd with rest */
struct gb_uart_proto_version_response {
__u8 status;
__u8 major;
__u8 minor;
};
......@@ -106,10 +105,6 @@ struct gb_uart_serial_state_request {
__u16 control;
};
struct gb_uart_simple_response {
__u8 status;
};
struct gb_tty {
struct tty_port port;
struct gb_connection *connection;
......@@ -159,11 +154,10 @@ static int get_version(struct gb_tty *tty)
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(tty->connection, "response %hhu",
response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(tty->connection, "result %hhu",
operation->result);
} else {
if (response->major > GB_UART_VERSION_MAJOR) {
pr_err("unsupported major version (%hhu > %hhu)\n",
......@@ -188,15 +182,13 @@ static int send_data(struct gb_tty *tty, u16 size, const u8 *data)
struct gb_connection *connection = tty->connection;
struct gb_operation *operation;
struct gb_uart_send_data_request *request;
struct gb_uart_simple_response *response;
int retval;
if (!data || !size)
return 0;
operation = gb_operation_create(connection, GB_UART_REQ_SEND_DATA,
sizeof(*request) + size,
sizeof(*response));
sizeof(*request) + size, 0);
if (!operation)
return -ENOMEM;
request = operation->request.payload;
......@@ -211,11 +203,10 @@ static int send_data(struct gb_tty *tty, u16 size, const u8 *data)
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "send data response %hhu",
response->status);
retval = -EIO;
if (operation->result) {
retval = gb_operation_status_map(operation->result);
gb_connection_err(connection, "send data result %hhu",
operation->result);
}
out:
gb_operation_destroy(operation);
......@@ -229,12 +220,10 @@ static int send_line_coding(struct gb_tty *tty,
struct gb_connection *connection = tty->connection;
struct gb_operation *operation;
struct gb_uart_set_line_coding_request *request;
struct gb_uart_simple_response *response;
int retval;
operation = gb_operation_create(connection, GB_UART_REQ_SET_LINE_CODING,
sizeof(*request),
sizeof(*response));
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
request = operation->request.payload;
......@@ -248,11 +237,10 @@ static int send_line_coding(struct gb_tty *tty,
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "send line coding response %hhu",
response->status);
retval = -EIO;
if (operation->result) {
retval = gb_operation_status_map(operation->result);
gb_connection_err(connection, "send line coding result %hhu",
operation->result);
}
out:
gb_operation_destroy(operation);
......@@ -265,13 +253,11 @@ static int send_control(struct gb_tty *tty, u16 control)
struct gb_connection *connection = tty->connection;
struct gb_operation *operation;
struct gb_uart_set_control_line_state_request *request;
struct gb_uart_simple_response *response;
int retval;
operation = gb_operation_create(connection,
GB_UART_REQ_SET_CONTROL_LINE_STATE,
sizeof(*request),
sizeof(*response));
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
request = operation->request.payload;
......@@ -285,11 +271,10 @@ static int send_control(struct gb_tty *tty, u16 control)
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "send control response %hhu",
response->status);
retval = -EIO;
if (operation->result) {
retval = gb_operation_status_map(operation->result);
gb_connection_err(connection, "send control result %hhu",
operation->result);
}
out:
gb_operation_destroy(operation);
......@@ -302,7 +287,6 @@ static int send_break(struct gb_tty *tty, u8 state)
struct gb_connection *connection = tty->connection;
struct gb_operation *operation;
struct gb_uart_set_break_request *request;
struct gb_uart_simple_response *response;
int retval;
if ((state != 0) && (state != 1)) {
......@@ -311,8 +295,7 @@ static int send_break(struct gb_tty *tty, u8 state)
}
operation = gb_operation_create(connection, GB_UART_REQ_SET_BREAK,
sizeof(*request),
sizeof(*response));
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
request = operation->request.payload;
......@@ -326,11 +309,10 @@ static int send_break(struct gb_tty *tty, u8 state)
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "send break response %hhu",
response->status);
retval = -EIO;
if (operation->result) {
retval = gb_operation_status_map(operation->result);
gb_connection_err(connection, "send break result %hhu",
operation->result);
}
out:
gb_operation_destroy(operation);
......
......@@ -34,7 +34,6 @@ struct gb_vibrator_device {
#define GB_VIBRATOR_TYPE_RESPONSE 0x80 /* OR'd with rest */
struct gb_vibrator_proto_version_response {
__u8 status;
__u8 major;
__u8 minor;
};
......@@ -43,15 +42,10 @@ struct gb_vibrator_on_request {
__le16 timeout_ms;
};
struct gb_vibrator_simple_response {
__u8 status;
};
static int request_operation(struct gb_connection *connection, int type,
void *response, int response_size)
{
struct gb_operation *operation;
struct gb_vibrator_simple_response *fake_response;
int ret;
operation = gb_operation_create(connection, type, 0, response_size);
......@@ -70,15 +64,15 @@ static int request_operation(struct gb_connection *connection, int type,
* layout for where the status is, so cast this to a random request so
* we can see the status easier.
*/
fake_response = operation->response.payload;
if (fake_response->status) {
gb_connection_err(connection, "response %hhu",
fake_response->status);
ret = -EIO;
if (operation->result) {
ret = gb_operation_status_map(operation->result);
gb_connection_err(connection, "operation result %hhu",
operation->result);
} else {
/* Good request, so copy to the caller's buffer */
if (response_size && response)
memcpy(response, fake_response, response_size);
memcpy(response, operation->response.payload,
response_size);
}
out:
gb_operation_destroy(operation);
......@@ -119,11 +113,10 @@ static int turn_on(struct gb_vibrator_device *vib, u16 timeout_ms)
struct gb_connection *connection = vib->connection;
struct gb_operation *operation;
struct gb_vibrator_on_request *request;
struct gb_vibrator_simple_response *response;
int retval;
operation = gb_operation_create(connection, GB_VIBRATOR_TYPE_ON,
sizeof(*request), sizeof(*response));
sizeof(*request), 0);
if (!operation)
return -ENOMEM;
request = operation->request.payload;
......@@ -137,11 +130,10 @@ static int turn_on(struct gb_vibrator_device *vib, u16 timeout_ms)
goto out;
}
response = operation->response.payload;
if (response->status) {
gb_connection_err(connection, "send data response %hhu",
response->status);
retval = -EIO;
if (operation->result) {
retval = gb_operation_status_map(operation->result);
gb_connection_err(connection, "send data result %hhu",
operation->result);
}
out:
gb_operation_destroy(operation);
......
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