Lines Matching refs:ep

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