Commit 97664a20 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Greg Kroah-Hartman

usb: renesas_usbhs: shrink spin lock area

spin lock was very effective while doing 1 packet send/recv on
current renesas_usbhs driver.
But this lock is enough only
 - modify packet/pipe link
 - modify interrpt mask
 - modify fifo access
This patch shrink spin lock area
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 8a2c225d
...@@ -204,6 +204,10 @@ void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data); ...@@ -204,6 +204,10 @@ void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data);
void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data); void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data);
int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev); int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev);
#define usbhs_lock(p, f) spin_lock_irqsave(usbhs_priv_to_lock(p), f)
#define usbhs_unlock(p, f) spin_unlock_irqrestore(usbhs_priv_to_lock(p), f)
/* /*
* sysconfig * sysconfig
*/ */
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
/* /*
* packet info function * packet info function
*/ */
static int usbhsf_null_handle(struct usbhs_pkt *pkt) static int usbhsf_null_handle(struct usbhs_pkt *pkt, int *is_done)
{ {
struct usbhs_priv *priv = usbhs_pipe_to_priv(pkt->pipe); struct usbhs_priv *priv = usbhs_pipe_to_priv(pkt->pipe);
struct device *dev = usbhs_priv_to_dev(priv); struct device *dev = usbhs_priv_to_dev(priv);
...@@ -48,6 +48,10 @@ void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt, ...@@ -48,6 +48,10 @@ void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
{ {
struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
struct device *dev = usbhs_priv_to_dev(priv); struct device *dev = usbhs_priv_to_dev(priv);
unsigned long flags;
/******************** spin lock ********************/
usbhs_lock(priv, flags);
if (!handler) { if (!handler) {
dev_err(dev, "no handler function\n"); dev_err(dev, "no handler function\n");
...@@ -63,14 +67,17 @@ void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt, ...@@ -63,14 +67,17 @@ void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
pkt->length = len; pkt->length = len;
pkt->zero = zero; pkt->zero = zero;
pkt->actual = 0; pkt->actual = 0;
usbhs_unlock(priv, flags);
/******************** spin unlock ******************/
} }
void usbhs_pkt_pop(struct usbhs_pkt *pkt) static void __usbhsf_pkt_del(struct usbhs_pkt *pkt)
{ {
list_del_init(&pkt->node); list_del_init(&pkt->node);
} }
struct usbhs_pkt *usbhs_pkt_get(struct usbhs_pipe *pipe) static struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
{ {
if (list_empty(&pipe->list)) if (list_empty(&pipe->list))
return NULL; return NULL;
...@@ -78,6 +85,71 @@ struct usbhs_pkt *usbhs_pkt_get(struct usbhs_pipe *pipe) ...@@ -78,6 +85,71 @@ struct usbhs_pkt *usbhs_pkt_get(struct usbhs_pipe *pipe)
return list_entry(pipe->list.next, struct usbhs_pkt, node); return list_entry(pipe->list.next, struct usbhs_pkt, node);
} }
struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt)
{
struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
unsigned long flags;
/******************** spin lock ********************/
usbhs_lock(priv, flags);
if (!pkt)
pkt = __usbhsf_pkt_get(pipe);
if (pkt)
__usbhsf_pkt_del(pkt);
usbhs_unlock(priv, flags);
/******************** spin unlock ******************/
return pkt;
}
int __usbhs_pkt_handler(struct usbhs_pipe *pipe, int type)
{
struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
struct usbhs_pkt *pkt;
struct device *dev = usbhs_priv_to_dev(priv);
int (*func)(struct usbhs_pkt *pkt, int *is_done);
unsigned long flags;
int ret = 0;
int is_done = 0;
/******************** spin lock ********************/
usbhs_lock(priv, flags);
pkt = __usbhsf_pkt_get(pipe);
if (!pkt)
goto __usbhs_pkt_handler_end;
switch (type) {
case USBHSF_PKT_PREPARE:
func = pkt->handler->prepare;
break;
case USBHSF_PKT_TRY_RUN:
func = pkt->handler->try_run;
break;
default:
dev_err(dev, "unknown pkt hander\n");
goto __usbhs_pkt_handler_end;
}
ret = func(pkt, &is_done);
if (is_done)
__usbhsf_pkt_del(pkt);
__usbhs_pkt_handler_end:
usbhs_unlock(priv, flags);
/******************** spin unlock ******************/
if (is_done)
info->done(pkt);
return ret;
}
/* /*
* irq enable/disable function * irq enable/disable function
*/ */
...@@ -188,18 +260,17 @@ static int usbhsf_fifo_select(struct usbhs_pipe *pipe, int write) ...@@ -188,18 +260,17 @@ static int usbhsf_fifo_select(struct usbhs_pipe *pipe, int write)
/* /*
* PIO fifo functions * PIO fifo functions
*/ */
static int usbhsf_try_push(struct usbhs_pkt *pkt) static int usbhsf_try_push(struct usbhs_pkt *pkt, int *is_done)
{ {
struct usbhs_pipe *pipe = pkt->pipe; struct usbhs_pipe *pipe = pkt->pipe;
struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
struct device *dev = usbhs_priv_to_dev(priv); struct device *dev = usbhs_priv_to_dev(priv);
void __iomem *addr = priv->base + CFIFO; void __iomem *addr = priv->base + CFIFO;
u8 *buf; u8 *buf;
int maxp = usbhs_pipe_get_maxpacket(pipe); int maxp = usbhs_pipe_get_maxpacket(pipe);
int total_len; int total_len;
int i, ret, len; int i, ret, len;
int is_short, is_done; int is_short;
ret = usbhsf_fifo_select(pipe, 1); ret = usbhsf_fifo_select(pipe, 1);
if (ret < 0) if (ret < 0)
...@@ -240,11 +311,11 @@ static int usbhsf_try_push(struct usbhs_pkt *pkt) ...@@ -240,11 +311,11 @@ static int usbhsf_try_push(struct usbhs_pkt *pkt)
pkt->actual += total_len; pkt->actual += total_len;
if (pkt->actual < pkt->length) if (pkt->actual < pkt->length)
is_done = 0; /* there are remainder data */ *is_done = 0; /* there are remainder data */
else if (is_short) else if (is_short)
is_done = 1; /* short packet */ *is_done = 1; /* short packet */
else else
is_done = !pkt->zero; /* send zero packet ? */ *is_done = !pkt->zero; /* send zero packet ? */
/* /*
* pipe/irq handling * pipe/irq handling
...@@ -252,21 +323,19 @@ static int usbhsf_try_push(struct usbhs_pkt *pkt) ...@@ -252,21 +323,19 @@ static int usbhsf_try_push(struct usbhs_pkt *pkt)
if (is_short) if (is_short)
usbhsf_send_terminator(pipe); usbhsf_send_terminator(pipe);
usbhsf_tx_irq_ctrl(pipe, !is_done); usbhsf_tx_irq_ctrl(pipe, !*is_done);
usbhs_pipe_enable(pipe); usbhs_pipe_enable(pipe);
dev_dbg(dev, " send %d (%d/ %d/ %d/ %d)\n", dev_dbg(dev, " send %d (%d/ %d/ %d/ %d)\n",
usbhs_pipe_number(pipe), usbhs_pipe_number(pipe),
pkt->length, pkt->actual, is_done, pkt->zero); pkt->length, pkt->actual, *is_done, pkt->zero);
/* /*
* Transmission end * Transmission end
*/ */
if (is_done) { if (*is_done) {
if (usbhs_pipe_is_dcp(pipe)) if (usbhs_pipe_is_dcp(pipe))
usbhs_dcp_control_transfer_done(pipe); usbhs_dcp_control_transfer_done(pipe);
info->done(pkt);
} }
return 0; return 0;
...@@ -286,7 +355,7 @@ struct usbhs_pkt_handle usbhs_fifo_push_handler = { ...@@ -286,7 +355,7 @@ struct usbhs_pkt_handle usbhs_fifo_push_handler = {
.try_run = usbhsf_try_push, .try_run = usbhsf_try_push,
}; };
static int usbhsf_prepare_pop(struct usbhs_pkt *pkt) static int usbhsf_prepare_pop(struct usbhs_pkt *pkt, int *is_done)
{ {
struct usbhs_pipe *pipe = pkt->pipe; struct usbhs_pipe *pipe = pkt->pipe;
int ret; int ret;
...@@ -304,7 +373,7 @@ static int usbhsf_prepare_pop(struct usbhs_pkt *pkt) ...@@ -304,7 +373,7 @@ static int usbhsf_prepare_pop(struct usbhs_pkt *pkt)
return ret; return ret;
} }
static int usbhsf_try_pop(struct usbhs_pkt *pkt) static int usbhsf_try_pop(struct usbhs_pkt *pkt, int *is_done)
{ {
struct usbhs_pipe *pipe = pkt->pipe; struct usbhs_pipe *pipe = pkt->pipe;
struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
...@@ -316,7 +385,6 @@ static int usbhsf_try_pop(struct usbhs_pkt *pkt) ...@@ -316,7 +385,6 @@ static int usbhsf_try_pop(struct usbhs_pkt *pkt)
int rcv_len, len; int rcv_len, len;
int i, ret; int i, ret;
int total_len = 0; int total_len = 0;
int is_done = 0;
ret = usbhsf_fifo_select(pipe, 0); ret = usbhsf_fifo_select(pipe, 0);
if (ret < 0) if (ret < 0)
...@@ -367,22 +435,16 @@ static int usbhsf_try_pop(struct usbhs_pkt *pkt) ...@@ -367,22 +435,16 @@ static int usbhsf_try_pop(struct usbhs_pkt *pkt)
usbhs_fifo_read_end: usbhs_fifo_read_end:
if ((pkt->actual == pkt->length) || /* receive all data */ if ((pkt->actual == pkt->length) || /* receive all data */
(total_len < maxp)) /* short packet */ (total_len < maxp)) { /* short packet */
is_done = 1; *is_done = 1;
dev_dbg(dev, " recv %d (%d/ %d/ %d/ %d)\n",
usbhs_pipe_number(pipe),
pkt->length, pkt->actual, is_done, pkt->zero);
if (is_done) {
struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
usbhsf_rx_irq_ctrl(pipe, 0); usbhsf_rx_irq_ctrl(pipe, 0);
usbhs_pipe_disable(pipe); usbhs_pipe_disable(pipe);
info->done(pkt);
} }
dev_dbg(dev, " recv %d (%d/ %d/ %d/ %d)\n",
usbhs_pipe_number(pipe),
pkt->length, pkt->actual, *is_done, pkt->zero);
return 0; return 0;
} }
...@@ -394,15 +456,11 @@ struct usbhs_pkt_handle usbhs_fifo_pop_handler = { ...@@ -394,15 +456,11 @@ struct usbhs_pkt_handle usbhs_fifo_pop_handler = {
/* /*
* handler function * handler function
*/ */
static int usbhsf_ctrl_stage_end(struct usbhs_pkt *pkt) static int usbhsf_ctrl_stage_end(struct usbhs_pkt *pkt, int *is_done)
{ {
struct usbhs_pipe *pipe = pkt->pipe; usbhs_dcp_control_transfer_done(pkt->pipe);
struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
usbhs_dcp_control_transfer_done(pipe);
info->done(pkt); *is_done = 1;
return 0; return 0;
} }
...@@ -419,7 +477,6 @@ static int usbhsf_irq_empty(struct usbhs_priv *priv, ...@@ -419,7 +477,6 @@ static int usbhsf_irq_empty(struct usbhs_priv *priv,
struct usbhs_irq_state *irq_state) struct usbhs_irq_state *irq_state)
{ {
struct usbhs_pipe *pipe; struct usbhs_pipe *pipe;
struct usbhs_pkt *pkt;
struct device *dev = usbhs_priv_to_dev(priv); struct device *dev = usbhs_priv_to_dev(priv);
int i, ret; int i, ret;
...@@ -438,8 +495,7 @@ static int usbhsf_irq_empty(struct usbhs_priv *priv, ...@@ -438,8 +495,7 @@ static int usbhsf_irq_empty(struct usbhs_priv *priv,
if (!(irq_state->bempsts & (1 << i))) if (!(irq_state->bempsts & (1 << i)))
continue; continue;
pkt = usbhs_pkt_get(pipe); ret = usbhs_pkt_run(pipe);
ret = usbhs_pkt_run(pkt);
if (ret < 0) if (ret < 0)
dev_err(dev, "irq_empty run_error %d : %d\n", i, ret); dev_err(dev, "irq_empty run_error %d : %d\n", i, ret);
} }
...@@ -451,7 +507,6 @@ static int usbhsf_irq_ready(struct usbhs_priv *priv, ...@@ -451,7 +507,6 @@ static int usbhsf_irq_ready(struct usbhs_priv *priv,
struct usbhs_irq_state *irq_state) struct usbhs_irq_state *irq_state)
{ {
struct usbhs_pipe *pipe; struct usbhs_pipe *pipe;
struct usbhs_pkt *pkt;
struct device *dev = usbhs_priv_to_dev(priv); struct device *dev = usbhs_priv_to_dev(priv);
int i, ret; int i, ret;
...@@ -470,8 +525,7 @@ static int usbhsf_irq_ready(struct usbhs_priv *priv, ...@@ -470,8 +525,7 @@ static int usbhsf_irq_ready(struct usbhs_priv *priv,
if (!(irq_state->brdysts & (1 << i))) if (!(irq_state->brdysts & (1 << i)))
continue; continue;
pkt = usbhs_pkt_get(pipe); ret = usbhs_pkt_run(pipe);
ret = usbhs_pkt_run(pkt);
if (ret < 0) if (ret < 0)
dev_err(dev, "irq_ready run_error %d : %d\n", i, ret); dev_err(dev, "irq_ready run_error %d : %d\n", i, ret);
} }
......
...@@ -31,8 +31,8 @@ struct usbhs_pkt { ...@@ -31,8 +31,8 @@ struct usbhs_pkt {
}; };
struct usbhs_pkt_handle { struct usbhs_pkt_handle {
int (*prepare)(struct usbhs_pkt *pkt); int (*prepare)(struct usbhs_pkt *pkt, int *is_done);
int (*try_run)(struct usbhs_pkt *pkt); int (*try_run)(struct usbhs_pkt *pkt, int *is_done);
}; };
/* /*
...@@ -44,6 +44,11 @@ void usbhs_fifo_quit(struct usbhs_priv *priv); ...@@ -44,6 +44,11 @@ void usbhs_fifo_quit(struct usbhs_priv *priv);
/* /*
* packet info * packet info
*/ */
enum {
USBHSF_PKT_PREPARE,
USBHSF_PKT_TRY_RUN,
};
extern struct usbhs_pkt_handle usbhs_fifo_push_handler; extern struct usbhs_pkt_handle usbhs_fifo_push_handler;
extern struct usbhs_pkt_handle usbhs_fifo_pop_handler; extern struct usbhs_pkt_handle usbhs_fifo_pop_handler;
extern struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler; extern struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler;
...@@ -52,10 +57,10 @@ void usbhs_pkt_init(struct usbhs_pkt *pkt); ...@@ -52,10 +57,10 @@ void usbhs_pkt_init(struct usbhs_pkt *pkt);
void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt, void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
struct usbhs_pkt_handle *handler, struct usbhs_pkt_handle *handler,
void *buf, int len, int zero); void *buf, int len, int zero);
void usbhs_pkt_pop(struct usbhs_pkt *pkt); struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt);
struct usbhs_pkt *usbhs_pkt_get(struct usbhs_pipe *pipe); int __usbhs_pkt_handler(struct usbhs_pipe *pipe, int type);
#define usbhs_pkt_start(p) ((p)->handler->prepare(p)) #define usbhs_pkt_start(p) __usbhs_pkt_handler(p, USBHSF_PKT_PREPARE)
#define usbhs_pkt_run(p) ((p)->handler->try_run(p)) #define usbhs_pkt_run(p) __usbhs_pkt_handler(p, USBHSF_PKT_TRY_RUN)
#endif /* RENESAS_USB_FIFO_H */ #endif /* RENESAS_USB_FIFO_H */
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment