mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-02 15:18:19 +00:00
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 <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This commit is contained in:
parent
f0f70916fb
commit
1cfc667d75
8 changed files with 31 additions and 44 deletions
|
@ -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;
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
#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;
|
||||
|
|
|
@ -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... */
|
||||
|
|
|
@ -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[];
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue