diff mbox series

[02/10] usb: gadget: aspeed: Cleanup EP0 state on port reset

Message ID 20190706005345.18131-3-benh@kernel.crashing.org (mailing list archive)
State Superseded
Headers show
Series usb: gadget: aspeed: Bug fixes | expand

Commit Message

Benjamin Herrenschmidt July 6, 2019, 12:53 a.m. UTC
Otherwise, we can have a stale state after a disconnect and reconnect
causing errors on the first SETUP packet to the device.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 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(+)

Comments

Sergei Shtylyov July 6, 2019, 8:11 a.m. UTC | #1
Hello!

On 06.07.2019 3:53, Benjamin Herrenschmidt wrote:

> Otherwise, we can have a stale state after a disconnect and reconnect
> causing errors on the first SETUP packet to the device.
> 
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
[...]
> diff --git a/drivers/usb/gadget/udc/aspeed-vhub/ep0.c b/drivers/usb/gadget/udc/aspeed-vhub/ep0.c
> index e2927fb083cf..5054c6343ead 100644
> --- a/drivers/usb/gadget/udc/aspeed-vhub/ep0.c
> +++ b/drivers/usb/gadget/udc/aspeed-vhub/ep0.c
> @@ -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;

    This line is indented with spaces, previous with a tab.

> +}
> +
> +
>   void ast_vhub_init_ep0(struct ast_vhub *vhub, struct ast_vhub_ep *ep,
>   		       struct ast_vhub_dev *dev)
>   {
[...]

MBR, Sergei
Benjamin Herrenschmidt July 6, 2019, 12:34 p.m. UTC | #2
On Sat, 2019-07-06 at 11:11 +0300, Sergei Shtylyov wrote:
> Hello!
> 
> On 06.07.2019 3:53, Benjamin Herrenschmidt wrote:
> 
> > Otherwise, we can have a stale state after a disconnect and
> > reconnect
> > causing errors on the first SETUP packet to the device.
> > 
> > Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> 
> [...]
> > diff --git a/drivers/usb/gadget/udc/aspeed-vhub/ep0.c
> > b/drivers/usb/gadget/udc/aspeed-vhub/ep0.c
> > index e2927fb083cf..5054c6343ead 100644
> > --- a/drivers/usb/gadget/udc/aspeed-vhub/ep0.c
> > +++ b/drivers/usb/gadget/udc/aspeed-vhub/ep0.c
> > @@ -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;
> 
>     This line is indented with spaces, previous with a tab.

Thanks, will clean up.

Cheers,
Ben.
> 
> > +}
> > +
> > +
> >   void ast_vhub_init_ep0(struct ast_vhub *vhub, struct ast_vhub_ep
> > *ep,
> >   		       struct ast_vhub_dev *dev)
> >   {
> 
> [...]
> 
> MBR, Sergei
diff mbox series

Patch

diff --git a/drivers/usb/gadget/udc/aspeed-vhub/dev.c b/drivers/usb/gadget/udc/aspeed-vhub/dev.c
index 6b1b16b17d7d..678bbdbd0971 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/dev.c
+++ b/drivers/usb/gadget/udc/aspeed-vhub/dev.c
@@ -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 |
diff --git a/drivers/usb/gadget/udc/aspeed-vhub/ep0.c b/drivers/usb/gadget/udc/aspeed-vhub/ep0.c
index e2927fb083cf..5054c6343ead 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/ep0.c
+++ b/drivers/usb/gadget/udc/aspeed-vhub/ep0.c
@@ -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)
 {
diff --git a/drivers/usb/gadget/udc/aspeed-vhub/vhub.h b/drivers/usb/gadget/udc/aspeed-vhub/vhub.h
index 4ed03d33a5a9..2e7ef387f4f0 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/vhub.h
+++ b/drivers/usb/gadget/udc/aspeed-vhub/vhub.h
@@ -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);