]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
greybus: kill struct gmod_cport
authorAlex Elder <elder@linaro.org>
Wed, 1 Oct 2014 00:25:21 +0000 (19:25 -0500)
committerGreg Kroah-Hartman <greg@kroah.com>
Wed, 1 Oct 2014 01:19:12 +0000 (18:19 -0700)
A UniPro (short header) segment has a 5-bit field to represent a
CPort Id.  In addition, the 7-bit L3 short header holds a UniPro
device id.  There can be no more than 128 devices in a UniPro
network, but these two fields can be combined in ways to allow for
over 2000 CPorts within a single device.  As a result, a device id
is represented with one byte, and a CPort Id within a device is
always representable with a two byte value.

This patch changes integral values that reresent CPort Ids so they
use type u16 consistently.

Separately, the contents of the gmod_cport structure were mostly
fabricated, with the cport_id field being the only one that's
meaningful.  This patch gets rid of that structure, putting a
simple u16 to represent the CPort Id everywhere it had been used
before.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/staging/greybus/core.c
drivers/staging/greybus/es1-ap-usb.c
drivers/staging/greybus/gbuf.c
drivers/staging/greybus/greybus.h
drivers/staging/greybus/kernel_ver.h
drivers/staging/greybus/svc_msg.h
drivers/staging/greybus/test_sink.c
drivers/staging/greybus/uart-gb.c

index 3cc54ed492ee2c5fe191efd6cf2010d71383a8f0..f8ba49cea0b93e3897f052c16c6c8865eb200383 100644 (file)
@@ -160,8 +160,6 @@ static void greybus_module_release(struct device *dev)
 
        for (i = 0; i < gmod->num_strings; ++i)
                kfree(gmod->string[i]);
-       for (i = 0; i < gmod->num_cports; ++i)
-               kfree(gmod->cport[i]);
        kfree(gmod);
 }
 
