Lines Matching refs:ep
35 int ast_vhub_reply(struct ast_vhub_ep *ep, char *ptr, int len)
37 struct usb_request *req = &ep->ep0.req.req;
40 if (WARN_ON(ep->d_idx != 0))
42 if (WARN_ON(!ep->ep0.dir_in))
59 spin_unlock(&ep->vhub->lock);
60 if (ep->ep.ops->queue(&ep->ep, req, GFP_ATOMIC))
64 spin_lock(&ep->vhub->lock);
68 int __ast_vhub_simple_reply(struct ast_vhub_ep *ep, int len, ...)
70 u8 *buffer = ep->buf;
82 return ast_vhub_reply(ep, NULL, len);
85 void ast_vhub_ep0_handle_setup(struct ast_vhub_ep *ep)
91 if (WARN_ON(ep->d_idx != 0))
98 memcpy_fromio(&crq, ep->ep0.setup, sizeof(crq));
100 EPDBG(ep, "SETUP packet %02x/%02x/%04x/%04x/%04x [%s] st=%d\n",
106 ep->ep0.state);
118 if (ep->ep0.state != ep0_state_token &&
119 ep->ep0.state != ep0_state_stall) {
120 EPDBG(ep, "wrong state\n");
121 ast_vhub_nuke(ep, -EIO);
125 ep->ep0.state = ep0_state_data;
126 ep->ep0.dir_in = !!(crq.bRequestType & USB_DIR_IN);
130 if (ep->dev == NULL) {
132 std_req_rc = ast_vhub_std_hub_request(ep, &crq);
134 std_req_rc = ast_vhub_class_hub_request(ep, &crq);
138 std_req_rc = ast_vhub_std_dev_request(ep, &crq);
153 if (WARN_ON(!ep->dev))
155 if (ep->dev->driver) {
156 EPDBG(ep, "forwarding to gadget...\n");
157 spin_unlock(&ep->vhub->lock);
158 rc = ep->dev->driver->setup(&ep->dev->gadget, &crq);
159 spin_lock(&ep->vhub->lock);
160 EPDBG(ep, "driver returned %d\n", rc);
162 EPDBG(ep, "no gadget for request !\n");
168 EPDBG(ep, "stalling\n");
169 writel(VHUB_EP0_CTRL_STALL, ep->ep0.ctlstat);
170 ep->ep0.state = ep0_state_stall;
171 ep->ep0.dir_in = false;
175 EPVDBG(ep, "sending [in] status with no data\n");
176 writel(VHUB_EP0_TX_BUFF_RDY, ep->ep0.ctlstat);
177 ep->ep0.state = ep0_state_status;
178 ep->ep0.dir_in = false;
182 static void ast_vhub_ep0_do_send(struct ast_vhub_ep *ep,
196 EPVDBG(ep, "complete send %d/%d\n",
198 ep->ep0.state = ep0_state_status;
199 writel(VHUB_EP0_RX_BUFF_RDY, ep->ep0.ctlstat);
200 ast_vhub_done(ep, req, 0);
209 if (chunk > ep->ep.maxpacket)
210 chunk = ep->ep.maxpacket;
211 else if ((chunk < ep->ep.maxpacket) || !req->req.zero)
214 EPVDBG(ep, "send chunk=%d last=%d, req->act=%d mp=%d\n",
215 chunk, req->last_desc, req->req.actual, ep->ep.maxpacket);
222 memcpy(ep->buf, req->req.buf + req->req.actual, chunk);
224 vhub_dma_workaround(ep->buf);
228 writel(reg, ep->ep0.ctlstat);
229 writel(reg | VHUB_EP0_TX_BUFF_RDY, ep->ep0.ctlstat);
233 static void ast_vhub_ep0_rx_prime(struct ast_vhub_ep *ep)
235 EPVDBG(ep, "rx prime\n");
238 writel(VHUB_EP0_RX_BUFF_RDY, ep->ep0.ctlstat);
241 static void ast_vhub_ep0_do_receive(struct ast_vhub_ep *ep, struct ast_vhub_req *req,
250 EPVDBG(ep, "receive got=%d remain=%d\n", len, remain);
254 EPDBG(ep, "receiving too much (ovf: %d) !\n",
260 memcpy(req->req.buf + req->req.actual, ep->buf, len);
264 if (len < ep->ep.maxpacket || len == remain) {
265 ep->ep0.state = ep0_state_status;
266 writel(VHUB_EP0_TX_BUFF_RDY, ep->ep0.ctlstat);
267 ast_vhub_done(ep, req, rc);
269 ast_vhub_ep0_rx_prime(ep);
272 void ast_vhub_ep0_handle_ack(struct ast_vhub_ep *ep, bool in_ack)
275 struct ast_vhub *vhub = ep->vhub;
281 stat = readl(ep->ep0.ctlstat);
284 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue);
286 EPVDBG(ep, "ACK status=%08x,state=%d is_in=%d in_ack=%d req=%p\n",
287 stat, ep->ep0.state, ep->ep0.dir_in, in_ack, req);
289 switch(ep->ep0.state) {
294 ast_vhub_nuke(ep, -EINVAL);
301 if ((ep->ep0.dir_in && (stat & VHUB_EP0_TX_BUFF_RDY)) ||
302 (!ep->ep0.dir_in && (stat & VHUB_EP0_RX_BUFF_RDY)) ||
303 (ep->ep0.dir_in != in_ack)) {
319 if (ep->ep0.dir_in)
320 ast_vhub_ep0_do_send(ep, req);
322 ast_vhub_ep0_do_receive(ep, req, VHUB_EP0_RX_LEN(stat));
328 ast_vhub_nuke(ep, -EINVAL);
336 if (ep->ep0.dir_in == in_ack) {
346 ast_vhub_nuke(ep, -EIO);
352 writel(VHUB_EP0_CTRL_STALL, ep->ep0.ctlstat);
353 ep->ep0.state = ep0_state_stall;
355 ep->ep0.state = ep0_state_token;
362 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
363 struct ast_vhub *vhub = ep->vhub;
378 if (WARN_ON(ep->d_idx != 0))
382 if (ep->dev && !ep->dev->enabled)
391 EPVDBG(ep, "enqueue req @%p\n", req);
392 EPVDBG(ep, " l=%d zero=%d noshort=%d is_in=%d\n",
394 u_req->short_not_ok, ep->ep0.dir_in);
405 if (!list_empty(&ep->queue) ||
406 ep->ep0.state == ep0_state_token ||
407 ep->ep0.state == ep0_state_stall) {
409 EPVDBG(ep, "EP0: list_empty=%d state=%d\n",
410 list_empty(&ep->queue), ep->ep0.state);
416 list_add_tail(&req->queue, &ep->queue);
418 if (ep->ep0.dir_in) {
420 ast_vhub_ep0_do_send(ep, req);
423 EPVDBG(ep, "0-length rx completion\n");
424 ep->ep0.state = ep0_state_status;
425 writel(VHUB_EP0_TX_BUFF_RDY, ep->ep0.ctlstat);
426 ast_vhub_done(ep, req, 0);
429 ast_vhub_ep0_rx_prime(ep);
439 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
440 struct ast_vhub *vhub = ep->vhub;
448 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue);
452 EPVDBG(ep, "dequeue req @%p\n", req);
458 ast_vhub_done(ep, req, -ECONNRESET);
461 writel(VHUB_EP0_CTRL_STALL, ep->ep0.ctlstat);
462 ep->ep0.state = ep0_state_status;
463 ep->ep0.dir_in = false;
480 struct ast_vhub_ep *ep = &dev->ep0;
482 ast_vhub_nuke(ep, -EIO);
483 ep->ep0.state = ep0_state_token;
487 void ast_vhub_init_ep0(struct ast_vhub *vhub, struct ast_vhub_ep *ep,
490 memset(ep, 0, sizeof(*ep));
492 INIT_LIST_HEAD(&ep->ep.ep_list);
493 INIT_LIST_HEAD(&ep->queue);
494 ep->ep.ops = &ast_vhub_ep0_ops;
495 ep->ep.name = "ep0";
496 ep->ep.caps.type_control = true;
497 usb_ep_set_maxpacket_limit(&ep->ep, AST_VHUB_EP0_MAX_PACKET);
498 ep->d_idx = 0;
499 ep->dev = dev;
500 ep->vhub = vhub;
501 ep->ep0.state = ep0_state_token;
502 INIT_LIST_HEAD(&ep->ep0.req.queue);
503 ep->ep0.req.internal = true;
507 ep->ep0.ctlstat = dev->regs + AST_VHUB_DEV_EP0_CTRL;
508 ep->ep0.setup = vhub->regs +
510 ep->buf = vhub->ep0_bufs +
512 ep->buf_dma = vhub->ep0_bufs_dma +
515 ep->ep0.ctlstat = vhub->regs + AST_VHUB_EP0_CTRL;
516 ep->ep0.setup = vhub->regs + AST_VHUB_SETUP0;
517 ep->buf = vhub->ep0_bufs;
518 ep->buf_dma = vhub->ep0_bufs_dma;