#include "./common.h"
#include "./pipe.h"
+/*
+ * packet info function
+ */
+void usbhs_pkt_update(struct usbhs_pkt *pkt,
+ struct usbhs_pipe *pipe,
+ void *buf, int len)
+{
+ pkt->pipe = pipe;
+ pkt->buf = buf;
+ pkt->length = len;
+ pkt->actual = 0;
+ pkt->maxp = 0;
+}
+
/*
* FIFO ctrl
*/
return usbhsf_fifo_select(pipe, 1);
}
-int usbhs_fifo_write(struct usbhs_pipe *pipe, u8 *buf, int len)
+int usbhs_fifo_write(struct usbhs_pkt *pkt)
{
+ struct usbhs_pipe *pipe = pkt->pipe;
struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
+ struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
void __iomem *addr = priv->base + CFIFO;
int maxp = usbhs_pipe_get_maxpacket(pipe);
int total_len;
- int i, ret;
+ u8 *buf = pkt->buf;
+ int i, ret, len;
ret = usbhs_pipe_is_accessible(pipe);
if (ret < 0)
if (ret < 0)
return ret;
- len = min(len, maxp);
+ len = min(pkt->length, maxp);
total_len = len;
/*
if (total_len < maxp)
usbhsf_send_terminator(pipe);
- return total_len;
+ usbhs_pipe_enable(pipe);
+
+ /* update pkt */
+ if (info->tx_done) {
+ pkt->actual = total_len;
+ pkt->maxp = maxp;
+ info->tx_done(pkt);
+ }
+
+ return 0;
}
int usbhs_fifo_prepare_read(struct usbhs_pipe *pipe)
return ret;
}
-int usbhs_fifo_read(struct usbhs_pipe *pipe, u8 *buf, int len)
+int usbhs_fifo_read(struct usbhs_pkt *pkt)
{
+ struct usbhs_pipe *pipe = pkt->pipe;
struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
+ struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
void __iomem *addr = priv->base + CFIFO;
- int rcv_len;
+ u8 *buf = pkt->buf;
+ int rcv_len, len;
int i, ret;
- int total_len;
+ int total_len = 0;
u32 data = 0;
ret = usbhsf_fifo_select(pipe, 0);
*/
if (0 == rcv_len) {
usbhsf_fifo_clear(pipe);
- return 0;
+ goto usbhs_fifo_read_end;
}
- len = min(rcv_len, len);
+ len = min(rcv_len, pkt->length);
total_len = len;
/*
buf[i] = (data >> ((i & 0x03) * 8)) & 0xff;
}
- return total_len;
+usbhs_fifo_read_end:
+ if (info->rx_done) {
+ /* update pkt */
+ pkt->actual = total_len;
+ pkt->maxp = usbhs_pipe_get_maxpacket(pipe);
+ info->rx_done(pkt);
+ }
+
+ return 0;
}
struct usbhsg_request {
struct usb_request req;
struct list_head node;
+ struct usbhs_pkt pkt;
};
#define EP_NAME_SIZE 8
#define usbhsg_pipe_to_uep(p) ((p)->mod_private)
#define usbhsg_is_dcp(u) ((u) == usbhsg_gpriv_to_dcp((u)->gpriv))
+#define usbhsg_ureq_to_pkt(u) (&(u)->pkt)
+#define usbhsg_pkt_to_ureq(i) \
+ container_of(i, struct usbhsg_request, pkt)
+
#define usbhsg_is_not_connected(gp) ((gp)->gadget.speed == USB_SPEED_UNKNOWN)
/* status */
return 0;
}
-static int usbhsg_try_run_send_packet(struct usbhsg_uep *uep,
- struct usbhsg_request *ureq)
+/*
+ * packet send hander
+ */
+static void usbhsg_try_run_send_packet_bh(struct usbhs_pkt *pkt)
{
- struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
+ struct usbhs_pipe *pipe = pkt->pipe;
+ struct usbhsg_uep *uep = usbhsg_pipe_to_uep(pipe);
+ struct usbhsg_request *ureq = usbhsg_pkt_to_ureq(pkt);
struct usb_request *req = &ureq->req;
struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
struct device *dev = usbhsg_gpriv_to_dev(gpriv);
- void *buf;
- int remainder, send;
+ int remainder, send, maxp;
int is_done = 0;
int enable;
- int maxp;
- /*
- ********* assume under spin lock *********
- */
-
- maxp = usbhs_pipe_get_maxpacket(pipe);
- buf = req->buf + req->actual;
- remainder = req->length - req->actual;
-
- send = usbhs_fifo_write(pipe, buf, remainder);
+ maxp = pkt->maxp;
+ send = pkt->actual;
+ remainder = pkt->length;
/*
- * send < 0 : pipe busy
* send = 0 : send zero packet
* send > 0 : send data
*
* send <= max_packet
*/
- if (send > 0)
- req->actual += send;
+ req->actual += send;
/* send all packet ? */
if (send < remainder)
enable = !is_done;
uep->handler->irq_mask(uep, enable);
- /*
- * usbhs_fifo_enable execute
- * - after callback_update,
- * - before queue_pop / stage_end
- */
- usbhs_pipe_enable(pipe);
-
/*
* all data were sent ?
*/
usbhsg_queue_pop(uep, ureq, 0);
}
+}
+
+static int usbhsg_try_run_send_packet(struct usbhsg_uep *uep,
+ struct usbhsg_request *ureq)
+{
+ struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
+ struct usb_request *req = &ureq->req;
+ struct usbhs_pkt *pkt = usbhsg_ureq_to_pkt(ureq);
+ int ret;
+
+ /*
+ ********* assume under spin lock *********
+ */
+
+ usbhs_pkt_update(pkt, pipe,
+ req->buf + req->actual,
+ req->length - req->actual);
+
+ ret = usbhs_fifo_write(pkt);
+ if (ret < 0) {
+ /* pipe is busy.
+ * retry in interrupt */
+ uep->handler->irq_mask(uep, 1);
+ }
return 0;
}
return 0;
}
-static int usbhsg_try_run_receive_packet(struct usbhsg_uep *uep,
- struct usbhsg_request *ureq)
+/*
+ * packet recv hander
+ */
+static void usbhsg_try_run_receive_packet_bh(struct usbhs_pkt *pkt)
{
- struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
+ struct usbhs_pipe *pipe = pkt->pipe;
+ struct usbhsg_uep *uep = usbhsg_pipe_to_uep(pipe);
+ struct usbhsg_request *ureq = usbhsg_pkt_to_ureq(pkt);
struct usb_request *req = &ureq->req;
struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
struct device *dev = usbhsg_gpriv_to_dev(gpriv);
- void *buf;
- int maxp;
- int remainder, recv;
+ int remainder, recv, maxp;
int is_done = 0;
- /*
- ********* assume under spin lock *********
- */
-
- maxp = usbhs_pipe_get_maxpacket(pipe);
- buf = req->buf + req->actual;
- remainder = req->length - req->actual;
+ maxp = pkt->maxp;
+ remainder = pkt->length;
+ recv = pkt->actual;
- recv = usbhs_fifo_read(pipe, buf, remainder);
/*
* recv < 0 : pipe busy
* recv >= 0 : receive data
*
* recv <= max_packet
*/
- if (recv < 0)
- return -EBUSY;
/* update parameters */
req->actual += recv;
usbhs_pipe_disable(pipe);
usbhsg_queue_pop(uep, ureq, 0);
}
+}
- return 0;
+static int usbhsg_try_run_receive_packet(struct usbhsg_uep *uep,
+ struct usbhsg_request *ureq)
+{
+ struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
+ struct usb_request *req = &ureq->req;
+ struct usbhs_pkt *pkt = usbhsg_ureq_to_pkt(ureq);
+
+ /*
+ ********* assume under spin lock *********
+ */
+
+ usbhs_pkt_update(pkt, pipe,
+ req->buf + req->actual,
+ req->length - req->actual);
+
+ return usbhs_fifo_read(pkt);
}
static int usbhsg_prepare_receive_packet(struct usbhsg_uep *uep,
/*
* pipe initialize and enable DCP
*/
- usbhs_pipe_init(priv);
+ usbhs_pipe_init(priv,
+ usbhsg_try_run_send_packet_bh,
+ usbhsg_try_run_receive_packet_bh);
usbhsg_uep_init(gpriv);
usbhsg_dcp_enable(dcp);