usb: gadget: aspeed: Bug fixes
Subsystems (2)
cover usb: gadget: aspeed: Bug fixes
So I finally got back an Aspeed eval board, and thus resumed maintaining and handling bug reports for this driver.
This is a series that fixes a number of enumeration related issues with a variety of hosts, OSes, and circumstances (ie, plugging/unplugging at funny times, etc...).
I also added dummy support for the TT requests, it doesn't hurt as some host seem to send them even when TT support isn't advertized.
Most of this is bug fixes and probably shouldn't wait for another merge window, except possibly the last 2 patches.
v2: - Fix a space vs. tab issue in patch 2 reported by Sergei Shtylyov
- Put the TT patches at the end of the list as they aren't as clear cut "bug fixes".
PATCH v2 1/12 usb: gadget: aspeed: Don't set port enable change bit on reset
This bit should be only set when the port enable goes down, for example, on errors. Not when it gets set after a port reset. Some USB stacks seem to be sensitive to this and fails enumeration.
--- drivers/usb/gadget/udc/aspeed-vhub/hub.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/usb/gadget/udc/aspeed-vhub/hub.c +8 -1
@@ -449,8 +449,15 @@ static void ast_vhub_change_port_stat(struct ast_vhub *vhub,USB_PORT_STAT_C_OVERCURRENT |USB_PORT_STAT_C_RESET |USB_PORT_STAT_C_L1 ; - p->change |= chg; +/* +* We only set USB_PORT_STAT_C_ENABLE if we are disabling +* the port as per USB spec, otherwise MacOS gets upset +*/ +if (p->status &USB_PORT_STAT_ENABLE ) + chg &= ~USB_PORT_STAT_C_ENABLE ; + + p->change = chg;ast_vhub_update_hub_ep1 (vhub, port); } }
Signature · 1 line
2.17.1
PATCH v2 2/12 usb: gadget: aspeed: Cleanup EP0 state on port reset
In reply to Benjamin HerrenschmidtOtherwise, we can have a stale state after a disconnect and reconnect causing errors on the first SETUP packet to the device.
--- drivers/usb/gadget/udc/aspeed-vhub/dev.c | 3 +++ drivers/usb/gadget/udc/aspeed-vhub/ep0.c | 9 +++++++++ drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 1 + 3 files changed, 13 insertions(+)
drivers/usb/gadget/udc/aspeed-vhub/dev.c +3 -0
@@ -55,6 +55,9 @@ static void ast_vhub_dev_enable(struct ast_vhub_dev *d)if (d->enabled)return ; +/* Cleanup EP0 state */ +ast_vhub_reset_ep0 (d); +/* Enable device and its EP0 interrupts */ reg =VHUB_DEV_EN_ENABLE_PORT | VHUB_DEV_EN_EP0_IN_ACK_IRQEN |
drivers/usb/gadget/udc/aspeed-vhub/ep0.c +9 -0
@@ -459,6 +459,15 @@ static const struct usb_ep_ops ast_vhub_ep0_ops = { .free_request = ast_vhub_free_request, }; +void ast_vhub_reset_ep0 (struct ast_vhub_dev *dev) +{ +struct ast_vhub_ep *ep = &dev->ep0; + +ast_vhub_nuke (ep, -EIO ); + ep->ep0.state = ep0_state_token; +} + +void ast_vhub_init_ep0 (struct ast_vhub *vhub,struct ast_vhub_ep *ep,struct ast_vhub_dev *dev) {
drivers/usb/gadget/udc/aspeed-vhub/vhub.h +1 -0
@@ -507,6 +507,7 @@ void ast_vhub_init_hw(struct ast_vhub *vhub);/* ep0.c */ void ast_vhub_ep0_handle_ack (struct ast_vhub_ep *ep,bool in_ack);void ast_vhub_ep0_handle_setup (struct ast_vhub_ep *ep); +void ast_vhub_reset_ep0 (struct ast_vhub_dev *dev);void ast_vhub_init_ep0 (struct ast_vhub *vhub,struct ast_vhub_ep *ep,struct ast_vhub_dev *dev);int ast_vhub_reply (struct ast_vhub_ep *ep,char *ptr,int len);
Signature · 1 line
2.17.1
PATCH v2 3/12 usb: gadget: aspeed: Fix EP0 stall handling
In reply to Benjamin HerrenschmidtWhen stalling EP0, we need to wait for an ACK interrupt, otherwise we may get out of sync on the next setup packet data phase. Also we need to ignore the direction when processing that interrupt as the HW reports a potential mismatch.
Implement this by adding a stall state to EP0. This fixes some reported issues with mass storage and some hosts.
--- drivers/usb/gadget/udc/aspeed-vhub/ep0.c | 48 +++++++++++++++-------- drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 1 + 2 files changed, 33 insertions(+), 16 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/ep0.c +32 -16
@@ -105,18 +105,20 @@ void ast_vhub_ep0_handle_setup(struct ast_vhub_ep *ep) (crq.bRequestType &USB_DIR_IN ) ?"in" :"out" , ep->ep0.state); -/* Check our state, cancel pending requests if needed */ -if (ep->ep0.state != ep0_state_token) { +/* +* Check our state, cancel pending requests if needed +* +* Note: Under some circumstances, we can get a new setup +* packet while waiting for the stall ack, just accept it. +* +* In any case, a SETUP packet in wrong state should have +* reset the HW state machine, so let's just log, nuke +* requests, move on. +*/ +if (ep->ep0.state != ep0_state_token && + ep->ep0.state != ep0_state_stall) {EPDBG (ep,"wrong state\n" );ast_vhub_nuke (ep, -EIO ); - -/* -* Accept the packet regardless, this seems to happen -* when stalling a SETUP packet that has an OUT data -* phase. -*/ -ast_vhub_nuke (ep,0 ); - goto stall; }/* Calculate next state for EP0 */
@@ -165,7 +167,7 @@ void ast_vhub_ep0_handle_setup(struct ast_vhub_ep *ep) stall:EPDBG (ep,"stalling\n" );writel (VHUB_EP0_CTRL_STALL , ep->ep0.ctlstat); - ep->ep0.state = ep0_state_status; + ep->ep0.state = ep0_state_stall; ep->ep0.dir_in = false;return ;
@@ -299,8 +301,8 @@ void ast_vhub_ep0_handle_ack(struct ast_vhub_ep *ep, bool in_ack)if ((ep->ep0.dir_in && (stat &VHUB_EP0_TX_BUFF_RDY )) || (!ep->ep0.dir_in && (stat &VHUB_EP0_RX_BUFF_RDY )) || (ep->ep0.dir_in != in_ack)) { +/* In that case, ignore interrupt */ dev_warn (dev,"irq state mismatch" ); - stall = true;break ; }/*
@@ -335,12 +337,22 @@ void ast_vhub_ep0_handle_ack(struct ast_vhub_ep *ep, bool in_ack)dev_warn (dev,"status direction mismatch\n" ); stall = true; } +break ; +case ep0_state_stall: +/* +* There shouldn't be any request left, but nuke just in case +* otherwise the stale request will block subsequent ones +*/ +ast_vhub_nuke (ep, -EIO ); +break ; } -/* Reset to token state */ - ep->ep0.state = ep0_state_token; -if (stall) +/* Reset to token state or stall */ +if (stall) {writel (VHUB_EP0_CTRL_STALL , ep->ep0.ctlstat); + ep->ep0.state = ep0_state_stall; + }else + ep->ep0.state = ep0_state_token; } static int ast_vhub_ep0_queue(struct usb_ep* u_ep, struct usb_request *u_req,
@@ -390,8 +402,12 @@ static int ast_vhub_ep0_queue(struct usb_ep* u_ep, struct usb_request *u_req,spin_lock_irqsave (&vhub->lock, flags);/* EP0 can only support a single request at a time */ -if (!list_empty (&ep->queue) || ep->ep0.state == ep0_state_token) { +if (!list_empty (&ep->queue) || + ep->ep0.state == ep0_state_token || + ep->ep0.state == ep0_state_stall) {dev_warn (dev,"EP0: Request in wrong state\n" ); +EPVDBG (ep,"EP0: list_empty=%d state=%d\n" , +list_empty (&ep->queue), ep->ep0.state);spin_unlock_irqrestore (&vhub->lock, flags);return -EBUSY ; }
drivers/usb/gadget/udc/aspeed-vhub/vhub.h +1 -0
@@ -257,6 +257,7 @@ enum ep0_state { ep0_state_token, ep0_state_data, ep0_state_status, + ep0_state_stall, };/*
Signature · 1 line
2.17.1
PATCH v2 4/12 usb: gadget: aspeed: Improve debugging when nuking
In reply to Benjamin HerrenschmidtWhen nuking requests, it's useful to display how many were actually nuked. It has proven handy when debugging issues where EP0 went in a wrong state.
--- drivers/usb/gadget/udc/aspeed-vhub/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/core.c +5 -2
@@ -65,13 +65,16 @@ void ast_vhub_done(struct ast_vhub_ep *ep, struct ast_vhub_req *req,void ast_vhub_nuke (struct ast_vhub_ep *ep,int status) {struct ast_vhub_req *req; - -EPDBG (ep,"Nuking\n" ); +int count =0 ;/* Beware, lock will be dropped & req-acquired by done() */ while (!list_empty (&ep->queue)) { req = list_first_entry(&ep->queue, struct ast_vhub_req, queue);ast_vhub_done (ep, req, status); + count++; + } +if (count) { +EPDBG (ep,"Nuked %d request(s)\n" , count); } }
Signature · 1 line
2.17.1
Re: [PATCH v2 04/12] usb: gadget: aspeed: Improve debugging when nuking
Quoted 19 lines · Benjamin Herrenschmidt
When nuking requests, it's useful to display how many were actually nuked. It has proven handy when debugging issues where EP0 went in a wrong state.
Signed-off-by Benjamin Herrenschmidt <[email protected]>--- drivers/usb/gadget/udc/aspeed-vhub/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/usb/gadget/udc/aspeed-vhub/core.c +0
-2@@ -65,13 +65,16 @@ void ast_vhub_done(struct ast_vhub_ep *ep, struct ast_vhub_req *req,void ast_vhub_nuke (struct ast_vhub_ep *ep,int status) {struct ast_vhub_req *req; - -EPDBG (ep,"Nuking\n" );
drivers/usb/gadget/udc/aspeed-vhub/core.c void ast_vhub_done(struct ast_vhub_ep *ep, struct ast_vhub_req *req, · line 77
Quoted 10 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +5
-0+int count =0 ;/* Beware, lock will be dropped & req-acquired by done() */ while (!list_empty (&ep->queue)) { req = list_first_entry(&ep->queue, struct ast_vhub_req, queue);ast_vhub_done (ep, req, status); + count++; + } +if (count) { +EPDBG (ep,"Nuked %d request(s)\n" , count);
CodingStyle says to avoid {} around a single statement.
drivers/usb/gadget/udc/aspeed-vhub/core.c void ast_vhub_done(struct ast_vhub_ep *ep, struct ast_vhub_req *req, · line 80
Quoted 3 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +0
-0} }
MBR, Sergei
Re: [PATCH v2 04/12] usb: gadget: aspeed: Improve debugging when nuking
Quoted 23 lines · Sergei Shtylyov
Quoted 23 lines
When nuking requests, it's useful to display how many were actually nuked. It has proven handy when debugging issues where EP0 went in a wrong state.
Signed-off-by Benjamin Herrenschmidt <[email protected]>---
drivers/usb/gadget/udc/aspeed-vhub/core.c| 7 +++++--1 file changed, 5 insertions(+), 2 deletions(-)drivers/usb/gadget/udc/aspeed-vhub/core.c +1
-2@@ -65,13 +65,16 @@ void ast_vhub_done(struct ast_vhub_ep *ep, structast_vhub_req *req, void ast_vhub_nuke(struct ast_vhub_ep *ep, int status) { struct ast_vhub_req *req; - - EPDBG(ep, "Nuking\n"); + int count = 0; /* Beware, lock will be dropped & req-acquired by done() */ while (!list_empty(&ep->queue)) {
Quoted 8 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c void ast_vhub_done(struct ast_vhub_ep *ep, struct ast_vhub_req *req, · line 77
Quoted 6 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +4
-0req = list_first_entry(&ep->queue, struct ast_vhub_req, queue); ast_vhub_done(ep, req, status); + count++; + } + if (count) { + EPDBG(ep, "Nuked %d request(s)\n", count);CodingStyle says to avoid {} around a single statement.
I somehow missed this in v1 posting, sorry about that.
Quoted 2 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c void ast_vhub_done(struct ast_vhub_ep *ep, struct · line 79
Quoted 2 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +0
-0} }
MBR, Sergei
Re: [PATCH v2 04/12] usb: gadget: aspeed: Improve debugging when nuking
Quoted 35 lines · Sergei Shtylyov
Quoted 24 lines · Sergei Shtylyov
Quoted 24 lines
When nuking requests, it's useful to display how many were actually nuked. It has proven handy when debugging issues where EP0 went in a wrong state.
Signed-off-by Benjamin Herrenschmidt <[email protected]>--- drivers/usb/gadget/udc/aspeed-vhub/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/usb/gadget/udc/aspeed-vhub/core.c +1
-2@@ -65,13 +65,16 @@ void ast_vhub_done(struct ast_vhub_ep *ep, structast_vhub_req *req, void ast_vhub_nuke(struct ast_vhub_ep *ep, int status) { struct ast_vhub_req *req; - -EPDBG (ep,"Nuking\n" ); +int count =0 ;/* Beware, lock will be dropped & req-acquired by done() */ while (!list_empty (&ep->queue)) {Quoted 8 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c void ast_vhub_done(struct ast_vhub_ep *ep, struct ast_vhub_req *req, · line 77
Quoted 6 lines
drivers/usb/gadget/udc/aspeed-vhub/core.c +4
-0req = list_first_entry(&ep->queue, struct ast_vhub_req, queue);ast_vhub_done (ep, req, status); + count++; + } +if (count) { +EPDBG (ep,"Nuked %d request(s)\n" , count);CodingStyle says to avoid {} around a single statement.
Quoted 1 line
I somehow missed this in v1 posting, sorry about that.
Yeah well ... there used to be more in there, forgot to remove the {} when I stripped it down. I'm not going to respin for something so trivial unless something else shows up.
Felipe, what's your situation with getting those patches ? I haven't heard for you in a couple of weeks...
Cheers,
Ben.
PATCH v2 5/12 usb: gadget: aspeed: Don't reject requests on suspended devices
In reply to Benjamin HerrenschmidtA disconnect may just suspend the hub in absence of a physical disconnect detection. If we start rejecting requests, the mass storage function gets into a spin trying to requeue the same request for ever and hangs.
--- drivers/usb/gadget/udc/aspeed-vhub/dev.c | 13 +++++++++---- drivers/usb/gadget/udc/aspeed-vhub/ep0.c | 2 +- drivers/usb/gadget/udc/aspeed-vhub/epn.c | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/dev.c +9 -4
@@ -204,14 +204,19 @@ int ast_vhub_std_dev_request(struct ast_vhub_ep *ep,u16 wValue, wIndex;/* No driver, we shouldn't be enabled ... */ -if (!d->driver || !d->enabled || d->suspended) { +if (!d->driver || !d->enabled) {EPDBG (ep, -"Device is wrong state driver=%p enabled=%d" -" suspended=%d\n" , - d->driver, d->enabled, d->suspended); +"Device is wrong state driver=%p enabled=%d\n" , + d->driver, d->enabled);return std_req_stall; } +/* +* Note: we used to reject/stall requests while suspended, +* we don't do that anymore as we seem to have cases of +* mass storage getting very upset. +*/ +/* First packet, grab speed */ if (d->gadget.speed ==USB_SPEED_UNKNOWN ) { d->gadget.speed = ep->vhub->speed;
drivers/usb/gadget/udc/aspeed-vhub/ep0.c +1 -1
@@ -379,7 +379,7 @@ static int ast_vhub_ep0_queue(struct usb_ep* u_ep, struct usb_request *u_req,return -EINVAL ;/* Disabled device */ -if (ep->dev && (!ep->dev->enabled || ep->dev->suspended)) +if (ep->dev && !ep->dev->enabled)return -ESHUTDOWN ;/* Data, no buffer and not internal ? */
drivers/usb/gadget/udc/aspeed-vhub/epn.c +1 -1
@@ -352,7 +352,7 @@ static int ast_vhub_epn_queue(struct usb_ep* u_ep, struct usb_request *u_req,/* Endpoint enabled ? */ if (!ep->epn.enabled || !u_ep->desc || !ep->dev || !ep->d_idx || - !ep->dev->enabled || ep->dev->suspended) { + !ep->dev->enabled) {EPDBG (ep,"Enqueuing request on wrong or disabled EP\n" );return -ESHUTDOWN ; }
Signature · 1 line
2.17.1
PATCH v2 6/12 usb: gadget: aspeed: Check suspend/resume callback existence
In reply to Benjamin Herrenschmidt.. before calling them
--- drivers/usb/gadget/udc/aspeed-vhub/dev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/dev.c +2 -2
@@ -458,7 +458,7 @@ static const struct usb_gadget_ops ast_vhub_udc_ops = {void ast_vhub_dev_suspend (struct ast_vhub_dev *d) { d->suspended = true; -if (d->driver) { +if (d->driver && d->driver->suspend) {spin_unlock (&d->vhub->lock); d->driver->suspend (&d->gadget);spin_lock (&d->vhub->lock);
@@ -468,7 +468,7 @@ void ast_vhub_dev_suspend(struct ast_vhub_dev *d)void ast_vhub_dev_resume (struct ast_vhub_dev *d) { d->suspended = false; -if (d->driver) { +if (d->driver && d->driver->resume) {spin_unlock (&d->vhub->lock); d->driver->resume (&d->gadget);spin_lock (&d->vhub->lock);
Signature · 1 line
2.17.1
PATCH v2 7/12 usb: gadget: aspeed: Rework the reset logic
In reply to Benjamin HerrenschmidtWe had some dodgy code using the speed setting to decide whether a port reset would reset the device or just enable it.
Instead, if the device is disabled and has a gadget attached, a reset will enable it. If it's already enabled, a reset will reset it.
--- drivers/usb/gadget/udc/aspeed-vhub/dev.c | 58 +++++++++++------------- 1 file changed, 27 insertions(+), 31 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/dev.c +27 -31
@@ -50,7 +50,7 @@ void ast_vhub_dev_irq(struct ast_vhub_dev *d)static void ast_vhub_dev_enable (struct ast_vhub_dev *d) { -u32 reg, hmsk; +u32 reg, hmsk, i;if (d->enabled)return ;
@@ -76,6 +76,20 @@ static void ast_vhub_dev_enable(struct ast_vhub_dev *d)/* Set EP0 DMA buffer address */ writel (d->ep0.buf_dma, d->regs +AST_VHUB_DEV_EP0_DATA ); +/* Clear stall on all EPs */ +for (i =0 ; i < AST_VHUB_NUM_GEN_EPs; i++) { +struct ast_vhub_ep *ep = d->epns[i]; + +if (ep && (ep->epn.stalled || ep->epn.wedged)) { + ep->epn.stalled = false; + ep->epn.wedged = false; +ast_vhub_update_epn_stall (ep); + } + } + +/* Additional cleanups */ + d->wakeup_en = false; + d->suspended = false; d->enabled = true; }
@@ -477,46 +491,28 @@ void ast_vhub_dev_resume(struct ast_vhub_dev *d)void ast_vhub_dev_reset (struct ast_vhub_dev *d) { -/* -* If speed is not set, we enable the port. If it is, -* send reset to the gadget and reset "speed". -* -* Speed is an indication that we have got the first -* setup packet to the device. -*/ -if (d->gadget.speed ==USB_SPEED_UNKNOWN && !d->enabled) { -DDBG (d,"Reset at unknown speed of disabled device, enabling...\n" ); -ast_vhub_dev_enable (d); - d->suspended = false; +/* No driver, just disable the device and return */ +if (!d->driver) { +ast_vhub_dev_disable (d); +return ; } -if (d->gadget.speed !=USB_SPEED_UNKNOWN && d->driver) { -unsigned int i; -DDBG (d,"Reset at known speed of bound device, resetting...\n" ); +/* If the port isn't enabled, just enable it */ +if (!d->enabled) { +DDBG (d,"Reset of disabled device, enabling...\n" ); +ast_vhub_dev_enable (d); + }else { +DDBG (d,"Reset of enabled device, resetting...\n" );spin_unlock (&d->vhub->lock); - d->driver->reset (&d->gadget); +usb_gadget_udc_reset (&d->gadget, d->driver);spin_lock (&d->vhub->lock);/* -* Disable/re-enable HW, this will clear the address +* Disable and maybe re-enable HW, this will clear the address * and speed setting. */ ast_vhub_dev_disable (d);ast_vhub_dev_enable (d); - -/* Clear stall on all EPs */ -for (i =0 ; i < AST_VHUB_NUM_GEN_EPs; i++) { -struct ast_vhub_ep *ep = d->epns[i]; - -if (ep && ep->epn.stalled) { - ep->epn.stalled = false; -ast_vhub_update_epn_stall (ep); - } - } - -/* Additional cleanups */ - d->wakeup_en = false; - d->suspended = false; } }
Signature · 1 line
2.17.1
PATCH v2 8/12 usb: gadget: aspeed: Remove unused "suspended" flag
In reply to Benjamin HerrenschmidtThe state bit in the hub is sufficient
--- drivers/usb/gadget/udc/aspeed-vhub/dev.c | 4 ---- drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 1 - 2 files changed, 5 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/dev.c +0 -4
@@ -89,7 +89,6 @@ static void ast_vhub_dev_enable(struct ast_vhub_dev *d)/* Additional cleanups */ d->wakeup_en = false; - d->suspended = false; d->enabled = true; }
@@ -110,7 +109,6 @@ static void ast_vhub_dev_disable(struct ast_vhub_dev *d)writel (0 , d->regs +AST_VHUB_DEV_EN_CTRL ); d->gadget.speed =USB_SPEED_UNKNOWN ; d->enabled = false; - d->suspended = false; } static int ast_vhub_dev_feature(struct ast_vhub_dev *d,
@@ -471,7 +469,6 @@ static const struct usb_gadget_ops ast_vhub_udc_ops = {void ast_vhub_dev_suspend (struct ast_vhub_dev *d) { - d->suspended = true;if (d->driver && d->driver->suspend) {spin_unlock (&d->vhub->lock); d->driver->suspend (&d->gadget);
@@ -481,7 +478,6 @@ void ast_vhub_dev_suspend(struct ast_vhub_dev *d)void ast_vhub_dev_resume (struct ast_vhub_dev *d) { - d->suspended = false;if (d->driver && d->driver->resume) {spin_unlock (&d->vhub->lock); d->driver->resume (&d->gadget);
drivers/usb/gadget/udc/aspeed-vhub/vhub.h +0 -1
@@ -354,7 +354,6 @@ struct ast_vhub_dev {struct usb_gadget_driver *driver; bool registered : 1; bool wakeup_en : 1; - bool suspended : 1; bool enabled : 1;/* Endpoint structures */
Signature · 1 line
2.17.1
PATCH v2 9/12 usb: gadget: composite: Clear "suspended" on reset/disconnect
In reply to Benjamin HerrenschmidtIn some cases, one can get out of suspend with a reset or a disconnect followed by a reconnect. Previously we would leave a stale suspended flag set.
--- drivers/usb/gadget/composite.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/gadget/composite.c +1 -0
@@ -1976,6 +1976,7 @@ void composite_disconnect(struct usb_gadget *gadget)* disconnect callbacks? */ spin_lock_irqsave (&cdev->lock, flags); + cdev->suspended =0 ;if (cdev->config)reset_config (cdev);if (cdev->driver->disconnect)
Signature · 1 line
2.17.1
PATCH v2 10/12 usb: gadget: mass_storage: Fix races between fsg_disable and fsg_set_alt
In reply to Benjamin HerrenschmidtIf fsg_disable() and fsg_set_alt() are called too closely to each other (for example due to a quick reset/reconnect), what can happen is that fsg_set_alt sets common->new_fsg from an interrupt while handle_exception is trying to process the config change caused by fsg_disable():
fsg_disable()
...
handle_exception()
sets state back to FSG_STATE_NORMAL hasn't yet called do_set_interface() or is inside it.
---> interrupt
fsg_set_alt sets common->new_fsg queues a new FSG_STATE_CONFIG_CHANGE
<---
Now, the first handle_exception can "see" the updated new_fsg, treats it as if it was a fsg_set_alt() response, call usb_composite_setup_continue() etc...
But then, the thread sees the second FSG_STATE_CONFIG_CHANGE, and goes back down the same path, wipes and reattaches a now active fsg, and .. calls usb_composite_setup_continue() which at this point is wrong.
Not only we get a backtrace, but I suspect the second set_interface wrecks some state causing the host to get upset in my case.
This fixes it by replacing "new_fsg" by a "state argument" (same principle) which is set in the same lock section as the state update, and retrieved similarly.
That way, there is never any discrepancy between the dequeued state and the observed value of it. We keep the ability to have the latest reconfig operation take precedence, but we guarantee that once "dequeued" the argument (new_fsg) will not be clobbered by any new event.
--- drivers/usb/gadget/function/f_mass_storage.c | 28 +++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/usb/gadget/function/f_mass_storage.c +18 -10
@@ -261,7 +261,7 @@ struct fsg_common;struct fsg_common {struct usb_gadget *gadget;struct usb_composite_dev *cdev; -struct fsg_dev *fsg, *new_fsg; +struct fsg_dev *fsg;wait_queue_head_t io_wait;wait_queue_head_t fsg_wait;
@@ -290,6 +290,7 @@ struct fsg_common {unsigned int bulk_out_maxpacket;enum fsg_state state;/* For exception handling */ unsigned int exception_req_tag; +void *exception_arg;enum data_direction data_dir;u32 data_size;
@@ -391,7 +392,8 @@ static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)/* These routines may be called in process context or in_irq */ -static void raise_exception (struct fsg_common *common,enum fsg_state new_state) +static void __raise_exception (struct fsg_common *common,enum fsg_state new_state, +void *arg) {unsigned long flags;
@@ -404,6 +406,7 @@ static void raise_exception(struct fsg_common *common, enum fsg_state new_state)if (common->state <= new_state) { common->exception_req_tag = common->ep0_req_tag; common->state = new_state; + common->exception_arg = arg;if (common->thread_task)send_sig_info (SIGUSR1 ,SEND_SIG_PRIV , common->thread_task);
@@ -411,6 +414,10 @@ static void raise_exception(struct fsg_common *common, enum fsg_state new_state)spin_unlock_irqrestore (&common->lock, flags); } +static void raise_exception (struct fsg_common *common,enum fsg_state new_state) +{ +__raise_exception (common, new_state,NULL ); +}/*-------------------------------------------------------------------------*/
@@ -2285,16 +2292,16 @@ static int do_set_interface(struct fsg_common *common, struct fsg_dev *new_fsg)static int fsg_set_alt (struct usb_function *f,unsigned intf,unsigned alt) {struct fsg_dev *fsg =fsg_from_func (f); - fsg->common->new_fsg = fsg; -raise_exception (fsg->common,FSG_STATE_CONFIG_CHANGE ); + +__raise_exception (fsg->common,FSG_STATE_CONFIG_CHANGE , fsg);return USB_GADGET_DELAYED_STATUS ; }static void fsg_disable (struct usb_function *f) {struct fsg_dev *fsg =fsg_from_func (f); - fsg->common->new_fsg =NULL ; -raise_exception (fsg->common,FSG_STATE_CONFIG_CHANGE ); + +__raise_exception (fsg->common,FSG_STATE_CONFIG_CHANGE ,NULL ); }
@@ -2307,6 +2314,7 @@ static void handle_exception(struct fsg_common *common)enum fsg_state old_state;struct fsg_lun *curlun;unsigned int exception_req_tag; +struct fsg_dev *new_fsg;/* * Clear the existing signals. Anything but SIGUSR1 is converted
@@ -2360,6 +2368,7 @@ static void handle_exception(struct fsg_common *common) common->next_buffhd_to_fill = &common->buffhds[0 ]; common->next_buffhd_to_drain = &common->buffhds[0 ]; exception_req_tag = common->exception_req_tag; + new_fsg = common->exception_arg; old_state = common->state; common->state =FSG_STATE_NORMAL ;
@@ -2413,8 +2422,8 @@ static void handle_exception(struct fsg_common *common)break ;case FSG_STATE_CONFIG_CHANGE : -do_set_interface (common, common->new_fsg); -if (common->new_fsg) +do_set_interface (common, new_fsg); +if (new_fsg)usb_composite_setup_continue (common->cdev);break ;
@@ -2989,8 +2998,7 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)DBG (fsg,"unbind\n" );if (fsg->common->fsg == fsg) { - fsg->common->new_fsg =NULL ; -raise_exception (fsg->common,FSG_STATE_CONFIG_CHANGE ); +__raise_exception (fsg->common,FSG_STATE_CONFIG_CHANGE ,NULL );/* FIXME: make interruptible or killable somehow? */ wait_event (common->fsg_wait, common->fsg != fsg); }
Signature · 1 line
2.17.1
PATCH v2 11/12 usb: Add definitions for the USB2.0 hub TT requests
In reply to Benjamin Herrenschmidt--- include/linux/usb/hcd.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/usb/hcd.h +4 -0
@@ -587,6 +587,10 @@ extern void usb_ep0_reinit(struct usb_device *);#define GetPortStatus HUB_CLASS_REQ(USB_DIR_IN, USB_RT_PORT, USB_REQ_GET_STATUS)#define SetHubFeature HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_HUB, USB_REQ_SET_FEATURE)#define SetPortFeature HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, USB_REQ_SET_FEATURE) +#define ClearTTBuffer HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, HUB_CLEAR_TT_BUFFER) +#define ResetTT HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, HUB_RESET_TT) +#define GetTTState HUB_CLASS_REQ(USB_DIR_IN, USB_RT_PORT, HUB_GET_TT_STATE) +#define StopTT HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, HUB_STOP_TT)/*-------------------------------------------------------------------------*/
Signature · 1 line
2.17.1
PATCH v2 12/12 usb: gadget: aspeed: Implement dummy hub TT requests
In reply to Benjamin HerrenschmidtWe just accept them instead of stalling and return zeros on GetTTState.
--- drivers/usb/gadget/udc/aspeed-vhub/hub.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/usb/gadget/udc/aspeed-vhub/hub.c +6 -0
@@ -730,6 +730,12 @@ enum std_req_rc ast_vhub_class_hub_request(struct ast_vhub_ep *ep,case ClearPortFeature:EPDBG (ep,"ClearPortFeature(%d,%d)\n" , wIndex &0xf , wValue);return ast_vhub_clr_port_feature (ep, wIndex &0xf , wValue); +case ClearTTBuffer: +case ResetTT: +case StopTT: +return std_req_complete; +case GetTTState: +return ast_vhub_simple_reply (ep,0 ,0 ,0 ,0 );default :EPDBG (ep,"Unknown class request\n" ); }
Signature · 1 line
2.17.1
Quoted 10 lines · Benjamin Herrenschmidt
So I finally got back an Aspeed eval board, and thus resumed maintaining and handling bug reports for this driver.
This is a series that fixes a number of enumeration related issues with a variety of hosts, OSes, and circumstances (ie, plugging/unplugging at funny times, etc...).
I also added dummy support for the TT requests, it doesn't hurt as some host seem to send them even when TT support isn't advertized.
Quoted 6 lines
Most of this is bug fixes and probably shouldn't wait for another merge window, except possibly the last 2 patches.
v2: - Fix a space vs. tab issue in patch 2 reported by Sergei Shtylyov
- Put the TT patches at the end of the list as they aren't as clear cut "bug fixes".
and
- Add the f_mass_storage fix that I posted separately and
accidentaly included in this resend... the patches are completely identical to the previously posted "v2" of those.
Cheers,
Ben.