diff options
author | Sergei Shtylyov <sshtylyov@ru.mvista.com> | 2009-11-18 14:51:18 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-11-30 19:43:15 -0500 |
commit | cea83241b3a84499c4f9b12f8288f787e7aa6383 (patch) | |
tree | 3d26ab1e85646b401d80677fd45d847ab3fe9261 /drivers/usb | |
parent | c2f6595fbdb408d3d6850cfae590c8fa93e27399 (diff) |
USB: musb_gadget: fix STALL handling
The driver incorrectly cancels the mass-storage device CSW request
(which leads to device reset) due to giving back URB at the head of
endpoint's queue after sending each STALL handshake; stop doing that
and start checking for the queue being non-empty before stalling an
endpoint and disallowing stall in such case in musb_gadget_set_halt()
like the other gadget drivers do.
Moreover, the driver starts Rx request despite of the endpoint being
halted -- fix this by moving the SendStall bit check from musb_g_rx()
to rxstate(). And we also sometimes get into rxstate() with DMA still
active after clearing an endpoint's halt (not clear why), so bail out
in this case, similarly to what txstate() does...
While at it, also do the following changes :
- in musb_gadget_set_halt(), remove pointless Tx FIFO flushing (the
driver does not allow stalling with non-empty Tx FIFO anyway);
- in rxstate(), stop pointlessly zeroing the 'csr' variable;
- in musb_gadget_set_halt(), move the 'done' label to a more proper
place;
- in musb_g_rx(), eliminate the 'done' label completely...
Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Cc: <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/musb/musb_gadget.c | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index 8b3c4e2ed7b8..74073f9a43f0 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c | |||
@@ -4,6 +4,7 @@ | |||
4 | * Copyright 2005 Mentor Graphics Corporation | 4 | * Copyright 2005 Mentor Graphics Corporation |
5 | * Copyright (C) 2005-2006 by Texas Instruments | 5 | * Copyright (C) 2005-2006 by Texas Instruments |
6 | * Copyright (C) 2006-2007 Nokia Corporation | 6 | * Copyright (C) 2006-2007 Nokia Corporation |
7 | * Copyright (C) 2009 MontaVista Software, Inc. <source@mvista.com> | ||
7 | * | 8 | * |
8 | * This program is free software; you can redistribute it and/or | 9 | * This program is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU General Public License | 10 | * modify it under the terms of the GNU General Public License |
@@ -436,14 +437,6 @@ void musb_g_tx(struct musb *musb, u8 epnum) | |||
436 | csr |= MUSB_TXCSR_P_WZC_BITS; | 437 | csr |= MUSB_TXCSR_P_WZC_BITS; |
437 | csr &= ~MUSB_TXCSR_P_SENTSTALL; | 438 | csr &= ~MUSB_TXCSR_P_SENTSTALL; |
438 | musb_writew(epio, MUSB_TXCSR, csr); | 439 | musb_writew(epio, MUSB_TXCSR, csr); |
439 | if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) { | ||
440 | dma->status = MUSB_DMA_STATUS_CORE_ABORT; | ||
441 | musb->dma_controller->channel_abort(dma); | ||
442 | } | ||
443 | |||
444 | if (request) | ||
445 | musb_g_giveback(musb_ep, request, -EPIPE); | ||
446 | |||
447 | break; | 440 | break; |
448 | } | 441 | } |
449 | 442 | ||
@@ -582,15 +575,25 @@ void musb_g_tx(struct musb *musb, u8 epnum) | |||
582 | */ | 575 | */ |
583 | static void rxstate(struct musb *musb, struct musb_request *req) | 576 | static void rxstate(struct musb *musb, struct musb_request *req) |
584 | { | 577 | { |
585 | u16 csr = 0; | ||
586 | const u8 epnum = req->epnum; | 578 | const u8 epnum = req->epnum; |
587 | struct usb_request *request = &req->request; | 579 | struct usb_request *request = &req->request; |
588 | struct musb_ep *musb_ep = &musb->endpoints[epnum].ep_out; | 580 | struct musb_ep *musb_ep = &musb->endpoints[epnum].ep_out; |
589 | void __iomem *epio = musb->endpoints[epnum].regs; | 581 | void __iomem *epio = musb->endpoints[epnum].regs; |
590 | unsigned fifo_count = 0; | 582 | unsigned fifo_count = 0; |
591 | u16 len = musb_ep->packet_sz; | 583 | u16 len = musb_ep->packet_sz; |
584 | u16 csr = musb_readw(epio, MUSB_RXCSR); | ||
592 | 585 | ||
593 | csr = musb_readw(epio, MUSB_RXCSR); | 586 | /* We shouldn't get here while DMA is active, but we do... */ |
587 | if (dma_channel_status(musb_ep->dma) == MUSB_DMA_STATUS_BUSY) { | ||
588 | DBG(4, "DMA pending...\n"); | ||
589 | return; | ||
590 | } | ||
591 | |||
592 | if (csr & MUSB_RXCSR_P_SENDSTALL) { | ||
593 | DBG(5, "%s stalling, RXCSR %04x\n", | ||
594 | musb_ep->end_point.name, csr); | ||
595 | return; | ||
596 | } | ||
594 | 597 | ||
595 | if (is_cppi_enabled() && musb_ep->dma) { | 598 | if (is_cppi_enabled() && musb_ep->dma) { |
596 | struct dma_controller *c = musb->dma_controller; | 599 | struct dma_controller *c = musb->dma_controller; |
@@ -761,19 +764,10 @@ void musb_g_rx(struct musb *musb, u8 epnum) | |||
761 | csr, dma ? " (dma)" : "", request); | 764 | csr, dma ? " (dma)" : "", request); |
762 | 765 | ||
763 | if (csr & MUSB_RXCSR_P_SENTSTALL) { | 766 | if (csr & MUSB_RXCSR_P_SENTSTALL) { |
764 | if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) { | ||
765 | dma->status = MUSB_DMA_STATUS_CORE_ABORT; | ||
766 | (void) musb->dma_controller->channel_abort(dma); | ||
767 | request->actual += musb_ep->dma->actual_len; | ||
768 | } | ||
769 | |||
770 | csr |= MUSB_RXCSR_P_WZC_BITS; | 767 | csr |= MUSB_RXCSR_P_WZC_BITS; |
771 | csr &= ~MUSB_RXCSR_P_SENTSTALL; | 768 | csr &= ~MUSB_RXCSR_P_SENTSTALL; |
772 | musb_writew(epio, MUSB_RXCSR, csr); | 769 | musb_writew(epio, MUSB_RXCSR, csr); |
773 | 770 | return; | |
774 | if (request) | ||
775 | musb_g_giveback(musb_ep, request, -EPIPE); | ||
776 | goto done; | ||
777 | } | 771 | } |
778 | 772 | ||
779 | if (csr & MUSB_RXCSR_P_OVERRUN) { | 773 | if (csr & MUSB_RXCSR_P_OVERRUN) { |
@@ -795,7 +789,7 @@ void musb_g_rx(struct musb *musb, u8 epnum) | |||
795 | DBG((csr & MUSB_RXCSR_DMAENAB) ? 4 : 1, | 789 | DBG((csr & MUSB_RXCSR_DMAENAB) ? 4 : 1, |
796 | "%s busy, csr %04x\n", | 790 | "%s busy, csr %04x\n", |
797 | musb_ep->end_point.name, csr); | 791 | musb_ep->end_point.name, csr); |
798 | goto done; | 792 | return; |
799 | } | 793 | } |
800 | 794 | ||
801 | if (dma && (csr & MUSB_RXCSR_DMAENAB)) { | 795 | if (dma && (csr & MUSB_RXCSR_DMAENAB)) { |
@@ -826,22 +820,15 @@ void musb_g_rx(struct musb *musb, u8 epnum) | |||
826 | if ((request->actual < request->length) | 820 | if ((request->actual < request->length) |
827 | && (musb_ep->dma->actual_len | 821 | && (musb_ep->dma->actual_len |
828 | == musb_ep->packet_sz)) | 822 | == musb_ep->packet_sz)) |
829 | goto done; | 823 | return; |
830 | #endif | 824 | #endif |
831 | musb_g_giveback(musb_ep, request, 0); | 825 | musb_g_giveback(musb_ep, request, 0); |
832 | 826 | ||
833 | request = next_request(musb_ep); | 827 | request = next_request(musb_ep); |
834 | if (!request) | 828 | if (!request) |
835 | goto done; | 829 | return; |
836 | |||
837 | /* don't start more i/o till the stall clears */ | ||
838 | musb_ep_select(mbase, epnum); | ||
839 | csr = musb_readw(epio, MUSB_RXCSR); | ||
840 | if (csr & MUSB_RXCSR_P_SENDSTALL) | ||
841 | goto done; | ||
842 | } | 830 | } |
843 | 831 | ||
844 | |||
845 | /* analyze request if the ep is hot */ | 832 | /* analyze request if the ep is hot */ |
846 | if (request) | 833 | if (request) |
847 | rxstate(musb, to_musb_request(request)); | 834 | rxstate(musb, to_musb_request(request)); |
@@ -849,8 +836,6 @@ void musb_g_rx(struct musb *musb, u8 epnum) | |||
849 | DBG(3, "packet waiting for %s%s request\n", | 836 | DBG(3, "packet waiting for %s%s request\n", |
850 | musb_ep->desc ? "" : "inactive ", | 837 | musb_ep->desc ? "" : "inactive ", |
851 | musb_ep->end_point.name); | 838 | musb_ep->end_point.name); |
852 | |||
853 | done: | ||
854 | return; | 839 | return; |
855 | } | 840 | } |
856 | 841 | ||
@@ -1244,7 +1229,7 @@ int musb_gadget_set_halt(struct usb_ep *ep, int value) | |||
1244 | void __iomem *mbase; | 1229 | void __iomem *mbase; |
1245 | unsigned long flags; | 1230 | unsigned long flags; |
1246 | u16 csr; | 1231 | u16 csr; |
1247 | struct musb_request *request = NULL; | 1232 | struct musb_request *request; |
1248 | int status = 0; | 1233 | int status = 0; |
1249 | 1234 | ||
1250 | if (!ep) | 1235 | if (!ep) |
@@ -1260,24 +1245,29 @@ int musb_gadget_set_halt(struct usb_ep *ep, int value) | |||
1260 | 1245 | ||
1261 | musb_ep_select(mbase, epnum); | 1246 | musb_ep_select(mbase, epnum); |
1262 | 1247 | ||
1263 | /* cannot portably stall with non-empty FIFO */ | ||
1264 | request = to_musb_request(next_request(musb_ep)); | 1248 | request = to_musb_request(next_request(musb_ep)); |
1265 | if (value && musb_ep->is_in) { | 1249 | if (value) { |
1266 | csr = musb_readw(epio, MUSB_TXCSR); | 1250 | if (request) { |
1267 | if (csr & MUSB_TXCSR_FIFONOTEMPTY) { | 1251 | DBG(3, "request in progress, cannot halt %s\n", |
1268 | DBG(3, "%s fifo busy, cannot halt\n", ep->name); | 1252 | ep->name); |
1269 | spin_unlock_irqrestore(&musb->lock, flags); | 1253 | status = -EAGAIN; |
1270 | return -EAGAIN; | 1254 | goto done; |
1255 | } | ||
1256 | /* Cannot portably stall with non-empty FIFO */ | ||
1257 | if (musb_ep->is_in) { | ||
1258 | csr = musb_readw(epio, MUSB_TXCSR); | ||
1259 | if (csr & MUSB_TXCSR_FIFONOTEMPTY) { | ||
1260 | DBG(3, "FIFO busy, cannot halt %s\n", ep->name); | ||
1261 | status = -EAGAIN; | ||
1262 | goto done; | ||
1263 | } | ||
1271 | } | 1264 | } |
1272 | |||
1273 | } | 1265 | } |
1274 | 1266 | ||
1275 | /* set/clear the stall and toggle bits */ | 1267 | /* set/clear the stall and toggle bits */ |
1276 | DBG(2, "%s: %s stall\n", ep->name, value ? "set" : "clear"); | 1268 | DBG(2, "%s: %s stall\n", ep->name, value ? "set" : "clear"); |
1277 | if (musb_ep->is_in) { | 1269 | if (musb_ep->is_in) { |
1278 | csr = musb_readw(epio, MUSB_TXCSR); | 1270 | csr = musb_readw(epio, MUSB_TXCSR); |
1279 | if (csr & MUSB_TXCSR_FIFONOTEMPTY) | ||
1280 | csr |= MUSB_TXCSR_FLUSHFIFO; | ||
1281 | csr |= MUSB_TXCSR_P_WZC_BITS | 1271 | csr |= MUSB_TXCSR_P_WZC_BITS |
1282 | | MUSB_TXCSR_CLRDATATOG; | 1272 | | MUSB_TXCSR_CLRDATATOG; |
1283 | if (value) | 1273 | if (value) |
@@ -1300,14 +1290,13 @@ int musb_gadget_set_halt(struct usb_ep *ep, int value) | |||
1300 | musb_writew(epio, MUSB_RXCSR, csr); | 1290 | musb_writew(epio, MUSB_RXCSR, csr); |
1301 | } | 1291 | } |
1302 | 1292 | ||
1303 | done: | ||
1304 | |||
1305 | /* maybe start the first request in the queue */ | 1293 | /* maybe start the first request in the queue */ |
1306 | if (!musb_ep->busy && !value && request) { | 1294 | if (!musb_ep->busy && !value && request) { |
1307 | DBG(3, "restarting the request\n"); | 1295 | DBG(3, "restarting the request\n"); |
1308 | musb_ep_restart(musb, request); | 1296 | musb_ep_restart(musb, request); |
1309 | } | 1297 | } |
1310 | 1298 | ||
1299 | done: | ||
1311 | spin_unlock_irqrestore(&musb->lock, flags); | 1300 | spin_unlock_irqrestore(&musb->lock, flags); |
1312 | return status; | 1301 | return status; |
1313 | } | 1302 | } |