From 1cfc667d75d3a38989365da387f52a1c303c435d Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Tue, 30 Sep 2014 19:25:21 -0500 Subject: greybus: kill struct gmod_cport 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 Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/core.c | 14 +------------- drivers/staging/greybus/es1-ap-usb.c | 5 ++++- drivers/staging/greybus/gbuf.c | 22 +++++++++++----------- drivers/staging/greybus/greybus.h | 21 +++++++-------------- drivers/staging/greybus/kernel_ver.h | 3 +++ drivers/staging/greybus/svc_msg.h | 4 ++-- drivers/staging/greybus/test_sink.c | 4 ++-- drivers/staging/greybus/uart-gb.c | 2 +- 8 files changed, 31 insertions(+), 44 deletions(-) (limited to 'drivers') diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c index 3cc54ed..f8ba49c 100644 --- a/drivers/staging/greybus/core.c +++ b/drivers/staging/greybus/core.c @@ -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; diff --git a/drivers/staging/greybus/es1-ap-usb.c b/drivers/staging/greybus/es1-ap-usb.c index 8df1643..410acd3 100644 --- a/drivers/staging/greybus/es1-ap-usb.c +++ b/drivers/staging/greybus/es1-ap-usb.c @@ -11,8 +11,10 @@ #include #include #include + #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; diff --git a/drivers/staging/greybus/gbuf.c b/drivers/staging/greybus/gbuf.c index 94c2d6a..7b4a72a 100644 --- a/drivers/staging/greybus/gbuf.c +++ b/drivers/staging/greybus/gbuf.c @@ -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... */ diff --git a/drivers/staging/greybus/greybus.h b/drivers/staging/greybus/greybus.h index 1328dc9..4ca11f2 100644 --- a/drivers/staging/greybus/greybus.h +++ b/drivers/staging/greybus/greybus.h @@ -101,13 +101,6 @@ 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[]; diff --git a/drivers/staging/greybus/kernel_ver.h b/drivers/staging/greybus/kernel_ver.h index 40cc2e8..4aa5b83 100644 --- a/drivers/staging/greybus/kernel_ver.h +++ b/drivers/staging/greybus/kernel_ver.h @@ -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 */ diff --git a/drivers/staging/greybus/svc_msg.h b/drivers/staging/greybus/svc_msg.h index 4b69604..986368d 100644 --- a/drivers/staging/greybus/svc_msg.h +++ b/drivers/staging/greybus/svc_msg.h @@ -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 { diff --git a/drivers/staging/greybus/test_sink.c b/drivers/staging/greybus/test_sink.c index 8b254e3..811a237 100644 --- a/drivers/staging/greybus/test_sink.c +++ b/drivers/staging/greybus/test_sink.c @@ -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); diff --git a/drivers/staging/greybus/uart-gb.c b/drivers/staging/greybus/uart-gb.c index 7735a04..7f9d498 100644 --- a/drivers/staging/greybus/uart-gb.c +++ b/drivers/staging/greybus/uart-gb.c @@ -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; -- cgit v1.1