greybus: Add flags to struct gb_protocol

This helps in removing special per-protocol code, with the help of
generic flags passed by protocol drivers.

Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
Viresh Kumar 2015-09-07 16:01:24 +05:30 committed by Greg Kroah-Hartman
parent fb198317fd
commit 5a5296bb8d
4 changed files with 25 additions and 18 deletions

View File

@ -315,7 +315,7 @@ static void gb_connection_cancel_operations(struct gb_connection *connection,
static void
gb_connection_svc_connection_destroy(struct gb_connection *connection)
{
if (connection->hd_cport_id == GB_SVC_CPORT_ID)
if (connection->protocol->flags & GB_PROTOCOL_SKIP_SVC_CONNECTION)
return;
if (connection->hd->driver->connection_destroy)
@ -334,12 +334,8 @@ static void gb_connection_disconnected(struct gb_connection *connection)
int cport_id = connection->intf_cport_id;
int ret;
/*
* Inform Interface about In-active CPorts. We don't need to do this
* operation for control cport.
*/
if ((cport_id == GB_CONTROL_CPORT_ID) ||
(connection->hd_cport_id == GB_SVC_CPORT_ID))
/* Inform Interface about inactive CPorts */
if (connection->protocol->flags & GB_PROTOCOL_SKIP_CONTROL_DISCONNECTED)
return;
control = connection->bundle->intf->control;
@ -354,13 +350,14 @@ static int gb_connection_init(struct gb_connection *connection)
{
int cport_id = connection->intf_cport_id;
struct greybus_host_device *hd = connection->hd;
struct gb_protocol *protocol = connection->protocol;
int ret;
/*
* Request the SVC to create a connection from AP's cport to interface's
* cport.
*/
if (connection->hd_cport_id != GB_SVC_CPORT_ID) {
if (!(protocol->flags & GB_PROTOCOL_SKIP_SVC_CONNECTION)) {
ret = gb_svc_connection_create(hd->svc,
hd->endo->ap_intf_id, connection->hd_cport_id,
connection->bundle->intf->interface_id,
@ -375,13 +372,8 @@ static int gb_connection_init(struct gb_connection *connection)
if (hd->driver->connection_create)
hd->driver->connection_create(connection);
}
/*
* Inform Interface about Active CPorts. We don't need to do this
* operation for control cport.
*/
if (cport_id != GB_CONTROL_CPORT_ID &&
connection->hd_cport_id != GB_SVC_CPORT_ID) {
/* Inform Interface about active CPorts */
if (!(protocol->flags & GB_PROTOCOL_SKIP_CONTROL_CONNECTED)) {
struct gb_control *control = connection->bundle->intf->control;
ret = gb_control_connected_operation(control, cport_id);
@ -402,7 +394,7 @@ static int gb_connection_init(struct gb_connection *connection)
* Request protocol version supported by the module. We don't need to do
* this for SVC as that is initiated by the SVC.
*/
if (connection->hd_cport_id != GB_SVC_CPORT_ID) {
if (!(protocol->flags & GB_PROTOCOL_SKIP_VERSION)) {
ret = gb_protocol_get_version(connection);
if (ret) {
dev_err(&connection->dev,
@ -412,7 +404,7 @@ static int gb_connection_init(struct gb_connection *connection)
}
}
ret = connection->protocol->connection_init(connection);
ret = protocol->connection_init(connection);
if (!ret)
return 0;
@ -505,7 +497,7 @@ int gb_connection_bind_protocol(struct gb_connection *connection)
* active device, so bring up the connection at the same time.
*/
if ((!connection->bundle &&
connection->hd_cport_id == GB_SVC_CPORT_ID) ||
protocol->flags & GB_PROTOCOL_NO_BUNDLE) ||
connection->bundle->intf->device_id != GB_DEVICE_ID_BAD) {
ret = gb_connection_init(connection);
if (ret) {

View File

@ -130,5 +130,7 @@ static struct gb_protocol control_protocol = {
.connection_init = gb_control_connection_init,
.connection_exit = gb_control_connection_exit,
.request_recv = gb_control_request_recv,
.flags = GB_PROTOCOL_SKIP_CONTROL_CONNECTED |
GB_PROTOCOL_SKIP_CONTROL_DISCONNECTED,
};
gb_builtin_protocol_driver(control_protocol);

View File

@ -13,6 +13,13 @@
struct gb_connection;
struct gb_operation;
/* Possible flags for protocol drivers */
#define GB_PROTOCOL_SKIP_CONTROL_CONNECTED BIT(0) /* Don't sent connected requests */
#define GB_PROTOCOL_SKIP_CONTROL_DISCONNECTED BIT(1) /* Don't sent disconnected requests */
#define GB_PROTOCOL_NO_BUNDLE BIT(2) /* Protocol May have a bundle-less connection */
#define GB_PROTOCOL_SKIP_VERSION BIT(3) /* Don't send get_version() requests */
#define GB_PROTOCOL_SKIP_SVC_CONNECTION BIT(4) /* Don't send SVC connection requests */
typedef int (*gb_connection_init_t)(struct gb_connection *);
typedef void (*gb_connection_exit_t)(struct gb_connection *);
typedef int (*gb_request_recv_t)(u8, struct gb_operation *);
@ -27,6 +34,7 @@ struct gb_protocol {
u8 major;
u8 minor;
u8 count;
unsigned long flags;
struct list_head links; /* global list */

View File

@ -524,5 +524,10 @@ static struct gb_protocol svc_protocol = {
.connection_init = gb_svc_connection_init,
.connection_exit = gb_svc_connection_exit,
.request_recv = gb_svc_request_recv,
.flags = GB_PROTOCOL_SKIP_CONTROL_CONNECTED |
GB_PROTOCOL_SKIP_CONTROL_DISCONNECTED |
GB_PROTOCOL_NO_BUNDLE |
GB_PROTOCOL_SKIP_VERSION |
GB_PROTOCOL_SKIP_SVC_CONNECTION,
};
gb_builtin_protocol_driver(svc_protocol);