mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-26 05:55:06 +07:00
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: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This commit is contained in:
parent
bc717fcbf6
commit
25d0f81a0e
@ -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);
|
||||
|
@ -55,14 +55,12 @@ struct gb_gpio_controller {
|
||||
|
||||
/* version request has no payload */
|
||||
struct gb_gpio_proto_version_response {
|
||||
__u8 status;
|
||||
__u8 major;
|
||||
__u8 minor;
|
||||
};
|
||||
|
||||
/* line count request has no payload */
|
||||
struct gb_gpio_line_count_response {
|
||||
__u8 status;
|
||||
__u8 count;
|
||||
};
|
||||
|
||||
@ -70,44 +68,35 @@ struct gb_gpio_activate_request {
|
||||
__u8 which;
|
||||
};
|
||||
struct gb_gpio_activate_response {
|
||||
__u8 status;
|
||||
};
|
||||
|
||||
struct gb_gpio_deactivate_request {
|
||||
__u8 which;
|
||||
};
|
||||
struct gb_gpio_deactivate_response {
|
||||
__u8 status;
|
||||
};
|
||||
/* deactivate response has no payload */
|
||||
|
||||
struct gb_gpio_get_direction_request {
|
||||
__u8 which;
|
||||
};
|
||||
struct gb_gpio_get_direction_response {
|
||||
__u8 status;
|
||||
__u8 direction;
|
||||
};
|
||||
|
||||
struct gb_gpio_direction_in_request {
|
||||
__u8 which;
|
||||
};
|
||||
struct gb_gpio_direction_in_response {
|
||||
__u8 status;
|
||||
};
|
||||
/* direction in response has no payload */
|
||||
|
||||
struct gb_gpio_direction_out_request {
|
||||
__u8 which;
|
||||
__u8 value;
|
||||
};
|
||||
struct gb_gpio_direction_out_response {
|
||||
__u8 status;
|
||||
};
|
||||
/* direction out response has no payload */
|
||||
|
||||
struct gb_gpio_get_value_request {
|
||||
__u8 which;
|
||||
};
|
||||
struct gb_gpio_get_value_response {
|
||||
__u8 status;
|
||||
__u8 value;
|
||||
};
|
||||
|
||||
@ -115,17 +104,13 @@ struct gb_gpio_set_value_request {
|
||||
__u8 which;
|
||||
__u8 value;
|
||||
};
|
||||
struct gb_gpio_set_value_response {
|
||||
__u8 status;
|
||||
};
|
||||
/* set value response has no payload */
|
||||
|
||||
struct gb_gpio_set_debounce_request {
|
||||
__u8 which;
|
||||
__le16 usec;
|
||||
};
|
||||
struct gb_gpio_set_debounce_response {
|
||||
__u8 status;
|
||||
};
|
||||
/* debounce response has no payload */
|
||||
|
||||
|
||||
/*
|
||||
@ -153,12 +138,12 @@ static int gb_gpio_proto_version_operation(struct gb_gpio_controller *gb_gpio_co
|
||||
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_GPIO_VERSION_MAJOR) {
|
||||
pr_err("unsupported major version (%hhu > %hhu)\n",
|
||||
response->major, GB_GPIO_VERSION_MAJOR);
|
||||
@ -199,12 +184,12 @@ static int gb_gpio_line_count_operation(struct gb_gpio_controller *gb_gpio_contr
|
||||
goto out;
|
||||
}
|
||||
|
||||
response = operation->response.payload;
|
||||
if (response->status) {
|
||||
gb_connection_err(connection, "line count response %hhu",
|
||||
response->status);
|
||||
ret = -EIO;
|
||||
if (operation->result) {
|
||||
ret = gb_operation_status_map(operation->result);
|
||||
gb_connection_err(connection, "line count result %hhu",
|
||||
operation->result);
|
||||
} else {
|
||||
response = operation->response.payload;
|
||||
gb_gpio_controller->line_max = response->count;
|
||||
|
||||
pr_debug("%s: count = %u\n", __func__,
|
||||
@ -222,7 +207,6 @@ static int gb_gpio_activate_operation(struct gb_gpio_controller *gb_gpio_control
|
||||
struct gb_connection *connection = gb_gpio_controller->connection;
|
||||
struct gb_operation *operation;
|
||||
struct gb_gpio_activate_request *request;
|
||||
struct gb_gpio_activate_response *response;
|
||||
int ret;
|
||||
|
||||
if (which > gb_gpio_controller->line_max)
|
||||
@ -231,7 +215,7 @@ static int gb_gpio_activate_operation(struct gb_gpio_controller *gb_gpio_control
|
||||
/* activate response has no payload */
|
||||
operation = gb_operation_create(connection,
|
||||
GB_GPIO_TYPE_ACTIVATE,
|
||||
sizeof(*request), sizeof(*response));
|
||||
sizeof(*request), 0);
|
||||
if (!operation)
|
||||
return -ENOMEM;
|
||||
request = operation->request.payload;
|
||||
@ -244,11 +228,10 @@ static int gb_gpio_activate_operation(struct gb_gpio_controller *gb_gpio_control
|
||||
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);
|
||||
} else {
|
||||
gb_gpio_controller->lines[which].active = true;
|
||||
|
||||
@ -266,7 +249,6 @@ static int gb_gpio_deactivate_operation(struct gb_gpio_controller *gb_gpio_contr
|
||||
struct gb_connection *connection = gb_gpio_controller->connection;
|
||||
struct gb_operation *operation;
|
||||
struct gb_gpio_deactivate_request *request;
|
||||
struct gb_gpio_deactivate_response *response;
|
||||
int ret;
|
||||
|
||||
if (which > gb_gpio_controller->line_max)
|
||||
@ -275,7 +257,7 @@ static int gb_gpio_deactivate_operation(struct gb_gpio_controller *gb_gpio_contr
|
||||
/* deactivate response has no payload */
|
||||
operation = gb_operation_create(connection,
|
||||
GB_GPIO_TYPE_DEACTIVATE,
|
||||
sizeof(*request), sizeof(*response));
|
||||
sizeof(*request), 0);
|
||||
if (!operation)
|
||||
return -ENOMEM;
|
||||
request = operation->request.payload;
|
||||
@ -288,11 +270,10 @@ static int gb_gpio_deactivate_operation(struct gb_gpio_controller *gb_gpio_contr
|
||||
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);
|
||||
} else {
|
||||
gb_gpio_controller->lines[which].active = false;
|
||||
pr_debug("%s: %u is now inactive\n", __func__, which);
|
||||
@ -330,14 +311,15 @@ static int gb_gpio_get_direction_operation(struct gb_gpio_controller *gb_gpio_co
|
||||
goto out;
|
||||
}
|
||||
|
||||
response = operation->response.payload;
|
||||
if (response->status) {
|
||||
gb_connection_err(connection, "get direction response %hhu",
|
||||
response->status);
|
||||
ret = -EIO;
|
||||
if (operation->result) {
|
||||
ret = gb_operation_status_map(operation->result);
|
||||
gb_connection_err(connection, "get direction result %hhu",
|
||||
operation->result);
|
||||
} else {
|
||||
u8 direction = response->direction;
|
||||
u8 direction;
|
||||
|
||||
response = operation->response.payload;
|
||||
direction = response->direction;
|
||||
if (direction && direction != 1)
|
||||
pr_warn("gpio %u direction was %u (should be 0 or 1)\n",
|
||||
which, direction);
|
||||
@ -357,7 +339,6 @@ static int gb_gpio_direction_in_operation(struct gb_gpio_controller *gb_gpio_con
|
||||
struct gb_connection *connection = gb_gpio_controller->connection;
|
||||
struct gb_operation *operation;
|
||||
struct gb_gpio_direction_in_request *request;
|
||||
struct gb_gpio_direction_in_response *response;
|
||||
int ret;
|
||||
|
||||
if (which > gb_gpio_controller->line_max)
|
||||
@ -366,7 +347,7 @@ static int gb_gpio_direction_in_operation(struct gb_gpio_controller *gb_gpio_con
|
||||
/* direction_in response has no payload */
|
||||
operation = gb_operation_create(connection,
|
||||
GB_GPIO_TYPE_DIRECTION_IN,
|
||||
sizeof(*request), sizeof(*response));
|
||||
sizeof(*request), 0);
|
||||
if (!operation)
|
||||
return -ENOMEM;
|
||||
request = operation->request.payload;
|
||||
@ -379,11 +360,10 @@ static int gb_gpio_direction_in_operation(struct gb_gpio_controller *gb_gpio_con
|
||||
goto out;
|
||||
}
|
||||
|
||||
response = operation->response.payload;
|
||||
if (response->status) {
|
||||
gb_connection_err(connection, "direction in response %hhu",
|
||||
response->status);
|
||||
ret = -EIO;
|
||||
if (operation->result) {
|
||||
ret = gb_operation_status_map(operation->result);
|
||||
gb_connection_err(connection, "direction in result %hhu",
|
||||
operation->result);
|
||||
} else {
|
||||
gb_gpio_controller->lines[which].direction = 1;
|
||||
pr_debug("%s: direction of %u is now in\n", __func__, which);
|
||||
@ -400,7 +380,6 @@ static int gb_gpio_direction_out_operation(struct gb_gpio_controller *gb_gpio_co
|
||||
struct gb_connection *connection = gb_gpio_controller->connection;
|
||||
struct gb_operation *operation;
|
||||
struct gb_gpio_direction_out_request *request;
|
||||
struct gb_gpio_direction_out_response *response;
|
||||
int ret;
|
||||
|
||||
if (which > gb_gpio_controller->line_max)
|
||||
@ -409,7 +388,7 @@ static int gb_gpio_direction_out_operation(struct gb_gpio_controller *gb_gpio_co
|
||||
/* direction_out response has no payload */
|
||||
operation = gb_operation_create(connection,
|
||||
GB_GPIO_TYPE_DIRECTION_OUT,
|
||||
sizeof(*request), sizeof(*response));
|
||||
sizeof(*request), 0);
|
||||
if (!operation)
|
||||
return -ENOMEM;
|
||||
request = operation->request.payload;
|
||||
@ -423,11 +402,10 @@ static int gb_gpio_direction_out_operation(struct gb_gpio_controller *gb_gpio_co
|
||||
goto out;
|
||||
}
|
||||
|
||||
response = operation->response.payload;
|
||||
if (response->status) {
|
||||
gb_connection_err(connection, "direction out response %hhu",
|
||||
response->status);
|
||||
ret = -EIO;
|
||||
if (operation->result) {
|
||||
ret = gb_operation_status_map(operation->result);
|
||||
gb_connection_err(connection, "direction out result %hhu",
|
||||
operation->result);
|
||||
} else {
|
||||
gb_gpio_controller->lines[which].direction = 0;
|
||||
pr_debug("%s: direction of %u is now out, value %s\n", __func__,
|
||||
@ -466,14 +444,15 @@ static int gb_gpio_get_value_operation(struct gb_gpio_controller *gb_gpio_contro
|
||||
goto out;
|
||||
}
|
||||
|
||||
response = operation->response.payload;
|
||||
if (response->status) {
|
||||
gb_connection_err(connection, "get value response %hhu",
|
||||
response->status);
|
||||
ret = -EIO;
|
||||
if (operation->result) {
|
||||
ret = gb_operation_status_map(operation->result);
|
||||
gb_connection_err(connection, "get value result %hhu",
|
||||
operation->result);
|
||||
} else {
|
||||
u8 value = response->value;
|
||||
u8 value;
|
||||
|
||||
response = operation->response.payload;
|
||||
value = response->value;
|
||||
if (value && value != 1)
|
||||
pr_warn("gpio %u value was %u (should be 0 or 1)\n",
|
||||
which, value);
|
||||
@ -495,7 +474,6 @@ static int gb_gpio_set_value_operation(struct gb_gpio_controller *gb_gpio_contro
|
||||
struct gb_connection *connection = gb_gpio_controller->connection;
|
||||
struct gb_operation *operation;
|
||||
struct gb_gpio_set_value_request *request;
|
||||
struct gb_gpio_set_value_response *response;
|
||||
int ret;
|
||||
|
||||
if (which > gb_gpio_controller->line_max)
|
||||
@ -504,7 +482,7 @@ static int gb_gpio_set_value_operation(struct gb_gpio_controller *gb_gpio_contro
|
||||
/* set_value response has no payload */
|
||||
operation = gb_operation_create(connection,
|
||||
GB_GPIO_TYPE_SET_VALUE,
|
||||
sizeof(*request), sizeof(*response));
|
||||
sizeof(*request), 0);
|
||||
if (!operation)
|
||||
return -ENOMEM;
|
||||
request = operation->request.payload;
|
||||
@ -518,11 +496,10 @@ static int gb_gpio_set_value_operation(struct gb_gpio_controller *gb_gpio_contro
|
||||
goto out;
|
||||
}
|
||||
|
||||
response = operation->response.payload;
|
||||
if (response->status) {
|
||||
gb_connection_err(connection, "set value response %hhu",
|
||||
response->status);
|
||||
ret = -EIO;
|
||||
if (operation->result) {
|
||||
ret = gb_operation_status_map(operation->result);
|
||||
gb_connection_err(connection, "set value result %hhu",
|
||||
operation->result);
|
||||
} else {
|
||||
/* XXX should this set direction to out? */
|
||||
gb_gpio_controller->lines[which].value = request->value;
|
||||
@ -542,7 +519,6 @@ static int gb_gpio_set_debounce_operation(struct gb_gpio_controller *gb_gpio_con
|
||||
struct gb_connection *connection = gb_gpio_controller->connection;
|
||||
struct gb_operation *operation;
|
||||
struct gb_gpio_set_debounce_request *request;
|
||||
struct gb_gpio_set_debounce_response *response;
|
||||
int ret;
|
||||
|
||||
if (which > gb_gpio_controller->line_max)
|
||||
@ -551,7 +527,7 @@ static int gb_gpio_set_debounce_operation(struct gb_gpio_controller *gb_gpio_con
|
||||
/* set_debounce response has no payload */
|
||||
operation = gb_operation_create(connection,
|
||||
GB_GPIO_TYPE_SET_DEBOUNCE,
|
||||
sizeof(*request), sizeof(*response));
|
||||
sizeof(*request), 0);
|
||||
if (!operation)
|
||||
return -ENOMEM;
|
||||
request = operation->request.payload;
|
||||
@ -565,11 +541,10 @@ static int gb_gpio_set_debounce_operation(struct gb_gpio_controller *gb_gpio_con
|
||||
goto out;
|
||||
}
|
||||
|
||||
response = operation->response.payload;
|
||||
if (response->status) {
|
||||
gb_connection_err(connection, "set debounce response %hhu",
|
||||
response->status);
|
||||
ret = -EIO;
|
||||
if (operation->result) {
|
||||
ret = gb_operation_status_map(operation->result);
|
||||
gb_connection_err(connection, "set debounce result %hhu",
|
||||
operation->result);
|
||||
} else {
|
||||
gb_gpio_controller->lines[which].debounce_usec = le16_to_cpu(request->usec);
|
||||
pr_debug("%s: debounce of %u is now %hu usec\n", __func__, which,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user