Skip to content

Commit

Permalink
usb: renesas_usbhs: shrink spin lock area
Browse files Browse the repository at this point in the history
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: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Kuninori Morimoto authored and Greg Kroah-Hartman committed Jun 7, 2011
1 parent 8a2c225 commit 97664a2
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 291 deletions.
4 changes: 4 additions & 0 deletions drivers/usb/renesas_usbhs/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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
*/
Expand Down
138 changes: 96 additions & 42 deletions drivers/usb/renesas_usbhs/fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/*
* 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 device *dev = usbhs_priv_to_dev(priv);
Expand All @@ -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 device *dev = usbhs_priv_to_dev(priv);
unsigned long flags;

/******************** spin lock ********************/
usbhs_lock(priv, flags);

if (!handler) {
dev_err(dev, "no handler function\n");
Expand All @@ -63,21 +67,89 @@ void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
pkt->length = len;
pkt->zero = zero;
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);
}

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))
return NULL;

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
*/
Expand Down Expand Up @@ -188,18 +260,17 @@ static int usbhsf_fifo_select(struct usbhs_pipe *pipe, int write)
/*
* 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_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);
void __iomem *addr = priv->base + CFIFO;
u8 *buf;
int maxp = usbhs_pipe_get_maxpacket(pipe);
int total_len;
int i, ret, len;
int is_short, is_done;
int is_short;

ret = usbhsf_fifo_select(pipe, 1);
if (ret < 0)
Expand Down Expand Up @@ -240,33 +311,31 @@ static int usbhsf_try_push(struct usbhs_pkt *pkt)
pkt->actual += total_len;

if (pkt->actual < pkt->length)
is_done = 0; /* there are remainder data */
*is_done = 0; /* there are remainder data */
else if (is_short)
is_done = 1; /* short packet */
*is_done = 1; /* short packet */
else
is_done = !pkt->zero; /* send zero packet ? */
*is_done = !pkt->zero; /* send zero packet ? */

/*
* pipe/irq handling
*/
if (is_short)
usbhsf_send_terminator(pipe);

usbhsf_tx_irq_ctrl(pipe, !is_done);
usbhsf_tx_irq_ctrl(pipe, !*is_done);
usbhs_pipe_enable(pipe);

dev_dbg(dev, " send %d (%d/ %d/ %d/ %d)\n",
usbhs_pipe_number(pipe),
pkt->length, pkt->actual, is_done, pkt->zero);
pkt->length, pkt->actual, *is_done, pkt->zero);

/*
* Transmission end
*/
if (is_done) {
if (*is_done) {
if (usbhs_pipe_is_dcp(pipe))
usbhs_dcp_control_transfer_done(pipe);

info->done(pkt);
}

return 0;
Expand All @@ -286,7 +355,7 @@ struct usbhs_pkt_handle usbhs_fifo_push_handler = {
.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;
int ret;
Expand All @@ -304,7 +373,7 @@ static int usbhsf_prepare_pop(struct usbhs_pkt *pkt)
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_priv *priv = usbhs_pipe_to_priv(pipe);
Expand All @@ -316,7 +385,6 @@ static int usbhsf_try_pop(struct usbhs_pkt *pkt)
int rcv_len, len;
int i, ret;
int total_len = 0;
int is_done = 0;

ret = usbhsf_fifo_select(pipe, 0);
if (ret < 0)
Expand Down Expand Up @@ -367,22 +435,16 @@ static int usbhsf_try_pop(struct usbhs_pkt *pkt)

usbhs_fifo_read_end:
if ((pkt->actual == pkt->length) || /* receive all data */
(total_len < maxp)) /* short packet */
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);

(total_len < maxp)) { /* short packet */
*is_done = 1;
usbhsf_rx_irq_ctrl(pipe, 0);
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;
}

Expand All @@ -394,15 +456,11 @@ struct usbhs_pkt_handle usbhs_fifo_pop_handler = {
/*
* 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;
struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
usbhs_dcp_control_transfer_done(pkt->pipe);

usbhs_dcp_control_transfer_done(pipe);

info->done(pkt);
*is_done = 1;

return 0;
}
Expand All @@ -419,7 +477,6 @@ static int usbhsf_irq_empty(struct usbhs_priv *priv,
struct usbhs_irq_state *irq_state)
{
struct usbhs_pipe *pipe;
struct usbhs_pkt *pkt;
struct device *dev = usbhs_priv_to_dev(priv);
int i, ret;

Expand All @@ -438,8 +495,7 @@ static int usbhsf_irq_empty(struct usbhs_priv *priv,
if (!(irq_state->bempsts & (1 << i)))
continue;

pkt = usbhs_pkt_get(pipe);
ret = usbhs_pkt_run(pkt);
ret = usbhs_pkt_run(pipe);
if (ret < 0)
dev_err(dev, "irq_empty run_error %d : %d\n", i, ret);
}
Expand All @@ -451,7 +507,6 @@ static int usbhsf_irq_ready(struct usbhs_priv *priv,
struct usbhs_irq_state *irq_state)
{
struct usbhs_pipe *pipe;
struct usbhs_pkt *pkt;
struct device *dev = usbhs_priv_to_dev(priv);
int i, ret;

Expand All @@ -470,8 +525,7 @@ static int usbhsf_irq_ready(struct usbhs_priv *priv,
if (!(irq_state->brdysts & (1 << i)))
continue;

pkt = usbhs_pkt_get(pipe);
ret = usbhs_pkt_run(pkt);
ret = usbhs_pkt_run(pipe);
if (ret < 0)
dev_err(dev, "irq_ready run_error %d : %d\n", i, ret);
}
Expand Down
17 changes: 11 additions & 6 deletions drivers/usb/renesas_usbhs/fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ struct usbhs_pkt {
};

struct usbhs_pkt_handle {
int (*prepare)(struct usbhs_pkt *pkt);
int (*try_run)(struct usbhs_pkt *pkt);
int (*prepare)(struct usbhs_pkt *pkt, int *is_done);
int (*try_run)(struct usbhs_pkt *pkt, int *is_done);
};

/*
Expand All @@ -44,6 +44,11 @@ void usbhs_fifo_quit(struct usbhs_priv *priv);
/*
* 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_pop_handler;
extern struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler;
Expand All @@ -52,10 +57,10 @@ void usbhs_pkt_init(struct usbhs_pkt *pkt);
void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
struct usbhs_pkt_handle *handler,
void *buf, int len, int zero);
void usbhs_pkt_pop(struct usbhs_pkt *pkt);
struct usbhs_pkt *usbhs_pkt_get(struct usbhs_pipe *pipe);
struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt);
int __usbhs_pkt_handler(struct usbhs_pipe *pipe, int type);

#define usbhs_pkt_start(p) ((p)->handler->prepare(p))
#define usbhs_pkt_run(p) ((p)->handler->try_run(p))
#define usbhs_pkt_start(p) __usbhs_pkt_handler(p, USBHSF_PKT_PREPARE)
#define usbhs_pkt_run(p) __usbhs_pkt_handler(p, USBHSF_PKT_TRY_RUN)

#endif /* RENESAS_USB_FIFO_H */
Loading

0 comments on commit 97664a2

Please sign in to comment.