Lines Matching full:ep

29 int ast_vhub_reply(struct ast_vhub_ep *ep, char *ptr, int len)  in ast_vhub_reply()  argument
31 struct usb_request *req = &ep->ep0.req.req; in ast_vhub_reply()
34 if (WARN_ON(ep->d_idx != 0)) in ast_vhub_reply()
36 if (WARN_ON(!ep->ep0.dir_in)) in ast_vhub_reply()
53 spin_unlock(&ep->vhub->lock); in ast_vhub_reply()
54 if (ep->ep.ops->queue(&ep->ep, req, GFP_ATOMIC)) in ast_vhub_reply()
58 spin_lock(&ep->vhub->lock); in ast_vhub_reply()
62 int __ast_vhub_simple_reply(struct ast_vhub_ep *ep, int len, ...) in __ast_vhub_simple_reply() argument
64 u8 *buffer = ep->buf; in __ast_vhub_simple_reply()
70 /* Copy data directly into EP buffer */ in __ast_vhub_simple_reply()
76 return ast_vhub_reply(ep, NULL, len); in __ast_vhub_simple_reply()
79 void ast_vhub_ep0_handle_setup(struct ast_vhub_ep *ep) in ast_vhub_ep0_handle_setup() argument
85 if (WARN_ON(ep->d_idx != 0)) in ast_vhub_ep0_handle_setup()
92 memcpy_fromio(&crq, ep->ep0.setup, sizeof(crq)); in ast_vhub_ep0_handle_setup()
94 EPDBG(ep, "SETUP packet %02x/%02x/%04x/%04x/%04x [%s] st=%d\n", in ast_vhub_ep0_handle_setup()
100 ep->ep0.state); in ast_vhub_ep0_handle_setup()
112 if (ep->ep0.state != ep0_state_token && in ast_vhub_ep0_handle_setup()
113 ep->ep0.state != ep0_state_stall) { in ast_vhub_ep0_handle_setup()
114 EPDBG(ep, "wrong state\n"); in ast_vhub_ep0_handle_setup()
115 ast_vhub_nuke(ep, -EIO); in ast_vhub_ep0_handle_setup()
119 ep->ep0.state = ep0_state_data; in ast_vhub_ep0_handle_setup()
120 ep->ep0.dir_in = !!(crq.bRequestType & USB_DIR_IN); in ast_vhub_ep0_handle_setup()
124 if (ep->dev == NULL) { in ast_vhub_ep0_handle_setup()
126 std_req_rc = ast_vhub_std_hub_request(ep, &crq); in ast_vhub_ep0_handle_setup()
128 std_req_rc = ast_vhub_class_hub_request(ep, &crq); in ast_vhub_ep0_handle_setup()
132 std_req_rc = ast_vhub_std_dev_request(ep, &crq); in ast_vhub_ep0_handle_setup()
147 if (WARN_ON(!ep->dev)) in ast_vhub_ep0_handle_setup()
149 if (ep->dev->driver) { in ast_vhub_ep0_handle_setup()
150 EPDBG(ep, "forwarding to gadget...\n"); in ast_vhub_ep0_handle_setup()
151 spin_unlock(&ep->vhub->lock); in ast_vhub_ep0_handle_setup()
152 rc = ep->dev->driver->setup(&ep->dev->gadget, &crq); in ast_vhub_ep0_handle_setup()
153 spin_lock(&ep->vhub->lock); in ast_vhub_ep0_handle_setup()
154 EPDBG(ep, "driver returned %d\n", rc); in ast_vhub_ep0_handle_setup()
156 EPDBG(ep, "no gadget for request !\n"); in ast_vhub_ep0_handle_setup()
162 EPDBG(ep, "stalling\n"); in ast_vhub_ep0_handle_setup()
163 writel(VHUB_EP0_CTRL_STALL, ep->ep0.ctlstat); in ast_vhub_ep0_handle_setup()
164 ep->ep0.state = ep0_state_stall; in ast_vhub_ep0_handle_setup()
165 ep->ep0.dir_in = false; in ast_vhub_ep0_handle_setup()
169 EPVDBG(ep, "sending [in] status with no data\n"); in ast_vhub_ep0_handle_setup()
170 writel(VHUB_EP0_TX_BUFF_RDY, ep->ep0.ctlstat); in ast_vhub_ep0_handle_setup()
171 ep->ep0.state = ep0_state_status; in ast_vhub_ep0_handle_setup()
172 ep->ep0.dir_in = false; in ast_vhub_ep0_handle_setup()
176 static void ast_vhub_ep0_do_send(struct ast_vhub_ep *ep, in ast_vhub_ep0_do_send() argument
190 EPVDBG(ep, "complete send %d/%d\n", in ast_vhub_ep0_do_send()
192 ep->ep0.state = ep0_state_status; in ast_vhub_ep0_do_send()
193 writel(VHUB_EP0_RX_BUFF_RDY, ep->ep0.ctlstat); in ast_vhub_ep0_do_send()
194 ast_vhub_done(ep, req, 0); in ast_vhub_ep0_do_send()
203 if (chunk > ep->ep.maxpacket) in ast_vhub_ep0_do_send()
204 chunk = ep->ep.maxpacket; in ast_vhub_ep0_do_send()
205 else if ((chunk < ep->ep.maxpacket) || !req->req.zero) in ast_vhub_ep0_do_send()
208 EPVDBG(ep, "send chunk=%d last=%d, req->act=%d mp=%d\n", in ast_vhub_ep0_do_send()
209 chunk, req->last_desc, req->req.actual, ep->ep.maxpacket); in ast_vhub_ep0_do_send()
213 * in the EP buffer) in ast_vhub_ep0_do_send()
216 memcpy(ep->buf, req->req.buf + req->req.actual, chunk); in ast_vhub_ep0_do_send()
218 vhub_dma_workaround(ep->buf); in ast_vhub_ep0_do_send()
222 writel(reg, ep->ep0.ctlstat); in ast_vhub_ep0_do_send()
223 writel(reg | VHUB_EP0_TX_BUFF_RDY, ep->ep0.ctlstat); in ast_vhub_ep0_do_send()
227 static void ast_vhub_ep0_rx_prime(struct ast_vhub_ep *ep) in ast_vhub_ep0_rx_prime() argument
229 EPVDBG(ep, "rx prime\n"); in ast_vhub_ep0_rx_prime()
232 writel(VHUB_EP0_RX_BUFF_RDY, ep->ep0.ctlstat); in ast_vhub_ep0_rx_prime()
235 static void ast_vhub_ep0_do_receive(struct ast_vhub_ep *ep, struct ast_vhub_req *req, in ast_vhub_ep0_do_receive() argument
244 EPVDBG(ep, "receive got=%d remain=%d\n", len, remain); in ast_vhub_ep0_do_receive()
248 EPDBG(ep, "receiving too much (ovf: %d) !\n", in ast_vhub_ep0_do_receive()
255 if (len < ep->ep.maxpacket && len != remain) { in ast_vhub_ep0_do_receive()
256 EPDBG(ep, "using expected data len instead\n"); in ast_vhub_ep0_do_receive()
261 memcpy(req->req.buf + req->req.actual, ep->buf, len); in ast_vhub_ep0_do_receive()
265 if (len < ep->ep.maxpacket || len == remain) { in ast_vhub_ep0_do_receive()
266 ep->ep0.state = ep0_state_status; in ast_vhub_ep0_do_receive()
267 writel(VHUB_EP0_TX_BUFF_RDY, ep->ep0.ctlstat); in ast_vhub_ep0_do_receive()
268 ast_vhub_done(ep, req, rc); in ast_vhub_ep0_do_receive()
270 ast_vhub_ep0_rx_prime(ep); in ast_vhub_ep0_do_receive()
273 void ast_vhub_ep0_handle_ack(struct ast_vhub_ep *ep, bool in_ack) in ast_vhub_ep0_handle_ack() argument
276 struct ast_vhub *vhub = ep->vhub; in ast_vhub_ep0_handle_ack()
282 stat = readl(ep->ep0.ctlstat); in ast_vhub_ep0_handle_ack()
285 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue); in ast_vhub_ep0_handle_ack()
287 EPVDBG(ep, "ACK status=%08x,state=%d is_in=%d in_ack=%d req=%p\n", in ast_vhub_ep0_handle_ack()
288 stat, ep->ep0.state, ep->ep0.dir_in, in_ack, req); in ast_vhub_ep0_handle_ack()
290 switch(ep->ep0.state) { in ast_vhub_ep0_handle_ack()
295 ast_vhub_nuke(ep, -EINVAL); in ast_vhub_ep0_handle_ack()
302 if ((ep->ep0.dir_in && (stat & VHUB_EP0_TX_BUFF_RDY)) || in ast_vhub_ep0_handle_ack()
303 (!ep->ep0.dir_in && (stat & VHUB_EP0_RX_BUFF_RDY)) || in ast_vhub_ep0_handle_ack()
304 (ep->ep0.dir_in != in_ack)) { in ast_vhub_ep0_handle_ack()
320 if (ep->ep0.dir_in) in ast_vhub_ep0_handle_ack()
321 ast_vhub_ep0_do_send(ep, req); in ast_vhub_ep0_handle_ack()
323 ast_vhub_ep0_do_receive(ep, req, VHUB_EP0_RX_LEN(stat)); in ast_vhub_ep0_handle_ack()
329 ast_vhub_nuke(ep, -EINVAL); in ast_vhub_ep0_handle_ack()
337 if (ep->ep0.dir_in == in_ack) { in ast_vhub_ep0_handle_ack()
347 ast_vhub_nuke(ep, -EIO); in ast_vhub_ep0_handle_ack()
353 writel(VHUB_EP0_CTRL_STALL, ep->ep0.ctlstat); in ast_vhub_ep0_handle_ack()
354 ep->ep0.state = ep0_state_stall; in ast_vhub_ep0_handle_ack()
356 ep->ep0.state = ep0_state_token; in ast_vhub_ep0_handle_ack()
363 struct ast_vhub_ep *ep = to_ast_ep(u_ep); in ast_vhub_ep0_queue() local
364 struct ast_vhub *vhub = ep->vhub; in ast_vhub_ep0_queue()
379 if (WARN_ON(ep->d_idx != 0)) in ast_vhub_ep0_queue()
383 if (ep->dev && !ep->dev->enabled) in ast_vhub_ep0_queue()
392 EPVDBG(ep, "enqueue req @%p\n", req); in ast_vhub_ep0_queue()
393 EPVDBG(ep, " l=%d zero=%d noshort=%d is_in=%d\n", in ast_vhub_ep0_queue()
395 u_req->short_not_ok, ep->ep0.dir_in); in ast_vhub_ep0_queue()
406 if (!list_empty(&ep->queue) || in ast_vhub_ep0_queue()
407 ep->ep0.state == ep0_state_token || in ast_vhub_ep0_queue()
408 ep->ep0.state == ep0_state_stall) { in ast_vhub_ep0_queue()
410 EPVDBG(ep, "EP0: list_empty=%d state=%d\n", in ast_vhub_ep0_queue()
411 list_empty(&ep->queue), ep->ep0.state); in ast_vhub_ep0_queue()
417 list_add_tail(&req->queue, &ep->queue); in ast_vhub_ep0_queue()
419 if (ep->ep0.dir_in) { in ast_vhub_ep0_queue()
421 ast_vhub_ep0_do_send(ep, req); in ast_vhub_ep0_queue()
424 EPVDBG(ep, "0-length rx completion\n"); in ast_vhub_ep0_queue()
425 ep->ep0.state = ep0_state_status; in ast_vhub_ep0_queue()
426 writel(VHUB_EP0_TX_BUFF_RDY, ep->ep0.ctlstat); in ast_vhub_ep0_queue()
427 ast_vhub_done(ep, req, 0); in ast_vhub_ep0_queue()
430 ast_vhub_ep0_rx_prime(ep); in ast_vhub_ep0_queue()
440 struct ast_vhub_ep *ep = to_ast_ep(u_ep); in ast_vhub_ep0_dequeue() local
441 struct ast_vhub *vhub = ep->vhub; in ast_vhub_ep0_dequeue()
449 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue); in ast_vhub_ep0_dequeue()
453 EPVDBG(ep, "dequeue req @%p\n", req); in ast_vhub_ep0_dequeue()
457 * DMAs go to the EP buffers, not the request. in ast_vhub_ep0_dequeue()
459 ast_vhub_done(ep, req, -ECONNRESET); in ast_vhub_ep0_dequeue()
461 /* We do stall the EP to clean things up in HW */ in ast_vhub_ep0_dequeue()
462 writel(VHUB_EP0_CTRL_STALL, ep->ep0.ctlstat); in ast_vhub_ep0_dequeue()
463 ep->ep0.state = ep0_state_status; in ast_vhub_ep0_dequeue()
464 ep->ep0.dir_in = false; in ast_vhub_ep0_dequeue()
481 struct ast_vhub_ep *ep = &dev->ep0; in ast_vhub_reset_ep0() local
483 ast_vhub_nuke(ep, -EIO); in ast_vhub_reset_ep0()
484 ep->ep0.state = ep0_state_token; in ast_vhub_reset_ep0()
488 void ast_vhub_init_ep0(struct ast_vhub *vhub, struct ast_vhub_ep *ep, in ast_vhub_init_ep0() argument
491 memset(ep, 0, sizeof(*ep)); in ast_vhub_init_ep0()
493 INIT_LIST_HEAD(&ep->ep.ep_list); in ast_vhub_init_ep0()
494 INIT_LIST_HEAD(&ep->queue); in ast_vhub_init_ep0()
495 ep->ep.ops = &ast_vhub_ep0_ops; in ast_vhub_init_ep0()
496 ep->ep.name = "ep0"; in ast_vhub_init_ep0()
497 ep->ep.caps.type_control = true; in ast_vhub_init_ep0()
498 usb_ep_set_maxpacket_limit(&ep->ep, AST_VHUB_EP0_MAX_PACKET); in ast_vhub_init_ep0()
499 ep->d_idx = 0; in ast_vhub_init_ep0()
500 ep->dev = dev; in ast_vhub_init_ep0()
501 ep->vhub = vhub; in ast_vhub_init_ep0()
502 ep->ep0.state = ep0_state_token; in ast_vhub_init_ep0()
503 INIT_LIST_HEAD(&ep->ep0.req.queue); in ast_vhub_init_ep0()
504 ep->ep0.req.internal = true; in ast_vhub_init_ep0()
508 ep->ep0.ctlstat = dev->regs + AST_VHUB_DEV_EP0_CTRL; in ast_vhub_init_ep0()
509 ep->ep0.setup = vhub->regs + in ast_vhub_init_ep0()
511 ep->buf = vhub->ep0_bufs + in ast_vhub_init_ep0()
513 ep->buf_dma = vhub->ep0_bufs_dma + in ast_vhub_init_ep0()
516 ep->ep0.ctlstat = vhub->regs + AST_VHUB_EP0_CTRL; in ast_vhub_init_ep0()
517 ep->ep0.setup = vhub->regs + AST_VHUB_SETUP0; in ast_vhub_init_ep0()
518 ep->buf = vhub->ep0_bufs; in ast_vhub_init_ep0()
519 ep->buf_dma = vhub->ep0_bufs_dma; in ast_vhub_init_ep0()