@@ -298,8 +296,6 @@ static int create_cport(struct greybus_module *gmod,
                        struct greybus_descriptor_cport *cport,
                        size_t desc_size)
 {
-       struct gmod_cport *gmod_cport;
-
        if (gmod->num_cports == MAX_CPORTS_PER_MODULE) {
                dev_err(gmod->dev.parent, "too many cports for this module!\n");
                return -EINVAL;
@@ -311,15 +307,7 @@ static int create_cport(struct greybus_module *gmod,
                return -EINVAL;
        }
 
-       gmod_cport = kzalloc(sizeof(*gmod_cport), GFP_KERNEL);
-       if (!gmod_cport)
-               return -ENOMEM;
-
-       gmod_cport->id = le16_to_cpu(cport->id);
-       gmod_cport->size = le16_to_cpu(cport->size);
-       gmod_cport->speed = cport->speed;
-
-       gmod->cport[gmod->num_cports] = gmod_cport;
+       gmod->cport_ids[gmod->num_cports] = le16_to_cpu(cport->id);
        gmod->num_cports++;
 
        return 0;
index 8df16437cc8b7d35f52135881c9759052d5cff32..410acd304dee1ba0b4ccf92bfcfca359a1ec86ee 100644 (file)
 #include <linux/errno.h>
 #include <linux/sizes.h>
 #include <linux/usb.h>
+
 #include "greybus.h"
 #include "svc_msg.h"
+#include "kernel_ver.h"
 
 /* Memory sizes for the buffers sent to/from the ES1 controller */
 #define ES1_SVC_MSG_SIZE       (sizeof(struct svc_msg) + SZ_64K)
@@ -114,7 +116,8 @@ static int alloc_gbuf_data(struct gbuf *gbuf, unsigned int size, gfp_t gfp_mask)
         * we will encode the cport number in the first byte of the buffer, so
         * set the second byte to be the "transfer buffer"
         */
-       buffer[0] = gbuf->cport->id;
+       BUG_ON(gbuf->cport_id > (u16)U8_MAX);
+       buffer[0] = gbuf->cport_id;
        gbuf->transfer_buffer = &buffer[1];
        gbuf->transfer_buffer_length = size;
        gbuf->actual_length = size;
index 94c2d6acb49133e20283f4555c249d39edc37be5..7b4a72a7c4b40dd79df22331e803336594ec0645 100644 (file)
@@ -27,7 +27,7 @@ static struct kmem_cache *gbuf_head_cache;
 static struct workqueue_struct *gbuf_workqueue;
 
 static struct gbuf *__alloc_gbuf(struct greybus_module *gmod,
-                               struct gmod_cport *cport,
+                               u16 cport_id,
                                gbuf_complete_t complete,
                                gfp_t gfp_mask,
                                void *context)
@@ -40,7 +40,7 @@ static struct gbuf *__alloc_gbuf(struct greybus_module *gmod,
 
        kref_init(&gbuf->kref);
        gbuf->gmod = gmod;
-       gbuf->cport = cport;
+       gbuf->cport_id = cport_id;
        INIT_WORK(&gbuf->event, cport_process_event);
        gbuf->complete = complete;
        gbuf->context = context;
@@ -64,7 +64,7 @@ static struct gbuf *__alloc_gbuf(struct greybus_module *gmod,
  * hardware designers for this issue...
  */
 struct gbuf *greybus_alloc_gbuf(struct greybus_module *gmod,
-                               struct gmod_cport *cport,
+                               u16 cport_id,
                                gbuf_complete_t complete,
                                unsigned int size,
                                gfp_t gfp_mask,
@@ -73,7 +73,7 @@ struct gbuf *greybus_alloc_gbuf(struct greybus_module *gmod,
        struct gbuf *gbuf;
        int retval;
 
-       gbuf = __alloc_gbuf(gmod, cport, complete, gfp_mask, context);
+       gbuf = __alloc_gbuf(gmod, cport_id, complete, gfp_mask, context);
        if (!gbuf)
                return NULL;
 
@@ -146,7 +146,7 @@ static void cport_process_event(struct work_struct *work)
 #define MAX_CPORTS     1024
 struct gb_cport_handler {
        gbuf_complete_t handler;
-       struct gmod_cport cport;
+       u16 cport_id;
        struct greybus_module *gmod;
        void *context;
 };
@@ -156,25 +156,25 @@ static struct gb_cport_handler cport_handler[MAX_CPORTS];
 // need it, we don't have a dynamic system...
 
 int gb_register_cport_complete(struct greybus_module *gmod,
-                              gbuf_complete_t handler, int cport_id,
+                              gbuf_complete_t handler, u16 cport_id,
                               void *context)
 {
        if (cport_handler[cport_id].handler)
                return -EINVAL;
        cport_handler[cport_id].context = context;
        cport_handler[cport_id].gmod = gmod;
-       cport_handler[cport_id].cport.id = cport_id;
+       cport_handler[cport_id].cport_id = cport_id;
        cport_handler[cport_id].handler = handler;
        return 0;
 }
 
-void gb_deregister_cport_complete(int cport_id)
+void gb_deregister_cport_complete(u16 cport_id)
 {
        cport_handler[cport_id].handler = NULL;
 }
 
-void greybus_cport_in(struct greybus_host_device *hd, int cport_id, u8 *data,
-                          size_t length)
+void greybus_cport_in(struct greybus_host_device *hd, u16 cport_id,
+                       u8 *data, size_t length)
 {
        struct gb_cport_handler *ch;
        struct gbuf *gbuf;
@@ -189,7 +189,7 @@ void greybus_cport_in(struct greybus_host_device *hd, int cport_id, u8 *data,
                return;
        }
 
-       gbuf = __alloc_gbuf(ch->gmod, &ch->cport, ch->handler, GFP_ATOMIC,
+       gbuf = __alloc_gbuf(ch->gmod, ch->cport_id, ch->handler, GFP_ATOMIC,
                        ch->context);
        if (!gbuf) {
                /* Again, something bad went wrong, log it... */
index 1328dc9cc6f1b60c891b44bc80b893b7eae35c95..4ca11f289ee06040a032ccccd79063bb3a040aa0 100644 (file)
 
 struct gbuf;
 
-struct gmod_cport {
-       u16     id;
-       u16     size;
-       u8      speed;  // valid???
-       // FIXME, what else?
-};
-
 struct gmod_string {
        u16     length;
        u8      id;
@@ -121,7 +114,7 @@ struct gbuf {
        void *hdpriv;
 
        struct greybus_module *gmod;
-       struct gmod_cport *cport;
+       u16 cport_id;
        int status;
        void *transfer_buffer;
        u32 transfer_flags;             /* flags for the transfer buffer */
@@ -187,8 +180,8 @@ struct greybus_host_device {
 struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *host_driver,
                                              struct device *parent);
 void greybus_remove_hd(struct greybus_host_device *hd);
-void greybus_cport_in(struct greybus_host_device *hd, int cport_id, u8 *data,
-                          size_t length);
+void greybus_cport_in(struct greybus_host_device *hd, u16 cport_id,
+                       u8 *data, size_t length);
 void greybus_gbuf_finished(struct gbuf *gbuf);
 
 
@@ -203,7 +196,7 @@ struct greybus_module {
        struct greybus_descriptor_module module;
        int num_cports;
        int num_strings;
-       struct gmod_cport *cport[MAX_CPORTS_PER_MODULE];
+       u16 cport_ids[MAX_CPORTS_PER_MODULE];
        struct gmod_string *string[MAX_STRINGS_PER_MODULE];
 
        struct greybus_host_device *hd;
@@ -218,7 +211,7 @@ struct greybus_module {
 #define to_greybus_module(d) container_of(d, struct greybus_module, dev)
 
 struct gbuf *greybus_alloc_gbuf(struct greybus_module *gmod,
-                               struct gmod_cport *cport,
+                               u16 cport_id,
                                gbuf_complete_t complete,
                                unsigned int size,
                                gfp_t gfp_mask,
@@ -298,9 +291,9 @@ int gb_gbuf_init(void);
 void gb_gbuf_exit(void);
 
 int gb_register_cport_complete(struct greybus_module *gmod,
-                              gbuf_complete_t handler, int cport_id,
+                              gbuf_complete_t handler, u16 cport_id,
                               void *context);
-void gb_deregister_cport_complete(int cport_id);
+void gb_deregister_cport_complete(u16 cport_id);
 
 extern const struct attribute_group *greybus_module_groups[];
 
index 40cc2e8af525269525c0bc6af492e6f8539bdb29..4aa5b83bff60424dbeaa14ea47a7c185be6f3303 100644 (file)
@@ -18,5 +18,8 @@
        struct device_attribute dev_attr_##_name = __ATTR_RO(_name)
 #endif
 
+#ifndef U8_MAX
+#define U8_MAX ((u8)~0U)
+#endif /* ! U8_MAX */
 
 #endif /* __GREYBUS_KERNEL_VER_H */
index 4b696040b4e1632d422a9587c29a80ba5870caaa..986368d1032324880e103abef260b665e54e8385 100644 (file)
@@ -49,9 +49,9 @@ struct svc_function_handshake {
 
 struct svc_function_unipro_set_route {
        __u8    source_module_id;
-       __u8    source_cport_id;
+       __u8    source_cport_id;        /* bottom 8 bits */
        __u8    destination_module_id;
-       __u8    destination_cport_id;
+       __u8    destination_cport_id;   /* bottom 8 bits */
 };
 
 struct svc_function_unipro_link_up {
index 8b254e3fb037fd17d00d5b0e9d5b02969bc9802d..811a237898cc065f78a8689416a3e0bd09c7a939 100644 (file)
@@ -16,9 +16,9 @@ struct test_device {
 };
 
 int gb_register_cport_complete(struct greybus_module *gmod,
-                              gbuf_complete_t handler, int cport_id,
+                              gbuf_complete_t handler, u16 cport_id,
                               void *context);
-void gb_deregister_cport_complete(int cport_id);
+void gb_deregister_cport_complete(u16 cport_id);
 
 
 
index 7735a045da69a45d5c7aa804b554c2d0d23fb24f..7f9d49869281f523fd2a1a2dbfac676f2dcb8421 100644 (file)
@@ -34,7 +34,7 @@
 struct gb_tty {
        struct tty_port port;
        struct greybus_module *gmod;
-       int cport_id;
+       u16 cport_id;
        unsigned int minor;
        unsigned char clocal;
        unsigned int throttled:1;