提交 1b0bf88f 编写于 作者: R Robert Baldyga 提交者: Felipe Balbi

usb: gadget: f_fs: virtual endpoint address mapping

This patch introduces virtual endpoint address mapping. It separates
function logic form physical endpoint addresses making it more hardware
independent.

Following modifications changes user space API, so to enable them user
have to switch on the FUNCTIONFS_VIRTUAL_ADDR flag in descriptors.

Endpoints are now refered using virtual endpoint addresses chosen by
user in endpoint descpriptors. This applies to each context when endpoint
address can be used:
- when accessing endpoint files in FunctionFS filesystemi (in file name),
- in setup requests directed to specific endpoint (in wIndex field),
- in descriptors returned by FUNCTIONFS_ENDPOINT_DESC ioctl.

In endpoint file names the endpoint address number is formatted as
double-digit hexadecimal value ("ep%02x") which has few advantages -
it is easy to parse, allows to easly recognize endpoint direction basing
on its name (IN endpoint number starts with digit 8, and OUT with 0)
which can be useful for debugging purpose, and it makes easier to introduce
further features allowing to use each endpoint number in both directions
to have more endpoints available for function if hardware supports this
(for example we could have ep01 which is endpoint 1 with OUT direction,
and ep81 which is endpoint 1 with IN direction).

Physical endpoint address can be still obtained using ioctl named
FUNCTIONFS_ENDPOINT_REVMAP, but now it's not neccesary to handle
USB transactions properly.
Signed-off-by: NRobert Baldyga <r.baldyga@samsung.com>
Acked-by: NMichal Nazarewicz <mina86@mina86.com>
Signed-off-by: NFelipe Balbi <balbi@ti.com>
上级 4cd41ffd
...@@ -1557,7 +1557,10 @@ static int ffs_epfiles_create(struct ffs_data *ffs) ...@@ -1557,7 +1557,10 @@ static int ffs_epfiles_create(struct ffs_data *ffs)
epfile->ffs = ffs; epfile->ffs = ffs;
mutex_init(&epfile->mutex); mutex_init(&epfile->mutex);
init_waitqueue_head(&epfile->wait); init_waitqueue_head(&epfile->wait);
sprintf(epfiles->name, "ep%u", i); if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR)
sprintf(epfiles->name, "ep%02x", ffs->eps_addrmap[i]);
else
sprintf(epfiles->name, "ep%u", i);
if (!unlikely(ffs_sb_create_file(ffs->sb, epfiles->name, epfile, if (!unlikely(ffs_sb_create_file(ffs->sb, epfiles->name, epfile,
&ffs_epfile_operations, &ffs_epfile_operations,
&epfile->dentry))) { &epfile->dentry))) {
...@@ -2106,10 +2109,12 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, ...@@ -2106,10 +2109,12 @@ static int __ffs_data_got_descs(struct ffs_data *ffs,
break; break;
case FUNCTIONFS_DESCRIPTORS_MAGIC_V2: case FUNCTIONFS_DESCRIPTORS_MAGIC_V2:
flags = get_unaligned_le32(data + 8); flags = get_unaligned_le32(data + 8);
ffs->user_flags = flags;
if (flags & ~(FUNCTIONFS_HAS_FS_DESC | if (flags & ~(FUNCTIONFS_HAS_FS_DESC |
FUNCTIONFS_HAS_HS_DESC | FUNCTIONFS_HAS_HS_DESC |
FUNCTIONFS_HAS_SS_DESC | FUNCTIONFS_HAS_SS_DESC |
FUNCTIONFS_HAS_MS_OS_DESC)) { FUNCTIONFS_HAS_MS_OS_DESC |
FUNCTIONFS_VIRTUAL_ADDR)) {
ret = -ENOSYS; ret = -ENOSYS;
goto error; goto error;
} }
...@@ -2466,7 +2471,13 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, ...@@ -2466,7 +2471,13 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
} else { } else {
struct usb_request *req; struct usb_request *req;
struct usb_ep *ep; struct usb_ep *ep;
u8 bEndpointAddress;
/*
* We back up bEndpointAddress because autoconfig overwrites
* it with physical endpoint address.
*/
bEndpointAddress = ds->bEndpointAddress;
pr_vdebug("autoconfig\n"); pr_vdebug("autoconfig\n");
ep = usb_ep_autoconfig(func->gadget, ds); ep = usb_ep_autoconfig(func->gadget, ds);
if (unlikely(!ep)) if (unlikely(!ep))
...@@ -2481,6 +2492,12 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, ...@@ -2481,6 +2492,12 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
ffs_ep->req = req; ffs_ep->req = req;
func->eps_revmap[ds->bEndpointAddress & func->eps_revmap[ds->bEndpointAddress &
USB_ENDPOINT_NUMBER_MASK] = idx + 1; USB_ENDPOINT_NUMBER_MASK] = idx + 1;
/*
* If we use virtual address mapping, we restore
* original bEndpointAddress value.
*/
if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR)
ds->bEndpointAddress = bEndpointAddress;
} }
ffs_dump_mem(": Rewritten ep desc", ds, ds->bLength); ffs_dump_mem(": Rewritten ep desc", ds, ds->bLength);
...@@ -2925,6 +2942,8 @@ static int ffs_func_setup(struct usb_function *f, ...@@ -2925,6 +2942,8 @@ static int ffs_func_setup(struct usb_function *f,
ret = ffs_func_revmap_ep(func, le16_to_cpu(creq->wIndex)); ret = ffs_func_revmap_ep(func, le16_to_cpu(creq->wIndex));
if (unlikely(ret < 0)) if (unlikely(ret < 0))
return ret; return ret;
if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR)
ret = func->ffs->eps_addrmap[ret];
break; break;
default: default:
......
...@@ -224,6 +224,8 @@ struct ffs_data { ...@@ -224,6 +224,8 @@ struct ffs_data {
void *ms_os_descs_ext_prop_name_avail; void *ms_os_descs_ext_prop_name_avail;
void *ms_os_descs_ext_prop_data_avail; void *ms_os_descs_ext_prop_data_avail;
unsigned user_flags;
u8 eps_addrmap[15]; u8 eps_addrmap[15];
unsigned short strings_count; unsigned short strings_count;
......
...@@ -19,6 +19,7 @@ enum functionfs_flags { ...@@ -19,6 +19,7 @@ enum functionfs_flags {
FUNCTIONFS_HAS_HS_DESC = 2, FUNCTIONFS_HAS_HS_DESC = 2,
FUNCTIONFS_HAS_SS_DESC = 4, FUNCTIONFS_HAS_SS_DESC = 4,
FUNCTIONFS_HAS_MS_OS_DESC = 8, FUNCTIONFS_HAS_MS_OS_DESC = 8,
FUNCTIONFS_VIRTUAL_ADDR = 16,
}; };
/* Descriptor of an non-audio endpoint */ /* Descriptor of an non-audio endpoint */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册