Skip to content

Commit

Permalink
usb: gadget: add usb_endpoint_descriptor to struct usb_ep
Browse files Browse the repository at this point in the history
Change usb_ep_enable() prototype to use endpoint
descriptor from usb_ep.

This optimization spares the FDs from saving the
endpoint chosen descriptor. This optimization is
not full though. To fully exploit this change, one
needs to update all the UDCs as well since in the
current implementation each of them saves the
endpoint descriptor in it's internal (and extended)
endpoint structure.

Signed-off-by: Tatyana Brokhman <tlinder@codeaurora.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Tatyana Brokhman authored and Greg Kroah-Hartman committed Jun 28, 2011
1 parent 0f91349 commit 72c973d
Show file tree
Hide file tree
Showing 26 changed files with 111 additions and 117 deletions.
8 changes: 5 additions & 3 deletions drivers/usb/gadget/dbgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ static int dbgp_enable_ep_req(struct usb_ep *ep)

static int __enable_ep(struct usb_ep *ep, struct usb_endpoint_descriptor *desc)
{
int err = usb_ep_enable(ep, desc);
int err;
ep->desc = desc;
err = usb_ep_enable(ep);
ep->driver_data = dbgp.gadget;
return err;
}
Expand Down Expand Up @@ -268,8 +270,8 @@ static int __init dbgp_configure_endpoints(struct usb_gadget *gadget)
dbgp.serial->in = dbgp.i_ep;
dbgp.serial->out = dbgp.o_ep;

dbgp.serial->in_desc = &i_desc;
dbgp.serial->out_desc = &o_desc;
dbgp.serial->in->desc = &i_desc;
dbgp.serial->out->desc = &o_desc;

