]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
greybus: connection: clean up connection-creation interface
authorJohan Hovold <johan@hovoldconsulting.com>
Wed, 25 Nov 2015 14:59:11 +0000 (15:59 +0100)
committerGreg Kroah-Hartman <gregkh@google.com>
Wed, 25 Nov 2015 23:34:19 +0000 (15:34 -0800)
Clean up the connection-creation interface by clearly separating our two
types of connections: static and dynamic.

Add two convenience functions for creating static and dynamic connections.

A static connection is a pre-setup connection that is defined by a host
device and a host-device cport id. Specifically, the remote interface or
cport id need not be known. The SVC connection is a static connection.

A dynamic connection is defined by a host device and a remote interface
and cport id. This is our normal connections where the host-device cport
is (generally) allocated dynamically.

Note that the new generic interface is marked static, but can be
exported later to allow dynamic connections to be created also from
fixed host-device cports (e.g. for CSI).

Also note that a connection of either type is uniquely identified by its
host-device and host-device cport id once created.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/connection.c
drivers/staging/greybus/connection.h
drivers/staging/greybus/interface.c
drivers/staging/greybus/manifest.c
drivers/staging/greybus/svc.c

index 51fc84e76a4896a2d5522a859c5eebde8c87fa9b..d87a346d1ce327d925299e9a2dc62b917dec681f 100644 (file)
@@ -94,25 +94,32 @@ int svc_update_connection(struct gb_interface *intf,
 }
 
 /*
- * Set up a Greybus connection, representing the bidirectional link
+ * gb_connection_create() - create a Greybus connection
+ * @hd:                        host device of the connection
+ * @hd_cport_id:       host-device cport id, or -1 for dynamic allocation
+ * @intf:              remote interface, or NULL for static connections
+ * @bundle:            remote-interface bundle (may be NULL)
+ * @cport_id:          remote-interface cport id, or 0 for static connections
+ * @protocol_id:       protocol id
+ *
+ * Create a Greybus connection, representing the bidirectional link
  * between a CPort on a (local) Greybus host device and a CPort on
- * another Greybus module.
+ * another Greybus interface.
  *
  * A connection also maintains the state of operations sent over the
  * connection.
  *
- * Returns a pointer to the new connection if successful, or a null
- * pointer otherwise.
+ * Return: A pointer to the new connection if successful, or NULL otherwise.
  */
