greybus: descriptor type updates

Some more updates to the definition of a manifest descriptor.
    - We get rid of function descriptors.  The type of function is
      easily specified with the CPort it uses.
    - Add a new interface descriptor type.
    - Clean up the CPort descriptor structure, eliminating fields
      that serve no purpose and adding the function id field

The sysfs stuff will be updated a little later to add entries
for the Greybus interfaces associated with modules.

Rearrange the order of a few things in "greybus_manifest.h".

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This commit is contained in:
Alex Elder 2014-10-01 21:54:10 -05:00 committed by Greg Kroah-Hartman
parent 513c54cb05
commit ecf7d57971
4 changed files with 47 additions and 82 deletions

View file

@ -232,19 +232,6 @@ static const struct greybus_module_id fake_gb_id = {
GREYBUS_DEVICE(0x42, 0x42)
};
static int create_function(struct greybus_module *gmod,
struct greybus_descriptor_function *function,
size_t desc_size)
{
if (desc_size != sizeof(*function)) {
dev_err(gmod->dev.parent, "invalid function header size %zu\n",
desc_size);
return -EINVAL;
}
memcpy(&gmod->function, function, desc_size);
return 0;
}
static int create_module(struct greybus_module *gmod,
struct greybus_descriptor_module *module,
size_t desc_size)
@ -385,9 +372,7 @@ void gb_add_module(struct greybus_host_device *hd, u8 module_id,
data_size = (size_t)desc_size - sizeof(desc->header);
switch (le16_to_cpu(desc->header.type)) {
case GREYBUS_TYPE_FUNCTION:
retval = create_function(gmod, &desc->function,
data_size);
case GREYBUS_TYPE_DEVICE:
break;
case GREYBUS_TYPE_MODULE:

View file

@ -192,7 +192,6 @@ void greybus_gbuf_finished(struct gbuf *gbuf);
struct greybus_module {
struct device dev;
u16 module_number;
struct greybus_descriptor_function function;
struct greybus_descriptor_module module;
int num_cports;
int num_strings;
@ -210,12 +209,9 @@ struct greybus_module {
};
#define to_greybus_module(d) container_of(d, struct greybus_module, dev)
struct gbuf *greybus_alloc_gbuf(struct greybus_module *gmod,
u16 cport_id,
gbuf_complete_t complete,
unsigned int size,
gfp_t gfp_mask,
void *context);
struct gbuf *greybus_alloc_gbuf(struct greybus_module *gmod, u16 cport_id,
gbuf_complete_t complete, unsigned int size,
gfp_t gfp_mask, void *context);
void greybus_free_gbuf(struct gbuf *gbuf);
struct gbuf *greybus_get_gbuf(struct gbuf *gbuf);
#define greybus_put_gbuf greybus_free_gbuf

View file

@ -14,26 +14,15 @@
#pragma pack(push, 1)
struct greybus_manifest_header {
__le16 size;
__u8 version_major;
__u8 version_minor;
};
enum greybus_descriptor_type {
GREYBUS_TYPE_INVALID = 0x00,
GREYBUS_TYPE_MODULE = 0x01,
GREYBUS_TYPE_FUNCTION = 0x02,
GREYBUS_TYPE_DEVICE = 0x02,
GREYBUS_TYPE_CLASS = 0x03,
GREYBUS_TYPE_STRING = 0x04,
GREYBUS_TYPE_CPORT = 0x05,
};
struct greybus_descriptor_header {
__le16 size;
__u8 type; /* enum greybus_descriptor_type */
};
enum greybus_function_type {
GREYBUS_FUNCTION_CONTROL = 0x00,
GREYBUS_FUNCTION_USB = 0x01,
@ -51,11 +40,10 @@ enum greybus_function_type {
GREYBUS_FUNCTION_VENDOR = 0xff,
};
struct greybus_descriptor_function {
__le16 cport;
__u8 function_type; /* enum greybus_function_type */
};
/*
* A module descriptor describes information about a module as a
* whole, *not* the functions within it.
*/
struct greybus_descriptor_module {
__le16 vendor;
__le16 product;
@ -65,26 +53,61 @@ struct greybus_descriptor_module {
__u8 product_stringid;
};
/*
* A UniPro device normally supports a range of 32 CPorts (0..31).
* It is possible to support more than this by having a UniPro
* switch treat one device as if it were more than one. E.g.,
* allocate 3 device ids (rather than the normal--1) to physical
* device 5, and configure the switch to route all packets destined
* for "encoded" device ids 5, 6, and 7 to physical device 5.
* Device 5 uses the encoded device id in incoming UniPro packets to
* determine which bank of 32 CPorts should receive the UniPro
* segment.
*
* The "scale" field in this structure is used to define the number
* of encoded device ids should be allocated for this physical
* device. Scale is normally 1, to represent 32 available CPorts.
* A scale value 2 represents up to 64 CPorts; scale value 3
* represents up to 96 CPorts, and so on.
*/
struct greybus_descriptor_interface {
__u8 id; /* module-relative id (0..) */
__u8 scale; /* indicates range of of CPorts supported */
/* UniPro gear, number of in/out lanes */
};
struct greybus_descriptor_cport {
__le16 id;
__u8 function_type; /* enum greybus_function_type */
};
struct greybus_descriptor_string {
__u8 length;
__u8 id;
__u8 string[0];
};
struct greybus_descriptor_cport {
__le16 id;
struct greybus_descriptor_header {
__le16 size;
__u8 type; /* enum greybus_descriptor_type */
};
struct greybus_descriptor {
struct greybus_descriptor_header header;
union {
struct greybus_descriptor_function function;
struct greybus_descriptor_module module;
struct greybus_descriptor_string string;
struct greybus_descriptor_interface interface;
struct greybus_descriptor_cport cport;
};
};
struct greybus_manifest_header {
__le16 size;
__u8 version_major;
__u8 version_minor;
};
struct greybus_manifest {
struct greybus_manifest_header header;
struct greybus_descriptor descriptors[0];

View file

@ -20,44 +20,6 @@
#include "kernel_ver.h"
/* Function fields */
#define greybus_function_attr(field) \
static ssize_t function_##field##_show(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \
struct greybus_module *gmod = to_greybus_module(dev); \
return sprintf(buf, "%d\n", gmod->function.field); \
} \
static DEVICE_ATTR_RO(function_##field)
greybus_function_attr(cport);
greybus_function_attr(function_type);
static struct attribute *function_attrs[] = {
&dev_attr_function_cport.attr,
&dev_attr_function_function_type.attr,
NULL,
};
static umode_t function_attrs_are_visible(struct kobject *kobj,
struct attribute *a, int n)
{
struct greybus_module *gmod = to_greybus_module(kobj_to_dev(kobj));
// FIXME - make this a dynamic structure to "know" if it really is here
// or not easier?
if (gmod->function.cport ||
gmod->function.function_type)
return a->mode;
return 0;
}
static struct attribute_group function_attr_grp = {
.attrs = function_attrs,
.is_visible = function_attrs_are_visible,
};
/* Module fields */
#define greybus_module_attr(field) \
static ssize_t module_##field##_show(struct device *dev, \
@ -147,7 +109,6 @@ static struct attribute_group module_attr_grp = {
const struct attribute_group *greybus_module_groups[] = {
&function_attr_grp,
&module_attr_grp,
NULL,
};