Commit cfb16906 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

greybus: greybus_protocols: add missing version-request definition

Add the missing version-request definition that was falsely claimed to
be empty.

Update the generic version-request helper and SVC version-request
handler to use the request definition rather than rely on the response
happening to have the same layout, something which also improves
readability.

Remove a misplaced "Control Protocol" header while at it.
Signed-off-by: default avatarJohan Hovold <johan@hovoldconsulting.com>
Reviewed-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 59832931
......@@ -103,9 +103,11 @@ struct gb_operation_msg_hdr {
#define GB_REQUEST_TYPE_INVALID 0x00
#define GB_REQUEST_TYPE_PROTOCOL_VERSION 0x01
/* Control Protocol */
struct gb_protocol_version_request {
__u8 major;
__u8 minor;
} __packed;
/* version request has no payload */
struct gb_protocol_version_response {
__u8 major;
__u8 minor;
......@@ -748,7 +750,10 @@ struct gb_spi_transfer_response {
#define GB_SVC_TYPE_ROUTE_CREATE 0x0b
#define GB_SVC_TYPE_ROUTE_DESTROY 0x0c
/* SVC version request/response have same payload as gb_protocol_version_response */
/*
* SVC version request/response has the same payload as
* gb_protocol_version_request/response.
*/
/* SVC protocol hello request */
struct gb_svc_hello_request {
......
......@@ -165,30 +165,31 @@ struct gb_protocol *gb_protocol_get(u8 id, u8 major, u8 minor)
int gb_protocol_get_version(struct gb_connection *connection)
{
struct gb_protocol_version_response version;
struct gb_protocol_version_request request;
struct gb_protocol_version_response response;
int retval;
version.major = connection->protocol->major;
version.minor = connection->protocol->minor;
request.major = connection->protocol->major;
request.minor = connection->protocol->minor;
retval = gb_operation_sync(connection, GB_REQUEST_TYPE_PROTOCOL_VERSION,
&version, sizeof(version), &version,
sizeof(version));
&request, sizeof(request), &response,
sizeof(response));
if (retval)
return retval;
if (version.major > connection->protocol->major) {
if (response.major > connection->protocol->major) {
dev_err(&connection->dev,
"unsupported major version (%hhu > %hhu)\n",
version.major, connection->protocol->major);
response.major, connection->protocol->major);
return -ENOTSUPP;
}
connection->module_major = version.major;
connection->module_minor = version.minor;
connection->module_major = response.major;
connection->module_minor = response.minor;
dev_dbg(&connection->dev, "version_major = %u version_minor = %u\n",
version.major, version.minor);
response.major, response.minor);
return 0;
}
......
......@@ -256,30 +256,31 @@ static void gb_svc_route_destroy(struct gb_svc *svc, u8 intf1_id, u8 intf2_id)
static int gb_svc_version_request(struct gb_operation *op)
{
struct gb_connection *connection = op->connection;
struct gb_protocol_version_response *version;
struct gb_protocol_version_request *request;
struct gb_protocol_version_response *response;
struct device *dev = &connection->dev;
version = op->request->payload;
request = op->request->payload;
if (version->major > GB_SVC_VERSION_MAJOR) {
if (request->major > GB_SVC_VERSION_MAJOR) {
dev_err(&connection->dev,
"unsupported major version (%hhu > %hhu)\n",
version->major, GB_SVC_VERSION_MAJOR);
request->major, GB_SVC_VERSION_MAJOR);
return -ENOTSUPP;
}
connection->module_major = version->major;
connection->module_minor = version->minor;
connection->module_major = request->major;
connection->module_minor = request->minor;
if (!gb_operation_response_alloc(op, sizeof(*version), GFP_KERNEL)) {
if (!gb_operation_response_alloc(op, sizeof(*response), GFP_KERNEL)) {
dev_err(dev, "%s: error allocating response\n",
__func__);
return -ENOMEM;
}
version = op->response->payload;
version->major = connection->module_major;
version->minor = connection->module_minor;
response = op->response->payload;
response->major = connection->module_major;
response->minor = connection->module_minor;
return 0;
}
......
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