-struct gb_connection *
-gb_connection_create_range(struct gb_host_device *hd,
-                          struct gb_bundle *bundle,
-                          u16 cport_id, u8 protocol_id, u32 ida_start,
-                          u32 ida_end)
+static struct gb_connection *
+gb_connection_create(struct gb_host_device *hd, int hd_cport_id,
+                               struct gb_interface *intf,
+                               struct gb_bundle *bundle, int cport_id,
+                               u8 protocol_id)
 {
        struct gb_connection *connection;
        struct ida *id_map = &hd->cport_id_map;
-       int hd_cport_id;
+       int ida_start, ida_end;
        int retval;
        u8 major = 0;
        u8 minor = 1;
@@ -128,6 +135,17 @@ gb_connection_create_range(struct gb_host_device *hd,
                return NULL;
        }
 
+       if (hd_cport_id < 0) {
+               ida_start = 0;
+               ida_end = hd->num_cports;
+       } else if (hd_cport_id < hd->num_cports) {
+               ida_start = hd_cport_id;
+               ida_end = hd_cport_id + 1;
+       } else {
+               dev_err(&hd->dev, "cport %d not available\n", hd_cport_id);
+               return NULL;
+       }
+
        hd_cport_id = ida_simple_get(id_map, ida_start, ida_end, GFP_KERNEL);
        if (hd_cport_id < 0)
                return NULL;
@@ -139,6 +157,7 @@ gb_connection_create_range(struct gb_host_device *hd,
        connection->hd_cport_id = hd_cport_id;
        connection->intf_cport_id = cport_id;
        connection->hd = hd;
+       connection->intf = intf;
 
        connection->protocol_id = protocol_id;
        connection->major = major;
@@ -186,6 +205,23 @@ gb_connection_create_range(struct gb_host_device *hd,
        return NULL;
 }
 
+struct gb_connection *
+gb_connection_create_static(struct gb_host_device *hd,
+                                       u16 hd_cport_id, u8 protocol_id)
+{
+       return gb_connection_create(hd, hd_cport_id, NULL, NULL, 0,
+                                                               protocol_id);
+}
+
+struct gb_connection *
+gb_connection_create_dynamic(struct gb_interface *intf,
+                                       struct gb_bundle *bundle,
+                                       u16 cport_id, u8 protocol_id)
+{
+       return gb_connection_create(intf->hd, -1, intf, bundle, cport_id,
+                                                               protocol_id);
+}
+
 static int gb_connection_hd_cport_enable(struct gb_connection *connection)
 {
        struct gb_host_device *hd = connection->hd;
@@ -214,14 +250,6 @@ static void gb_connection_hd_cport_disable(struct gb_connection *connection)
        hd->driver->cport_disable(hd, connection->hd_cport_id);
 }
 
-struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
-                               u16 cport_id, u8 protocol_id)
-{
-       return gb_connection_create_range(bundle->intf->hd, bundle,
-                                         cport_id, protocol_id,
-                                         0, bundle->intf->hd->num_cports);
-}
-
 /*
  * Cancel all active operations on a connection.
  *
index 44ecfbed1d0de04a3c30114dbe68f7ea086a9840..c5499fcbfd131b9a214173fe5dbb7a1484c933ce 100644 (file)
@@ -23,6 +23,7 @@ enum gb_connection_state {
 
 struct gb_connection {
        struct gb_host_device           *hd;
+       struct gb_interface             *intf;
        struct gb_bundle                *bundle;
        struct kref                     kref;
        u16                             hd_cport_id;
@@ -51,12 +52,12 @@ struct gb_connection {
 
 int svc_update_connection(struct gb_interface *intf,
                          struct gb_connection *connection);
-struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
-                               u16 cport_id, u8 protocol_id);
-struct gb_connection *gb_connection_create_range(struct gb_host_device *hd,
-                          struct gb_bundle *bundle,
-                          u16 cport_id, u8 protocol_id, u32 ida_start,
-                          u32 ida_end);
+
+struct gb_connection *gb_connection_create_static(struct gb_host_device *hd,
+                               u16 hd_cport_id, u8 protocol_id);
+struct gb_connection *gb_connection_create_dynamic(struct gb_interface *intf,
+                               struct gb_bundle *bundle, u16 cport_id,
+                               u8 protocol_id);
 void gb_connection_destroy(struct gb_connection *connection);
 
 void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id,
index c4ec25607230856fc2d82a08b2b43ce3936727e5..241518711323678c1c88e98e9cf85a4037a89ae4 100644 (file)
@@ -86,7 +86,8 @@ gb_interface_create_control_bundle_connection(struct gb_interface *intf)
                return -ENOMEM;
        }
 
-       connection = gb_connection_create(bundle, GB_CONTROL_CPORT_ID,
+       connection = gb_connection_create_dynamic(intf, bundle,
+                                               GB_CONTROL_CPORT_ID,
                                                GREYBUS_PROTOCOL_CONTROL);
        if (!connection) {
                dev_err(&intf->dev, "failed to create control connection\n");
index 41d51579217fd305254606a8bf7cdbbc319db389..9252bf46bcc4fa37362a4e1ab0ba661f5204eb2a 100644 (file)
@@ -251,7 +251,8 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
                        goto print_error_exit;
                }
 
-               if (!gb_connection_create(bundle, cport_id, protocol_id))
+               if (!gb_connection_create_dynamic(intf, bundle, cport_id,
+                                                               protocol_id))
                        goto exit;
 
 release_descriptor:
index c71f41d0ef62995baa1ae6f93bdeb17a8a7a761c..9dd51122ea4c2fa672045f23b362b2e4f53b9d11 100644 (file)
@@ -60,11 +60,8 @@ gb_ap_svc_connection_create(struct gb_host_device *hd)
 {
        struct gb_connection *connection;
 
-       connection = gb_connection_create_range(hd, NULL,
-                                               GB_SVC_CPORT_ID,
-                                               GREYBUS_PROTOCOL_SVC,
-                                               GB_SVC_CPORT_ID,
-                                               GB_SVC_CPORT_ID + 1);
+       connection = gb_connection_create_static(hd, GB_SVC_CPORT_ID,
+                                                       GREYBUS_PROTOCOL_SVC);
 
        return connection;
 }