if (gserial_setup(gadget, 1) < 0) {
stp = 3;
Expand Down
9 changes: 4 additions & 5 deletions drivers/usb/gadget/f_acm.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ struct f_acm {
struct acm_ep_descs hs;

struct usb_ep *notify;
struct usb_endpoint_descriptor *notify_desc;
struct usb_request *notify_req;

struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */
Expand Down Expand Up @@ -405,11 +404,11 @@ static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
usb_ep_disable(acm->notify);
} else {
VDBG(cdev, "init acm ctrl interface %d\n", intf);
acm->notify_desc = ep_choose(cdev->gadget,
acm->notify->desc = ep_choose(cdev->gadget,
acm->hs.notify,
acm->fs.notify);
}
usb_ep_enable(acm->notify, acm->notify_desc);
usb_ep_enable(acm->notify);
acm->notify->driver_data = acm;

} else if (intf == acm->data_id) {
Expand All @@ -418,9 +417,9 @@ static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
gserial_disconnect(&acm->port);
} else {
DBG(cdev, "activate acm ttyGS%d\n", acm->port_num);
acm->port.in_desc = ep_choose(cdev->gadget,
acm->port.in->desc = ep_choose(cdev->gadget,
acm->hs.in, acm->fs.in);
acm->port.out_desc = ep_choose(cdev->gadget,
acm->port.out->desc = ep_choose(cdev->gadget,
acm->hs.out, acm->fs.out);
}
gserial_connect(&acm->port, acm->port_num);
Expand Down
5 changes: 2 additions & 3 deletions drivers/usb/gadget/f_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ struct f_audio {

/* endpoints handle full and/or high speeds */
struct usb_ep *out_ep;
struct usb_endpoint_descriptor *out_desc;

spinlock_t lock;
struct f_audio_buf *copy_buf;
Expand Down Expand Up @@ -575,7 +574,7 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)

if (intf == 1) {
if (alt == 1) {
usb_ep_enable(out_ep, audio->out_desc);
usb_ep_enable(out_ep);
out_ep->driver_data = audio;
audio->copy_buf = f_audio_buffer_alloc(audio_buf_size);
if (IS_ERR(audio->copy_buf))
Expand Down Expand Up @@ -677,6 +676,7 @@ f_audio_bind(struct usb_configuration *c, struct usb_function *f)
if (!ep)
goto fail;
audio->out_ep = ep;
audio->out_ep->desc = &as_out_ep_desc;
ep->driver_data = cdev; /* claim */

status = -ENOMEM;
Expand Down Expand Up @@ -776,7 +776,6 @@ int __init audio_bind_config(struct usb_configuration *c)
audio->card.func.set_alt = f_audio_set_alt;
audio->card.func.setup = f_audio_setup;
audio->card.func.disable = f_audio_disable;
audio->out_desc = &as_out_ep_desc;

control_selector_init(audio);

Expand Down
17 changes: 8 additions & 9 deletions drivers/usb/gadget/f_ecm.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ struct f_ecm {
struct ecm_ep_descs hs;

struct usb_ep *notify;
struct usb_endpoint_descriptor *notify_desc;
struct usb_request *notify_req;
u8 notify_state;
bool is_open;
Expand Down Expand Up @@ -466,11 +465,11 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
usb_ep_disable(ecm->notify);
} else {
VDBG(cdev, "init ecm ctrl %d\n", intf);
ecm->notify_desc = ep_choose(cdev->gadget,
ecm->notify->desc = ep_choose(cdev->gadget,
ecm->hs.notify,
ecm->fs.notify);
}
usb_ep_enable(ecm->notify, ecm->notify_desc);
usb_ep_enable(ecm->notify);
ecm->notify->driver_data = ecm;

/* Data interface has two altsettings, 0 and 1 */
Expand All @@ -483,11 +482,11 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
gether_disconnect(&ecm->port);
}

if (!ecm->port.in) {
if (!ecm->port.in_ep->desc) {
DBG(cdev, "init ecm\n");
ecm->port.in = ep_choose(cdev->gadget,
ecm->port.in_ep->desc = ep_choose(cdev->gadget,
ecm->hs.in, ecm->fs.in);
ecm->port.out = ep_choose(cdev->gadget,
ecm->port.out_ep->desc = ep_choose(cdev->gadget,
ecm->hs.out, ecm->fs.out);
}

Expand Down Expand Up @@ -549,7 +548,7 @@ static void ecm_disable(struct usb_function *f)
if (ecm->notify->driver_data) {
usb_ep_disable(ecm->notify);
ecm->notify->driver_data = NULL;
ecm->notify_desc = NULL;
ecm->notify->desc = NULL;
}
}

Expand Down Expand Up @@ -723,9 +722,9 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
/* we might as well release our claims on endpoints */
if (ecm->notify)
ecm->notify->driver_data = NULL;
if (ecm->port.out)
if (ecm->port.out_ep->desc)
ecm->port.out_ep->driver_data = NULL;
if (ecm->port.in)
if (ecm->port.in_ep->desc)
ecm->port.in_ep->driver_data = NULL;

ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
Expand Down
10 changes: 5 additions & 5 deletions drivers/usb/gadget/f_eem.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ static int eem_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
gether_disconnect(&eem->port);
}

if (!eem->port.in) {
if (!eem->port.in_ep->desc) {
DBG(cdev, "init eem\n");
eem->port.in = ep_choose(cdev->gadget,
eem->port.in_ep->desc = ep_choose(cdev->gadget,
eem->hs.in, eem->fs.in);
eem->port.out = ep_choose(cdev->gadget,
eem->port.out_ep->desc = ep_choose(cdev->gadget,
eem->hs.out, eem->fs.out);
}

Expand Down Expand Up @@ -289,9 +289,9 @@ eem_bind(struct usb_configuration *c, struct usb_function *f)
usb_free_descriptors(f->descriptors);

/* we might as well release our claims on endpoints */
if (eem->port.out)
if (eem->port.out_ep->desc)
eem->port.out_ep->driver_data = NULL;
if (eem->port.in)
if (eem->port.in_ep->desc)
eem->port.in_ep->driver_data = NULL;

ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
Expand Down
3 changes: 2 additions & 1 deletion drivers/usb/gadget/f_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,8 @@ static int ffs_func_eps_enable(struct ffs_function *func)
ds = ep->descs[ep->descs[1] ? 1 : 0];

ep->ep->driver_data = ep;
ret = usb_ep_enable(ep->ep, ds);
ep->ep->desc = ds;
ret = usb_ep_enable(ep->ep);
if (likely(!ret)) {
epfile->ep = ep;
epfile->in = usb_endpoint_dir_in(ds);
Expand Down
5 changes: 2 additions & 3 deletions drivers/usb/gadget/f_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
{
struct usb_composite_dev *cdev = f->config->cdev;
struct f_hidg *hidg = func_to_hidg(f);
const struct usb_endpoint_descriptor *ep_desc;
int status = 0;

VDBG(cdev, "hidg_set_alt intf:%d alt:%d\n", intf, alt);
Expand All @@ -426,9 +425,9 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
if (hidg->in_ep->driver_data != NULL)
usb_ep_disable(hidg->in_ep);

ep_desc = ep_choose(f->config->cdev->gadget,
hidg->in_ep->desc = ep_choose(f->config->cdev->gadget,
hidg->hs_in_ep_desc, hidg->fs_in_ep_desc);
status = usb_ep_enable(hidg->in_ep, ep_desc);
status = usb_ep_enable(hidg->in_ep);
if (status < 0) {
ERROR(cdev, "Enable endpoint FAILED!\n");
goto fail;
Expand Down
14 changes: 6 additions & 8 deletions drivers/usb/gadget/f_loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,26 +250,24 @@ static int
enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop)
{
int result = 0;
const struct usb_endpoint_descriptor *src, *sink;
struct usb_ep *ep;
struct usb_request *req;
unsigned i;

src = ep_choose(cdev->gadget,
&hs_loop_source_desc, &fs_loop_source_desc);
sink = ep_choose(cdev->gadget,
&hs_loop_sink_desc, &fs_loop_sink_desc);

/* one endpoint writes data back IN to the host */
ep = loop->in_ep;
result = usb_ep_enable(ep, src);
ep->desc = ep_choose(cdev->gadget,
&hs_loop_source_desc, &fs_loop_source_desc);
result = usb_ep_enable(ep);
if (result < 0)
return result;
ep->driver_data = loop;

/* one endpoint just reads OUT packets */
ep = loop->out_ep;
result = usb_ep_enable(ep, sink);
ep->desc = ep_choose(cdev->gadget,
&hs_loop_sink_desc, &fs_loop_sink_desc);
result = usb_ep_enable(ep);
if (result < 0) {
fail0:
ep = loop->in_ep;
Expand Down
3 changes: 2 additions & 1 deletion drivers/usb/gadget/f_mass_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -2330,7 +2330,8 @@ static int enable_endpoint(struct fsg_common *common, struct usb_ep *ep,
int rc;

ep->driver_data = common;
rc = usb_ep_enable(ep, d);
ep->desc = (struct usb_endpoint_descriptor *)d;
rc = usb_ep_enable(ep);
if (rc)
ERROR(common, "can't enable %s, result %d\n", ep->name, rc);
return rc;
Expand Down
17 changes: 8 additions & 9 deletions drivers/usb/gadget/f_ncm.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ struct f_ncm {
struct ncm_ep_descs hs;

struct usb_ep *notify;
struct usb_endpoint_descriptor *notify_desc;
struct usb_request *notify_req;
u8 notify_state;
bool is_open;
Expand Down Expand Up @@ -804,11 +803,11 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
usb_ep_disable(ncm->notify);
} else {
DBG(cdev, "init ncm ctrl %d\n", intf);
ncm->notify_desc = ep_choose(cdev->gadget,
ncm->notify->desc = ep_choose(cdev->gadget,
ncm->hs.notify,
ncm->fs.notify);
}
usb_ep_enable(ncm->notify, ncm->notify_desc);
usb_ep_enable(ncm->notify);
ncm->notify->driver_data = ncm;

/* Data interface has two altsettings, 0 and 1 */
Expand All @@ -829,12 +828,12 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
if (alt == 1) {
struct net_device *net;

if (!ncm->port.in) {
if (!ncm->port.in_ep->desc) {
DBG(cdev, "init ncm\n");
ncm->port.in = ep_choose(cdev->gadget,
ncm->port.in_ep->desc = ep_choose(cdev->gadget,
ncm->hs.in,
ncm->fs.in);
ncm->port.out = ep_choose(cdev->gadget,
ncm->port.out_ep->desc = ep_choose(cdev->gadget,
ncm->hs.out,
ncm->fs.out);
}
Expand Down Expand Up @@ -1111,7 +1110,7 @@ static void ncm_disable(struct usb_function *f)
if (ncm->notify->driver_data) {
usb_ep_disable(ncm->notify);
ncm->notify->driver_data = NULL;
ncm->notify_desc = NULL;
ncm->notify->desc = NULL;
}
}

Expand Down Expand Up @@ -1288,9 +1287,9 @@ ncm_bind(struct usb_configuration *c, struct usb_function *f)
/* we might as well release our claims on endpoints */
if (ncm->notify)
ncm->notify->driver_data = NULL;
if (ncm->port.out)
if (ncm->port.out_ep->desc)
ncm->port.out_ep->driver_data = NULL;
if (ncm->port.in)
if (ncm->port.in_ep->desc)
ncm->port.in_ep->driver_data = NULL;

ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
Expand Down
6 changes: 3 additions & 3 deletions drivers/usb/gadget/f_obex.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ static int obex_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
gserial_disconnect(&obex->port);
}

if (!obex->port.in_desc) {
if (!obex->port.in->desc) {
DBG(cdev, "init obex ttyGS%d\n", obex->port_num);
obex->port.in_desc = ep_choose(cdev->gadget,
obex->port.in->desc = ep_choose(cdev->gadget,
obex->hs.obex_in, obex->fs.obex_in);
obex->port.out_desc = ep_choose(cdev->gadget,
obex->port.out->desc = ep_choose(cdev->gadget,
obex->hs.obex_out, obex->fs.obex_out);
}

Expand Down
9 changes: 4 additions & 5 deletions drivers/usb/gadget/f_phonet.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,17 +427,16 @@ static int pn_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
spin_lock(&port->lock);
__pn_reset(f);
if (alt == 1) {
struct usb_endpoint_descriptor *out, *in;
int i;

out = ep_choose(gadget,
fp->out_ep->desc = ep_choose(gadget,
&pn_hs_sink_desc,
&pn_fs_sink_desc);
in = ep_choose(gadget,
fp->in_ep->desc = ep_choose(gadget,
&pn_hs_source_desc,
&pn_fs_source_desc);
usb_ep_enable(fp->out_ep, out);
usb_ep_enable(fp->in_ep, in);
usb_ep_enable(fp->out_ep);
usb_ep_enable(fp->in_ep);

port->usb = fp;
fp->out_ep->driver_data = fp;
Expand Down
15 changes: 7 additions & 8 deletions drivers/usb/gadget/f_rndis.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ struct f_rndis {
struct rndis_ep_descs hs;

struct usb_ep *notify;
struct usb_endpoint_descriptor *notify_desc;
struct usb_request *notify_req;
atomic_t notify_count;
};
Expand Down Expand Up @@ -486,11 +485,11 @@ static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
usb_ep_disable(rndis->notify);
} else {
VDBG(cdev, "init rndis ctrl %d\n", intf);
rndis->notify_desc = ep_choose(cdev->gadget,
rndis->notify->desc = ep_choose(cdev->gadget,
rndis->hs.notify,
rndis->fs.notify);
}
usb_ep_enable(rndis->notify, rndis->notify_desc);
usb_ep_enable(rndis->notify);
rndis->notify->driver_data = rndis;

} else if (intf == rndis->data_id) {
Expand All @@ -501,11 +500,11 @@ static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
gether_disconnect(&rndis->port);
}

if (!rndis->port.in) {
if (!rndis->port.in_ep->desc) {
DBG(cdev, "init rndis\n");
rndis->port.in = ep_choose(cdev->gadget,
rndis->port.in_ep->desc = ep_choose(cdev->gadget,
rndis->hs.in, rndis->fs.in);
rndis->port.out = ep_choose(cdev->gadget,
rndis->port.out_ep->desc = ep_choose(cdev->gadget,
rndis->hs.out, rndis->fs.out);
}

Expand Down Expand Up @@ -738,9 +737,9 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
/* we might as well release our claims on endpoints */
if (rndis->notify)
rndis->notify->driver_data = NULL;
if (rndis->port.out)
if (rndis->port.out_ep->desc)
rndis->port.out_ep->driver_data = NULL;
if (rndis->port.in)
if (rndis->port.in_ep->desc)
rndis->port.in_ep->driver_data = NULL;

ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
Expand Down
Loading

0 comments on commit 72c973d

Please sign in to comment.