mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-24 05:04:00 +08:00
usb: gadget: f_fs: Add flags to descriptors block
This reworks the way SuperSpeed descriptors are added and instead of having a magic after full and high speed descriptors, it reworks the whole descriptors block to include a flags field which lists which descriptors are present and makes future extensions possible. Signed-off-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
This commit is contained in:
parent
8d4e897bd0
commit
ac8dde11f2
@ -1434,7 +1434,7 @@ static void ffs_data_clear(struct ffs_data *ffs)
|
|||||||
if (ffs->epfiles)
|
if (ffs->epfiles)
|
||||||
ffs_epfiles_destroy(ffs->epfiles, ffs->eps_count);
|
ffs_epfiles_destroy(ffs->epfiles, ffs->eps_count);
|
||||||
|
|
||||||
kfree(ffs->raw_descs);
|
kfree(ffs->raw_descs_data);
|
||||||
kfree(ffs->raw_strings);
|
kfree(ffs->raw_strings);
|
||||||
kfree(ffs->stringtabs);
|
kfree(ffs->stringtabs);
|
||||||
}
|
}
|
||||||
@ -1446,12 +1446,12 @@ static void ffs_data_reset(struct ffs_data *ffs)
|
|||||||
ffs_data_clear(ffs);
|
ffs_data_clear(ffs);
|
||||||
|
|
||||||
ffs->epfiles = NULL;
|
ffs->epfiles = NULL;
|
||||||
|
ffs->raw_descs_data = NULL;
|
||||||
ffs->raw_descs = NULL;
|
ffs->raw_descs = NULL;
|
||||||
ffs->raw_strings = NULL;
|
ffs->raw_strings = NULL;
|
||||||
ffs->stringtabs = NULL;
|
ffs->stringtabs = NULL;
|
||||||
|
|
||||||
ffs->raw_fs_hs_descs_length = 0;
|
ffs->raw_descs_length = 0;
|
||||||
ffs->raw_ss_descs_length = 0;
|
|
||||||
ffs->fs_descs_count = 0;
|
ffs->fs_descs_count = 0;
|
||||||
ffs->hs_descs_count = 0;
|
ffs->hs_descs_count = 0;
|
||||||
ffs->ss_descs_count = 0;
|
ffs->ss_descs_count = 0;
|
||||||
@ -1865,89 +1865,76 @@ static int __ffs_data_do_entity(enum ffs_entity_type type,
|
|||||||
static int __ffs_data_got_descs(struct ffs_data *ffs,
|
static int __ffs_data_got_descs(struct ffs_data *ffs,
|
||||||
char *const _data, size_t len)
|
char *const _data, size_t len)
|
||||||
{
|
{
|
||||||
unsigned fs_count, hs_count, ss_count = 0;
|
char *data = _data, *raw_descs;
|
||||||
int fs_len, hs_len, ss_len, ret = -EINVAL;
|
unsigned counts[3], flags;
|
||||||
char *data = _data;
|
int ret = -EINVAL, i;
|
||||||
|
|
||||||
ENTER();
|
ENTER();
|
||||||
|
|
||||||
if (unlikely(get_unaligned_le32(data) != FUNCTIONFS_DESCRIPTORS_MAGIC ||
|
if (get_unaligned_le32(data + 4) != len)
|
||||||
get_unaligned_le32(data + 4) != len))
|
|
||||||
goto error;
|
goto error;
|
||||||
fs_count = get_unaligned_le32(data + 8);
|
|
||||||
hs_count = get_unaligned_le32(data + 12);
|
|
||||||
|
|
||||||
data += 16;
|
switch (get_unaligned_le32(data)) {
|
||||||
len -= 16;
|
case FUNCTIONFS_DESCRIPTORS_MAGIC:
|
||||||
|
flags = FUNCTIONFS_HAS_FS_DESC | FUNCTIONFS_HAS_HS_DESC;
|
||||||
if (likely(fs_count)) {
|
|
||||||
fs_len = ffs_do_descs(fs_count, data, len,
|
|
||||||
__ffs_data_do_entity, ffs);
|
|
||||||
if (unlikely(fs_len < 0)) {
|
|
||||||
ret = fs_len;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
data += fs_len;
|
|
||||||
len -= fs_len;
|
|
||||||
} else {
|
|
||||||
fs_len = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (likely(hs_count)) {
|
|
||||||
hs_len = ffs_do_descs(hs_count, data, len,
|
|
||||||
__ffs_data_do_entity, ffs);
|
|
||||||
if (unlikely(hs_len < 0)) {
|
|
||||||
ret = hs_len;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
data += hs_len;
|
|
||||||
len -= hs_len;
|
|
||||||
} else {
|
|
||||||
hs_len = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len >= 8) {
|
|
||||||
/* Check SS_MAGIC for presence of ss_descs and get SS_COUNT */
|
|
||||||
if (get_unaligned_le32(data) != FUNCTIONFS_SS_DESC_MAGIC)
|
|
||||||
goto einval;
|
|
||||||
|
|
||||||
ss_count = get_unaligned_le32(data + 4);
|
|
||||||
data += 8;
|
data += 8;
|
||||||
len -= 8;
|
len -= 8;
|
||||||
}
|
break;
|
||||||
|
case FUNCTIONFS_DESCRIPTORS_MAGIC_V2:
|
||||||
if (!fs_count && !hs_count && !ss_count)
|
flags = get_unaligned_le32(data + 8);
|
||||||
goto einval;
|
if (flags & ~(FUNCTIONFS_HAS_FS_DESC |
|
||||||
|
FUNCTIONFS_HAS_HS_DESC |
|
||||||
if (ss_count) {
|
FUNCTIONFS_HAS_SS_DESC)) {
|
||||||
ss_len = ffs_do_descs(ss_count, data, len,
|
ret = -ENOSYS;
|
||||||
__ffs_data_do_entity, ffs);
|
|
||||||
if (unlikely(ss_len < 0)) {
|
|
||||||
ret = ss_len;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
ret = ss_len;
|
data += 12;
|
||||||
} else {
|
len -= 12;
|
||||||
ss_len = 0;
|
break;
|
||||||
ret = 0;
|
default:
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(len != ret))
|
/* Read fs_count, hs_count and ss_count (if present) */
|
||||||
goto einval;
|
for (i = 0; i < 3; ++i) {
|
||||||
|
if (!(flags & (1 << i))) {
|
||||||
|
counts[i] = 0;
|
||||||
|
} else if (len < 4) {
|
||||||
|
goto error;
|
||||||
|
} else {
|
||||||
|
counts[i] = get_unaligned_le32(data);
|
||||||
|
data += 4;
|
||||||
|
len -= 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ffs->raw_fs_hs_descs_length = fs_len + hs_len;
|
/* Read descriptors */
|
||||||
ffs->raw_ss_descs_length = ss_len;
|
raw_descs = data;
|
||||||
ffs->raw_descs = _data;
|
for (i = 0; i < 3; ++i) {
|
||||||
ffs->fs_descs_count = fs_count;
|
if (!counts[i])
|
||||||
ffs->hs_descs_count = hs_count;
|
continue;
|
||||||
ffs->ss_descs_count = ss_count;
|
ret = ffs_do_descs(counts[i], data, len,
|
||||||
|
__ffs_data_do_entity, ffs);
|
||||||
|
if (ret < 0)
|
||||||
|
goto error;
|
||||||
|
data += ret;
|
||||||
|
len -= ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (raw_descs == data || len) {
|
||||||
|
ret = -EINVAL;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
ffs->raw_descs_data = _data;
|
||||||
|
ffs->raw_descs = raw_descs;
|
||||||
|
ffs->raw_descs_length = data - raw_descs;
|
||||||
|
ffs->fs_descs_count = counts[0];
|
||||||
|
ffs->hs_descs_count = counts[1];
|
||||||
|
ffs->ss_descs_count = counts[2];
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
einval:
|
|
||||||
ret = -EINVAL;
|
|
||||||
error:
|
error:
|
||||||
kfree(_data);
|
kfree(_data);
|
||||||
return ret;
|
return ret;
|
||||||
@ -2359,8 +2346,7 @@ static int _ffs_func_bind(struct usb_configuration *c,
|
|||||||
vla_item_with_sz(d, struct usb_descriptor_header *, ss_descs,
|
vla_item_with_sz(d, struct usb_descriptor_header *, ss_descs,
|
||||||
super ? ffs->ss_descs_count + 1 : 0);
|
super ? ffs->ss_descs_count + 1 : 0);
|
||||||
vla_item_with_sz(d, short, inums, ffs->interfaces_count);
|
vla_item_with_sz(d, short, inums, ffs->interfaces_count);
|
||||||
vla_item_with_sz(d, char, raw_descs,
|
vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length);
|
||||||
ffs->raw_fs_hs_descs_length + ffs->raw_ss_descs_length);
|
|
||||||
char *vlabuf;
|
char *vlabuf;
|
||||||
|
|
||||||
ENTER();
|
ENTER();
|
||||||
@ -2376,15 +2362,9 @@ static int _ffs_func_bind(struct usb_configuration *c,
|
|||||||
|
|
||||||
/* Zero */
|
/* Zero */
|
||||||
memset(vla_ptr(vlabuf, d, eps), 0, d_eps__sz);
|
memset(vla_ptr(vlabuf, d, eps), 0, d_eps__sz);
|
||||||
/* Copy only raw (hs,fs) descriptors (until ss_magic and ss_count) */
|
/* Copy descriptors */
|
||||||
memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs + 16,
|
memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs,
|
||||||
ffs->raw_fs_hs_descs_length);
|
ffs->raw_descs_length);
|
||||||
/* Copy SS descs present @ header + hs_fs_descs + ss_magic + ss_count */
|
|
||||||
if (func->ffs->ss_descs_count)
|
|
||||||
memcpy(vla_ptr(vlabuf, d, raw_descs) +
|
|
||||||
ffs->raw_fs_hs_descs_length,
|
|
||||||
ffs->raw_descs + 16 + ffs->raw_fs_hs_descs_length + 8,
|
|
||||||
ffs->raw_ss_descs_length);
|
|
||||||
|
|
||||||
memset(vla_ptr(vlabuf, d, inums), 0xff, d_inums__sz);
|
memset(vla_ptr(vlabuf, d, inums), 0xff, d_inums__sz);
|
||||||
for (ret = ffs->eps_count; ret; --ret) {
|
for (ret = ffs->eps_count; ret; --ret) {
|
||||||
|
@ -206,15 +206,13 @@ struct ffs_data {
|
|||||||
|
|
||||||
/* filled by __ffs_data_got_descs() */
|
/* filled by __ffs_data_got_descs() */
|
||||||
/*
|
/*
|
||||||
* Real descriptors are 16 bytes after raw_descs (so you need
|
* raw_descs is what you kfree, real_descs points inside of raw_descs,
|
||||||
* to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the
|
* where full speed, high speed and super speed descriptors start.
|
||||||
* first full speed descriptor).
|
* real_descs_length is the length of all those descriptors.
|
||||||
* raw_fs_hs_descs_length does not have those 16 bytes added.
|
|
||||||
* ss_descs are 8 bytes (ss_magic + count) pass the hs_descs
|
|
||||||
*/
|
*/
|
||||||
|
const void *raw_descs_data;
|
||||||
const void *raw_descs;
|
const void *raw_descs;
|
||||||
unsigned raw_fs_hs_descs_length;
|
unsigned raw_descs_length;
|
||||||
unsigned raw_ss_descs_length;
|
|
||||||
unsigned fs_descs_count;
|
unsigned fs_descs_count;
|
||||||
unsigned hs_descs_count;
|
unsigned hs_descs_count;
|
||||||
unsigned ss_descs_count;
|
unsigned ss_descs_count;
|
||||||
|
@ -10,10 +10,15 @@
|
|||||||
|
|
||||||
enum {
|
enum {
|
||||||
FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
|
FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
|
||||||
FUNCTIONFS_STRINGS_MAGIC = 2
|
FUNCTIONFS_STRINGS_MAGIC = 2,
|
||||||
|
FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define FUNCTIONFS_SS_DESC_MAGIC 0x0055DE5C
|
enum functionfs_flags {
|
||||||
|
FUNCTIONFS_HAS_FS_DESC = 1,
|
||||||
|
FUNCTIONFS_HAS_HS_DESC = 2,
|
||||||
|
FUNCTIONFS_HAS_SS_DESC = 4,
|
||||||
|
};
|
||||||
|
|
||||||
#ifndef __KERNEL__
|
#ifndef __KERNEL__
|
||||||
|
|
||||||
@ -29,34 +34,40 @@ struct usb_endpoint_descriptor_no_audio {
|
|||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* All numbers must be in little endian order.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct usb_functionfs_descs_head {
|
|
||||||
__le32 magic;
|
|
||||||
__le32 length;
|
|
||||||
__le32 fs_count;
|
|
||||||
__le32 hs_count;
|
|
||||||
} __attribute__((packed));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Descriptors format:
|
* Descriptors format:
|
||||||
*
|
*
|
||||||
* | off | name | type | description |
|
* | off | name | type | description |
|
||||||
* |-----+-----------+--------------+--------------------------------------|
|
* |-----+-----------+--------------+--------------------------------------|
|
||||||
* | 0 | magic | LE32 | FUNCTIONFS_{FS,HS}_DESCRIPTORS_MAGIC |
|
* | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC_V2 |
|
||||||
|
* | 4 | length | LE32 | length of the whole data chunk |
|
||||||
|
* | 8 | flags | LE32 | combination of functionfs_flags |
|
||||||
|
* | | fs_count | LE32 | number of full-speed descriptors |
|
||||||
|
* | | hs_count | LE32 | number of high-speed descriptors |
|
||||||
|
* | | ss_count | LE32 | number of super-speed descriptors |
|
||||||
|
* | | fs_descrs | Descriptor[] | list of full-speed descriptors |
|
||||||
|
* | | hs_descrs | Descriptor[] | list of high-speed descriptors |
|
||||||
|
* | | ss_descrs | Descriptor[] | list of super-speed descriptors |
|
||||||
|
*
|
||||||
|
* Depending on which flags are set, various fields may be missing in the
|
||||||
|
* structure. Any flags that are not recognised cause the whole block to be
|
||||||
|
* rejected with -ENOSYS.
|
||||||
|
*
|
||||||
|
* Legacy descriptors format:
|
||||||
|
*
|
||||||
|
* | off | name | type | description |
|
||||||
|
* |-----+-----------+--------------+--------------------------------------|
|
||||||
|
* | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC |
|
||||||
* | 4 | length | LE32 | length of the whole data chunk |
|
* | 4 | length | LE32 | length of the whole data chunk |
|
||||||
* | 8 | fs_count | LE32 | number of full-speed descriptors |
|
* | 8 | fs_count | LE32 | number of full-speed descriptors |
|
||||||
* | 12 | hs_count | LE32 | number of high-speed descriptors |
|
* | 12 | hs_count | LE32 | number of high-speed descriptors |
|
||||||
* | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors |
|
* | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors |
|
||||||
* | | hs_descrs | Descriptor[] | list of high-speed descriptors |
|
* | | hs_descrs | Descriptor[] | list of high-speed descriptors |
|
||||||
* | | ss_magic | LE32 | FUNCTIONFS_SS_DESC_MAGIC |
|
|
||||||
* | | ss_count | LE32 | number of super-speed descriptors |
|
|
||||||
* | | ss_descrs | Descriptor[] | list of super-speed descriptors |
|
|
||||||
*
|
*
|
||||||
* ss_magic: if present then it implies that SS_DESCs are also present
|
* All numbers must be in little endian order.
|
||||||
* descs are just valid USB descriptors and have the following format:
|
*
|
||||||
|
* Descriptor[] is an array of valid USB descriptors which have the following
|
||||||
|
* format:
|
||||||
*
|
*
|
||||||
* | off | name | type | description |
|
* | off | name | type | description |
|
||||||
* |-----+-----------------+------+--------------------------|
|
* |-----+-----------------+------+--------------------------|
|
||||||
|
Loading…
Reference in New Issue
Block a user