From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 01/18] usb: gadget: fastboot: Allocate IN requests when needed
Date: Mon, 20 Mar 2023 16:29:24 +0100 [thread overview]
Message-ID: <20230320152941.3155428-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20230320152941.3155428-1-s.hauer@pengutronix.de>
fastboot_download_finished() calls fastboot_tx_print() two times in a
row and waits for completion in between. Additionally this is called
from the completion function from another request. This seems to work
for example on the fsl_udc driver, but leads to problems on the DWC3
controller. Instead of re-using the same request over and over again,
just allocate a new request when needed. This way we no longer have
to poll for its completion before starting a new request.
While fixing fastboot on the DWC3 controller this also makes the
lifetime of a request clearer.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/usb/gadget/f_fastboot.c | 54 ++++++++++++---------------------
1 file changed, 20 insertions(+), 34 deletions(-)
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 96924c4cb9..078b37ce54 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -39,7 +39,7 @@ struct f_fastboot {
/* IN/OUT EP's and corresponding requests */
struct usb_ep *in_ep, *out_ep;
- struct usb_request *in_req, *out_req;
+ struct usb_request *out_req;
struct work_queue wq;
};
@@ -134,10 +134,6 @@ static int fastboot_write_usb(struct fastboot *fb, const char *buffer,
unsigned int buffer_size);
static void fastboot_start_download_usb(struct fastboot *fb);
-static void fastboot_complete(struct usb_ep *ep, struct usb_request *req)
-{
-}
-
struct fastboot_work {
struct work_struct work;
struct f_fastboot *f_fb;
@@ -183,6 +179,17 @@ static struct usb_request *fastboot_alloc_request(struct usb_ep *ep)
return req;
}
+static void fastboot_free_request(struct usb_ep *ep, struct usb_request *req)
+{
+ free(req->buf);
+ usb_ep_free_request(ep, req);
+}
+
+static void fastboot_complete(struct usb_ep *ep, struct usb_request *req)
+{
+ fastboot_free_request(ep, req);
+}
+
static int fastboot_bind(struct usb_configuration *c, struct usb_function *f)
{
struct usb_composite_dev *cdev = c->cdev;
@@ -259,14 +266,6 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f)
f_fb->out_req->complete = rx_handler_command;
f_fb->out_req->context = f_fb;
- f_fb->in_req = fastboot_alloc_request(f_fb->in_ep);
- if (!f_fb->in_req) {
- puts("failed alloc req in\n");
- ret = -EINVAL;
- goto err_free_out_req;
- }
- f_fb->in_req->complete = fastboot_complete;
-
ret = usb_assign_descriptors(f, fb_fs_descs, fb_hs_descs, NULL);
if (ret)
goto err_free_in_req;
@@ -274,9 +273,6 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f)
return 0;
err_free_in_req:
- free(f_fb->in_req->buf);
- usb_ep_free_request(f_fb->in_ep, f_fb->in_req);
-err_free_out_req:
free(f_fb->out_req->buf);
usb_ep_free_request(f_fb->out_ep, f_fb->out_req);
fb_generic_free:
@@ -291,11 +287,6 @@ static void fastboot_unbind(struct usb_configuration *c, struct usb_function *f)
{
struct f_fastboot *f_fb = func_to_fastboot(f);
- usb_ep_dequeue(f_fb->in_ep, f_fb->in_req);
- free(f_fb->in_req->buf);
- usb_ep_free_request(f_fb->in_ep, f_fb->in_req);
- f_fb->in_req = NULL;
-
usb_ep_dequeue(f_fb->out_ep, f_fb->out_req);
free(f_fb->out_req->buf);
usb_ep_free_request(f_fb->out_ep, f_fb->out_req);
@@ -404,28 +395,23 @@ DECLARE_USB_FUNCTION_INIT(fastboot, fastboot_alloc_instance, fastboot_alloc_func
static int fastboot_write_usb(struct fastboot *fb, const char *buffer, unsigned int buffer_size)
{
struct f_fastboot *f_fb = container_of(fb, struct f_fastboot, fastboot);
- struct usb_request *in_req = f_fb->in_req;
- uint64_t start;
+ struct usb_request *in_req;
int ret;
+ in_req = fastboot_alloc_request(f_fb->in_ep);
+ if (!in_req)
+ return -ENOMEM;
+
memcpy(in_req->buf, buffer, buffer_size);
in_req->length = buffer_size;
+ in_req->complete = fastboot_complete;
ret = usb_ep_queue(f_fb->in_ep, in_req);
- if (ret)
+ if (ret) {
+ fastboot_free_request(f_fb->in_ep, in_req);
pr_err("Error %d on queue\n", ret);
-
- start = get_time_ns();
-
- while (in_req->status == -EINPROGRESS) {
- if (is_timeout(start, 2 * SECOND))
- return -ETIMEDOUT;
- usb_gadget_poll();
}
- if (in_req->status)
- pr_err("Failed to send answer: %d\n", in_req->status);
-
return 0;
}
--
2.30.2
next prev parent reply other threads:[~2023-03-20 15:31 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-20 15:29 [PATCH 00/18] USB gadget overhaul Sascha Hauer
2023-03-20 15:29 ` Sascha Hauer [this message]
2023-03-20 15:29 ` [PATCH 02/18] usb: gadget: drop gadget_chips.h Sascha Hauer
2023-03-20 15:29 ` [PATCH 03/18] usb: gadget: move files to place where Linux has them Sascha Hauer
2023-03-20 15:29 ` [PATCH 04/18] usb: move include " Sascha Hauer
2023-03-20 15:29 ` [PATCH 05/18] usb: ch9: Update from Linux Kernel Sascha Hauer
2023-03-20 15:29 ` [PATCH 06/18] phy: Add mode setting support Sascha Hauer
2023-03-20 15:29 ` [PATCH 07/18] driver: Add unregister_driver() Sascha Hauer
2023-03-20 15:43 ` Ahmad Fatoum
2023-03-21 8:07 ` Sascha Hauer
2023-03-20 15:29 ` [PATCH 08/18] usb: gadget: Update core to Linux-6.3-rc2 Sascha Hauer
2023-03-20 15:29 ` [PATCH 09/18] uuid.h: sync with Linux-6.3-rc2 Sascha Hauer
2023-03-20 15:29 ` [PATCH 10/18] usb: gadget: Add super-speed-plus descriptors Sascha Hauer
2023-03-20 15:29 ` [PATCH 11/18] usb: gadget: update composite.c from Linux-6.3-rc2 Sascha Hauer
2023-03-20 15:29 ` [PATCH 12/18] Add dev_WARN_ONCE() Sascha Hauer
2023-03-20 15:29 ` [PATCH 13/18] usb: dwc3: sync with Linux-6.3-rc2 Sascha Hauer
2023-03-20 15:29 ` [PATCH 14/18] usb: gadget: dfu: Assign super speed descriptors Sascha Hauer
2023-03-20 15:29 ` [PATCH 15/18] usb: gadget: fastboot: Add " Sascha Hauer
2023-03-22 8:28 ` Johannes Zink
2023-03-20 15:29 ` [PATCH 16/18] usb: gadget: mass storage: " Sascha Hauer
2023-03-20 15:29 ` [PATCH 17/18] usb: gadget: u_serial: Put back to list if shutdown Sascha Hauer
2023-03-20 15:29 ` [PATCH 18/18] usb: gadget multi: support USB Super Speed Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230320152941.3155428-2-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox