Commit 85b55d6f authored by David Brownell's avatar David Brownell Committed by Greg Kroah-Hartman

[PATCH] USB: net2280, control requests can be deferred

To handle control messaging in contexts other than the
IRQ handler's setup() callback, a bit of automagic needed
to be removed; and some minor bugs fixed.
parent c52b51d9
...@@ -1107,7 +1107,7 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -1107,7 +1107,7 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
} }
/* respond with data transfer before status phase? */ /* respond with data transfer before status phase? */
if (value > 0) { if (value >= 0) {
req->length = value; req->length = value;
value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC); value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
if (value < 0) { if (value < 0) {
......
...@@ -393,7 +393,7 @@ net2280_free_request (struct usb_ep *_ep, struct usb_request *_req) ...@@ -393,7 +393,7 @@ net2280_free_request (struct usb_ep *_ep, struct usb_request *_req)
struct net2280_request *req; struct net2280_request *req;
ep = container_of (_ep, struct net2280_ep, ep); ep = container_of (_ep, struct net2280_ep, ep);
if (!ep || !_req) if (!_ep || !_req)
return; return;
req = container_of (_req, struct net2280_request, req); req = container_of (_req, struct net2280_request, req);
...@@ -442,7 +442,7 @@ net2280_alloc_buffer ( ...@@ -442,7 +442,7 @@ net2280_alloc_buffer (
struct net2280_ep *ep; struct net2280_ep *ep;
ep = container_of (_ep, struct net2280_ep, ep); ep = container_of (_ep, struct net2280_ep, ep);
if (!ep || (!ep->desc && ep->num != 0)) if (!_ep || (!ep->desc && ep->num != 0))
return 0; return 0;
*dma = DMA_ADDR_INVALID; *dma = DMA_ADDR_INVALID;
...@@ -561,16 +561,12 @@ static void out_flush (struct net2280_ep *ep) ...@@ -561,16 +561,12 @@ static void out_flush (struct net2280_ep *ep)
writel ((1 << FIFO_FLUSH), statp); writel ((1 << FIFO_FLUSH), statp);
mb (); mb ();
tmp = readl (statp); tmp = readl (statp);
if (tmp & (1 << DATA_OUT_PING_TOKEN_INTERRUPT)) { if (tmp & (1 << DATA_OUT_PING_TOKEN_INTERRUPT)
/* high speed did bulk NYET; fifo isn't filling */
&& ep->dev->gadget.speed == USB_SPEED_FULL) {
unsigned usec; unsigned usec;
if (ep->dev->gadget.speed == USB_SPEED_HIGH) { usec = 50; /* 64 byte bulk/interrupt */
if (ep->ep.maxpacket <= 512)
usec = 10; /* 512 byte bulk */
else
usec = 21; /* 1024 byte interrupt */
} else
usec = 50; /* 64 byte bulk/interrupt */
handshake (statp, (1 << USB_OUT_PING_NAK_SENT), handshake (statp, (1 << USB_OUT_PING_NAK_SENT),
(1 << USB_OUT_PING_NAK_SENT), usec); (1 << USB_OUT_PING_NAK_SENT), usec);
/* NAK done; now CLEAR_NAK_OUT_PACKETS is safe */ /* NAK done; now CLEAR_NAK_OUT_PACKETS is safe */
...@@ -614,15 +610,13 @@ read_fifo (struct net2280_ep *ep, struct net2280_request *req) ...@@ -614,15 +610,13 @@ read_fifo (struct net2280_ep *ep, struct net2280_request *req)
count = readl (&regs->ep_avail); count = readl (&regs->ep_avail);
tmp = req->req.length - req->req.actual; tmp = req->req.length - req->req.actual;
if (count > tmp) { if (count > tmp) {
unsigned over = tmp % ep->ep.maxpacket; /* as with DMA, data overflow gets flushed */
if ((tmp % ep->ep.maxpacket) != 0) {
/* FIXME handle this consistently between PIO and DMA */
if (over) {
ERROR (ep->dev, ERROR (ep->dev,
"%s out fifo %d bytes, over %d extra %d\n", "%s out fifo %d bytes, expected %d\n",
ep->ep.name, count, over, count - tmp); ep->ep.name, count, tmp);
req->req.status = -EOVERFLOW; req->req.status = -EOVERFLOW;
tmp -= over; cleanup = 1;
} }
count = tmp; count = tmp;
} }
...@@ -670,10 +664,12 @@ fill_dma_desc (struct net2280_ep *ep, struct net2280_request *req, int valid) ...@@ -670,10 +664,12 @@ fill_dma_desc (struct net2280_ep *ep, struct net2280_request *req, int valid)
/* don't let DMA continue after a short OUT packet, /* don't let DMA continue after a short OUT packet,
* so overruns can't affect the next transfer. * so overruns can't affect the next transfer.
* in case of overruns on max-size packets, we can't
* stop the fifo from filling but we can flush it.
*/ */
if (ep->is_in) if (ep->is_in)
dmacount |= (1 << DMA_DIRECTION); dmacount |= (1 << DMA_DIRECTION);
else if ((dmacount % ep->ep.maxpacket) != 0) else
dmacount |= (1 << END_OF_CHAIN); dmacount |= (1 << END_OF_CHAIN);
req->valid = valid; req->valid = valid;
...@@ -897,8 +893,12 @@ net2280_queue (struct usb_ep *_ep, struct usb_request *_req, int gfp_flags) ...@@ -897,8 +893,12 @@ net2280_queue (struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
start_dma (ep, req); start_dma (ep, req);
else { else {
/* maybe there's no control data, just status ack */ /* maybe there's no control data, just status ack */
if (ep->num == 0 && _req->length == 0) if (ep->num == 0 && _req->length == 0) {
allow_status (ep);
done (ep, req, 0);
VDEBUG (dev, "%s status ack\n", ep->ep.name);
goto done; goto done;
}
/* PIO ... stuff the fifo, or unblock it. */ /* PIO ... stuff the fifo, or unblock it. */
if (ep->is_in) if (ep->is_in)
...@@ -948,10 +948,9 @@ net2280_queue (struct usb_ep *_ep, struct usb_request *_req, int gfp_flags) ...@@ -948,10 +948,9 @@ net2280_queue (struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
} /* else the irq handler advances the queue. */ } /* else the irq handler advances the queue. */
if (req) { if (req)
done:
list_add_tail (&req->queue, &ep->queue); list_add_tail (&req->queue, &ep->queue);
} done:
spin_unlock_irqrestore (&dev->lock, flags); spin_unlock_irqrestore (&dev->lock, flags);
/* pci writes may still be posted */ /* pci writes may still be posted */
...@@ -992,6 +991,8 @@ static void scan_dma_completions (struct net2280_ep *ep) ...@@ -992,6 +991,8 @@ static void scan_dma_completions (struct net2280_ep *ep)
/* SHORT_PACKET_TRANSFERRED_INTERRUPT handles "usb-short" /* SHORT_PACKET_TRANSFERRED_INTERRUPT handles "usb-short"
* packets, including overruns, even when the transfer was * packets, including overruns, even when the transfer was
* exactly the length requested (dmacount now zero). * exactly the length requested (dmacount now zero).
* FIXME there's an overrun case here too, where we expect
* a short packet but receive a max length one (won't NAK).
*/ */
if (!ep->is_in && (req->req.length % ep->ep.maxpacket) != 0) { if (!ep->is_in && (req->req.length % ep->ep.maxpacket) != 0) {
req->dma_done = 1; req->dma_done = 1;
...@@ -1186,7 +1187,8 @@ net2280_set_halt (struct usb_ep *_ep, int value) ...@@ -1186,7 +1187,8 @@ net2280_set_halt (struct usb_ep *_ep, int value)
return -EINVAL; return -EINVAL;
if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
return -ESHUTDOWN; return -ESHUTDOWN;
if ((ep->desc->bmAttributes & 0x03) == USB_ENDPOINT_XFER_ISOC) if (ep->desc /* not ep0 */ && (ep->desc->bmAttributes & 0x03)
== USB_ENDPOINT_XFER_ISOC)
return -EINVAL; return -EINVAL;
VDEBUG (ep->dev, "%s %s halt\n", _ep->name, value ? "set" : "clear"); VDEBUG (ep->dev, "%s %s halt\n", _ep->name, value ? "set" : "clear");
...@@ -1712,7 +1714,7 @@ static void usb_reinit (struct net2280 *dev) ...@@ -1712,7 +1714,7 @@ static void usb_reinit (struct net2280 *dev)
static void ep0_start (struct net2280 *dev) static void ep0_start (struct net2280 *dev)
{ {
writel ( (1 << SET_EP_HIDE_STATUS_PHASE) writel ( (1 << CLEAR_EP_HIDE_STATUS_PHASE)
| (1 << CLEAR_NAK_OUT_PACKETS) | (1 << CLEAR_NAK_OUT_PACKETS)
| (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE) | (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
, &dev->epregs [0].ep_rsp); , &dev->epregs [0].ep_rsp);
...@@ -1916,22 +1918,27 @@ static void handle_ep_small (struct net2280_ep *ep) ...@@ -1916,22 +1918,27 @@ static void handle_ep_small (struct net2280_ep *ep)
if (ep->is_in) { if (ep->is_in) {
/* status; stop NAKing */ /* status; stop NAKing */
if (t & (1 << DATA_OUT_PING_TOKEN_INTERRUPT)) { if (t & (1 << DATA_OUT_PING_TOKEN_INTERRUPT)) {
if (ep->dev->protocol_stall) if (ep->dev->protocol_stall) {
ep->stopped = 1;
set_halt (ep); set_halt (ep);
}
mode = 2; mode = 2;
/* reply to extra IN tokens with a zlp */ /* reply to extra IN data tokens with a zlp */
} else if (t & (1 << DATA_IN_TOKEN_INTERRUPT)) { } else if (t & (1 << DATA_IN_TOKEN_INTERRUPT)) {
if (ep->dev->protocol_stall) { if (ep->dev->protocol_stall) {
ep->stopped = 1;
set_halt (ep); set_halt (ep);
mode = 2; mode = 2;
} else if (!req) } else if (!req && ep->stopped)
write_fifo (ep, 0); write_fifo (ep, 0);
} }
} else { } else {
/* status; stop NAKing */ /* status; stop NAKing */
if (t & (1 << DATA_IN_TOKEN_INTERRUPT)) { if (t & (1 << DATA_IN_TOKEN_INTERRUPT)) {
if (ep->dev->protocol_stall) if (ep->dev->protocol_stall) {
ep->stopped = 1;
set_halt (ep); set_halt (ep);
}
mode = 2; mode = 2;
/* an extra OUT token is an error */ /* an extra OUT token is an error */
} else if (((t & (1 << DATA_OUT_PING_TOKEN_INTERRUPT)) } else if (((t & (1 << DATA_OUT_PING_TOKEN_INTERRUPT))
...@@ -2031,6 +2038,10 @@ static void handle_ep_small (struct net2280_ep *ep) ...@@ -2031,6 +2038,10 @@ static void handle_ep_small (struct net2280_ep *ep)
/* maybe advance queue to next request */ /* maybe advance queue to next request */
if (ep->num == 0) { if (ep->num == 0) {
/* FIXME need mechanism (request flag?) so control OUT
* can decide to stall ep0 after that done() returns,
* from non-irq context
*/
allow_status (ep); allow_status (ep);
req = 0; req = 0;
} else { } else {
...@@ -2171,6 +2182,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat) ...@@ -2171,6 +2182,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
struct net2280_ep *e; struct net2280_ep *e;
u16 status; u16 status;
/* hw handles device and interface status */
if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT))
goto delegate; goto delegate;
if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0 if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0
...@@ -2188,12 +2200,14 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat) ...@@ -2188,12 +2200,14 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
set_fifo_bytecount (ep, u.r.wLength); set_fifo_bytecount (ep, u.r.wLength);
writel (status, &dev->epregs [0].ep_data); writel (status, &dev->epregs [0].ep_data);
allow_status (ep); allow_status (ep);
VDEBUG (dev, "%s stat %02x\n", ep->ep.name, status);
goto next_endpoints; goto next_endpoints;
} }
break; break;
case USB_REQ_CLEAR_FEATURE: { case USB_REQ_CLEAR_FEATURE: {
struct net2280_ep *e; struct net2280_ep *e;
/* hw handles device features */
if (u.r.bRequestType != USB_RECIP_ENDPOINT) if (u.r.bRequestType != USB_RECIP_ENDPOINT)
goto delegate; goto delegate;
if (u.r.wIndex != 0 /* HALT feature */ if (u.r.wIndex != 0 /* HALT feature */
...@@ -2202,11 +2216,15 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat) ...@@ -2202,11 +2216,15 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0) if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0)
goto do_stall; goto do_stall;
clear_halt (e); clear_halt (e);
allow_status (ep);
VDEBUG (dev, "%s clear halt\n", ep->ep.name);
goto next_endpoints;
} }
break; break;
case USB_REQ_SET_FEATURE: { case USB_REQ_SET_FEATURE: {
struct net2280_ep *e; struct net2280_ep *e;
/* hw handles device features */
if (u.r.bRequestType != USB_RECIP_ENDPOINT) if (u.r.bRequestType != USB_RECIP_ENDPOINT)
goto delegate; goto delegate;
if (u.r.wIndex != 0 /* HALT feature */ if (u.r.wIndex != 0 /* HALT feature */
...@@ -2215,6 +2233,9 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat) ...@@ -2215,6 +2233,9 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0) if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0)
goto do_stall; goto do_stall;
set_halt (e); set_halt (e);
allow_status (ep);
VDEBUG (dev, "%s set halt\n", ep->ep.name);
goto next_endpoints;
} }
break; break;
default: default:
...@@ -2235,23 +2256,12 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat) ...@@ -2235,23 +2256,12 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
VDEBUG (dev, "req %02x.%02x protocol STALL; stat %d\n", VDEBUG (dev, "req %02x.%02x protocol STALL; stat %d\n",
u.r.bRequestType, u.r.bRequest, tmp); u.r.bRequestType, u.r.bRequest, tmp);
dev->protocol_stall = 1; dev->protocol_stall = 1;
/* when there's no data, queueing a response is optional */
} else if (list_empty (&ep->queue)) {
if (u.r.wLength == 0) {
/* done() not possible/requested */
allow_status (ep);
} else {
DEBUG (dev, "req %02x.%02x v%04x "
"gadget error, len %d, stat %d\n",
u.r.bRequestType, u.r.bRequest,
le16_to_cpu (u.r.wValue),
u.r.wLength, tmp);
dev->protocol_stall = 1;
}
} }
/* some in/out token irq should follow; maybe stall then. */ /* some in/out token irq should follow; maybe stall then.
* driver must queue a request (even zlp) or halt ep0
* before the host times out.
*/
} }
next_endpoints: next_endpoints:
......
...@@ -437,6 +437,8 @@ struct net2280_ep_regs { /* [11.9] */ ...@@ -437,6 +437,8 @@ struct net2280_ep_regs { /* [11.9] */
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
#ifdef __KERNEL__
/* indexed registers [11.10] are accessed indirectly /* indexed registers [11.10] are accessed indirectly
* caller must own the device lock. * caller must own the device lock.
*/ */
...@@ -457,6 +459,9 @@ set_idx_reg (struct net2280_regs *regs, u32 index, u32 value) ...@@ -457,6 +459,9 @@ set_idx_reg (struct net2280_regs *regs, u32 index, u32 value)
/* posted, may not be visible yet */ /* posted, may not be visible yet */
} }
#endif /* __KERNEL__ */
#define REG_DIAG 0x0 #define REG_DIAG 0x0
#define RETRY_COUNTER 16 #define RETRY_COUNTER 16
#define FORCE_PCI_SERR 11 #define FORCE_PCI_SERR 11
...@@ -471,6 +476,8 @@ set_idx_reg (struct net2280_regs *regs, u32 index, u32 value) ...@@ -471,6 +476,8 @@ set_idx_reg (struct net2280_regs *regs, u32 index, u32 value)
#define REG_CHIPREV 0x03 /* in bcd */ #define REG_CHIPREV 0x03 /* in bcd */
#define REG_HS_NAK_RATE 0x0a /* NAK per N uframes */ #define REG_HS_NAK_RATE 0x0a /* NAK per N uframes */
#ifdef __KERNEL__
/* ep a-f highspeed and fullspeed maxpacket, addresses /* ep a-f highspeed and fullspeed maxpacket, addresses
* computed from ep->num * computed from ep->num
*/ */
...@@ -519,6 +526,7 @@ static inline void allow_status (struct net2280_ep *ep) ...@@ -519,6 +526,7 @@ static inline void allow_status (struct net2280_ep *ep)
writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE) writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
| (1 << CLEAR_NAK_OUT_PACKETS_MODE) | (1 << CLEAR_NAK_OUT_PACKETS_MODE)
, &ep->regs->ep_rsp); , &ep->regs->ep_rsp);
ep->stopped = 1;
} }
static inline void set_halt (struct net2280_ep *ep) static inline void set_halt (struct net2280_ep *ep)
...@@ -707,3 +715,4 @@ static inline void stop_out_naking (struct net2280_ep *ep) ...@@ -707,3 +715,4 @@ static inline void stop_out_naking (struct net2280_ep *ep)
writel ((1 << CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp); writel ((1 << CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
} }
#endif /* __KERNEL__ */
...@@ -653,7 +653,7 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req) ...@@ -653,7 +653,7 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
/* this endpoint is normally active while we're configured */ /* this endpoint is normally active while we're configured */
case -ECONNRESET: /* request dequeued */ case -ECONNRESET: /* request dequeued */
case -ESHUTDOWN: /* disconnect from host */ case -ESHUTDOWN: /* disconnect from host */
DEBUG (dev, "%s gone (%d), %d/%d\n", ep->name, status, VDEBUG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
req->actual, req->length); req->actual, req->length);
free_ep_req (ep, req); free_ep_req (ep, req);
return; return;
...@@ -1035,9 +1035,6 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -1035,9 +1035,6 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
if (ctrl->bRequestType != 0) if (ctrl->bRequestType != 0)
break; break;
spin_lock (&dev->lock); spin_lock (&dev->lock);
/* change hardware configuration!
* no response queued, just zero status == success
*/
value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC); value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
spin_unlock (&dev->lock); spin_unlock (&dev->lock);
break; break;
...@@ -1092,7 +1089,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -1092,7 +1089,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
} }
/* respond with data transfer before status phase? */ /* respond with data transfer before status phase? */
if (value > 0) { if (value >= 0) {
req->length = value; req->length = value;
value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC); value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
if (value < 0) { if (value < 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment