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 */
#define usbhsg_status_clr(gp, b) (gp->status &= ~b)
#define usbhsg_status_has(gp, b) (gp->status & b)
+/*
+ * usbhsg_trylock
+ *
+ * This driver don't use spin_try_lock
+ * to avoid warning of CONFIG_DEBUG_SPINLOCK
+ */
+static spinlock_t *usbhsg_trylock(struct usbhsg_gpriv *gpriv,
+ unsigned long *flags)
+{
+ spinlock_t *lock = usbhsg_gpriv_to_lock(gpriv);
+
+ /* check spin lock status
+ * to avoid deadlock/nest */
+ if (spin_is_locked(lock))
+ return NULL;
+
+ spin_lock_irqsave(lock, *flags);
+
+ return lock;
+}
+
+static void usbhsg_unlock(spinlock_t *lock, unsigned long *flags)
+{
+ if (!lock)
+ return;
+
+ spin_unlock_irqrestore(lock, *flags);
+}
+
/*
* list push/pop
*/
struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
struct device *dev = usbhsg_gpriv_to_dev(gpriv);
struct usbhsg_request *ureq;
- spinlock_t *lock = usbhsg_gpriv_to_lock(gpriv);
+ spinlock_t *lock;
unsigned long flags;
- int is_locked;
int ret = 0;
if (!uep->handler) {
* - usb_request :: complete
*
* But the caller of this function need not care about spinlock.
- * This function is using spin_trylock_irqsave for it.
+ * This function is using usbhsg_trylock for it.
* if "is_locked" is 1, this mean this function lock it.
* but if it is 0, this mean it is already under spin lock.
* see also
*/
/****************** spin try lock *******************/
- is_locked = spin_trylock_irqsave(lock, flags);
+ lock = usbhsg_trylock(gpriv, &flags);
+
ureq = usbhsg_queue_get(uep);
if (ureq) {
if (prepare)
else
ret = uep->handler->try_run(uep, ureq);
}
- if (is_locked)
- spin_unlock_irqrestore(lock, flags);
+ usbhsg_unlock(lock, &flags);
/******************** spin unlock ******************/
return ret;
* It mean "usb_ep_ops :: queue" which is using spinlock is called
* under spinlock.
*
- * To avoid dead-lock, this driver is using spin_trylock.
+ * To avoid dead-lock, this driver is using usbhsg_trylock.
* CAUTION [*endpoint queue*]
* CAUTION [*queue handler*]
*/
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_fifo_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;
int disable = 0;
uep->handler->irq_mask(uep, disable);
- usbhs_fifo_disable(pipe);
+ 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,
struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
if (!usbhsg_status_has(gpriv, USBHSG_STATUS_WEDGE)) {
- usbhs_fifo_disable(pipe);
+ usbhs_pipe_disable(pipe);
usbhs_pipe_clear_sequence(pipe);
- usbhs_fifo_enable(pipe);
+ usbhs_pipe_enable(pipe);
}
usbhsg_recip_handler_std_control_done(priv, uep, ctrl);
char *msg;
uep = usbhsg_gpriv_to_nth_uep(gpriv, nth);
+ if (!usbhsg_uep_to_pipe(uep)) {
+ dev_err(dev, "wrong recip request\n");
+ return -EINVAL;
+ }
switch (recip) {
case USB_RECIP_DEVICE:
ret = gpriv->driver->setup(&gpriv->gadget, &ctrl);
if (ret < 0)
- usbhs_fifo_stall(pipe);
+ usbhs_pipe_stall(pipe);
return ret;
}
********* assume under spin lock *********
*/
- usbhs_fifo_disable(pipe);
+ usbhs_pipe_disable(pipe);
/*
* disable pipe irq
usbhsg_queue_pop(uep, ureq, -ECONNRESET);
}
- uep->pipe->mod_private = NULL;
- uep->pipe = NULL;
-
return 0;
}
+static void usbhsg_uep_init(struct usbhsg_gpriv *gpriv)
+{
+ int i;
+ struct usbhsg_uep *uep;
+
+ usbhsg_for_each_uep_with_dcp(uep, gpriv, i)
+ uep->pipe = NULL;
+}
+
/*
*
* usb_ep_ops
struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
struct usbhs_pipe *pipe;
- spinlock_t *lock = usbhsg_gpriv_to_lock(gpriv);
+ spinlock_t *lock;
unsigned long flags;
int ret = -EIO;
+ /*
+ * if it already have pipe,
+ * nothing to do
+ */
+ if (uep->pipe)
+ return 0;
+
/******************** spin lock ********************/
- spin_lock_irqsave(lock, flags);
+ lock = usbhsg_trylock(gpriv, &flags);
pipe = usbhs_pipe_malloc(priv, desc);
if (pipe) {
ret = 0;
}
- spin_unlock_irqrestore(lock, flags);
+
+ usbhsg_unlock(lock, &flags);
/******************** spin unlock ******************/
return ret;
{
struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
- spinlock_t *lock = usbhsg_gpriv_to_lock(gpriv);
+ spinlock_t *lock;
unsigned long flags;
int ret;
/******************** spin lock ********************/
- spin_lock_irqsave(lock, flags);
+ lock = usbhsg_trylock(gpriv, &flags);
+
ret = usbhsg_pipe_disable(uep);
- spin_unlock_irqrestore(lock, flags);
+
+ usbhsg_unlock(lock, &flags);
/******************** spin unlock ******************/
return ret;
struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
struct usbhsg_request *ureq = usbhsg_req_to_ureq(req);
struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
- spinlock_t *lock = usbhsg_gpriv_to_lock(gpriv);
+ spinlock_t *lock;
unsigned long flags;
int ret = 0;
- int is_locked;
/*
* CAUTION [*endpoint queue*]
* it is already under spinlock on this driver.
* but it is called frm usb driver, this function should call spinlock.
*
- * This function is using spin_trylock_irqsave to solve this issue.
+ * This function is using usbshg_trylock to solve this issue.
* if "is_locked" is 1, this mean this function lock it.
* but if it is 0, this mean it is already under spin lock.
* see also
*/
/******************** spin lock ********************/
- is_locked = spin_trylock_irqsave(lock, flags);
+ lock = usbhsg_trylock(gpriv, &flags);
/* param check */
if (usbhsg_is_not_connected(gpriv) ||
else
usbhsg_queue_push(uep, ureq);
- if (is_locked)
- spin_unlock_irqrestore(lock, flags);
+ usbhsg_unlock(lock, &flags);
/******************** spin unlock ******************/
usbhsg_queue_prepare(uep);
struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
struct usbhsg_request *ureq = usbhsg_req_to_ureq(req);
struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
- spinlock_t *lock = usbhsg_gpriv_to_lock(gpriv);
+ spinlock_t *lock;
unsigned long flags;
- int is_locked;
/*
* see
*/
/******************** spin lock ********************/
- is_locked = spin_trylock_irqsave(lock, flags);
+ lock = usbhsg_trylock(gpriv, &flags);
usbhsg_queue_pop(uep, ureq, -ECONNRESET);
- if (is_locked)
- spin_unlock_irqrestore(lock, flags);
+ usbhsg_unlock(lock, &flags);
/******************** spin unlock ******************/
return 0;
struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
struct device *dev = usbhsg_gpriv_to_dev(gpriv);
- spinlock_t *lock = usbhsg_gpriv_to_lock(gpriv);
+ spinlock_t *lock;
unsigned long flags;
int ret = -EAGAIN;
- int is_locked;
/*
* see
*/
/******************** spin lock ********************/
- is_locked = spin_trylock_irqsave(lock, flags);
+ lock = usbhsg_trylock(gpriv, &flags);
if (!usbhsg_queue_get(uep)) {
dev_dbg(dev, "set halt %d (pipe %d)\n",
halt, usbhs_pipe_number(pipe));
if (halt)
- usbhs_fifo_stall(pipe);
+ usbhs_pipe_stall(pipe);
else
- usbhs_fifo_disable(pipe);
+ usbhs_pipe_disable(pipe);
if (halt && wedge)
usbhsg_status_set(gpriv, USBHSG_STATUS_WEDGE);
ret = 0;
}
- if (is_locked)
- spin_unlock_irqrestore(lock, flags);
+ usbhsg_unlock(lock, &flags);
/******************** spin unlock ******************/
return ret;
struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv);
struct usbhs_mod *mod = usbhs_mod_get_current(priv);
struct device *dev = usbhs_priv_to_dev(priv);
- spinlock_t *lock = usbhsg_gpriv_to_lock(gpriv);
+ spinlock_t *lock;
unsigned long flags;
/******************** spin lock ********************/
- spin_lock_irqsave(lock, flags);
+ lock = usbhsg_trylock(gpriv, &flags);
/*
* enable interrupt and systems if ready
/*
* 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);
/*
usbhs_irq_callback_update(priv, mod);
usbhsg_try_start_unlock:
- spin_unlock_irqrestore(lock, flags);
+ usbhsg_unlock(lock, &flags);
/******************** spin unlock ********************/
return 0;
struct usbhs_mod *mod = usbhs_mod_get_current(priv);
struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv);
struct device *dev = usbhs_priv_to_dev(priv);
- spinlock_t *lock = usbhsg_gpriv_to_lock(gpriv);
+ spinlock_t *lock;
unsigned long flags;
/******************** spin lock ********************/
- spin_lock_irqsave(lock, flags);
+ lock = usbhsg_trylock(gpriv, &flags);
/*
* disable interrupt and systems if 1st try
usbhs_sys_function_ctrl(priv, 0);
usbhs_sys_usb_ctrl(priv, 0);
- spin_unlock_irqrestore(lock, flags);
+ usbhsg_unlock(lock, &flags);
/******************** spin unlock ********************/
if (gpriv->driver &&
return 0;
usbhsg_try_stop_unlock:
- spin_unlock_irqrestore(lock, flags);
+ usbhsg_unlock(lock, &flags);
return 0;
}