greybus: Add flags to struct gb_protocol
authorViresh Kumar <viresh.kumar@linaro.org>
Mon, 7 Sep 2015 10:31:24 +0000 (16:01 +0530)
committerGreg Kroah-Hartman <gregkh@google.com>
Tue, 15 Sep 2015 04:19:46 +0000 (21:19 -0700)
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>
drivers/staging/greybus/connection.c
drivers/staging/greybus/control.c
drivers/staging/greybus/protocol.h
drivers/staging/greybus/svc.c

index e1a7705fd227d893f1c7a76863e19ed8d02c4a0b..3dcbb7832a58ed01dc898a5f4852c1d06a756af3 100644 (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) {
index e675c5c891236e7818971ca913502b25f9cba984..c092bebba77c2f01604115d767c4bdcb2562b4d8 100644 (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);
index 8d55a4a2f06e00ff1fa94d9899771274d0935c14..d856885a89e1f2f83c407e292bb594df618b8ab5 100644 (file)
 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 */
 
index b32519ac26fb27b0a22a08fb29018e462627b442..21dafcc3409a8a3115fc9a1dcff0d6135fb90b6f 100644 (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);