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