lkml.org 
[lkml]   [2010]   [Oct]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 04/29] memstick: core: rework state machines
Date
Make state machines in memstick core follow the
new style.

Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
---
drivers/memstick/core/memstick.c | 82 ++++++++++++++++++++-----------------
1 files changed, 44 insertions(+), 38 deletions(-)
diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
index 9fe36c7..e1aa089 100644
--- a/drivers/memstick/core/memstick.c
+++ b/drivers/memstick/core/memstick.c
@@ -211,44 +211,57 @@ static int memstick_dummy_check(struct memstick_dev *card)
*/

static int h_memstick_read_dev_id(struct memstick_dev *card,
- struct memstick_request **mrq)
+ struct memstick_request **mrq)
{
struct ms_id_register id_reg;

- if (!(*mrq)) {
- memstick_init_req(&card->current_mrq, MS_TPC_READ_REG, NULL,
- sizeof(struct ms_id_register));
- *mrq = &card->current_mrq;
- return 0;
- } else {
- if (!(*mrq)->error) {
- memcpy(&id_reg, (*mrq)->data, sizeof(id_reg));
- card->id.match_flags = MEMSTICK_MATCH_ALL;
- card->id.type = id_reg.type;
- card->id.category = id_reg.category;
- card->id.class = id_reg.class;
- dev_dbg(&card->dev, "if_mode = %02x\n", id_reg.if_mode);
- }
- complete(&card->mrq_complete);
- return -EAGAIN;
+ memstick_allocate_request(card, mrq);
+ if ((*mrq)->error)
+ return memstick_exit_state_machine(card, *mrq, (*mrq)->error);
+
+ switch (card->state) {
+ case 0:
+ if (!memstick_read_regs(card,
+ offsetof(struct ms_register, id),
+ sizeof(struct ms_id_register), *mrq))
+ return 0;
+ break;
+ case 1:
+ memcpy(&id_reg, (*mrq)->data, sizeof(id_reg));
+ card->id.match_flags = MEMSTICK_MATCH_ALL;
+ card->id.type = id_reg.type;
+ card->id.category = id_reg.category;
+ card->id.class = id_reg.class;
+ dev_dbg(&card->dev, "if_mode = %02x\n", id_reg.if_mode);
+ return memstick_exit_state_machine(card, *mrq, 0);
}
+
+ card->state++;
+ return 0;
}

static int h_memstick_set_rw_addr(struct memstick_dev *card,
struct memstick_request **mrq)
{
- if (!(*mrq)) {
- memstick_init_req(&card->current_mrq, MS_TPC_SET_RW_REG_ADRS,
+ memstick_allocate_request(card, mrq);
+ if ((*mrq)->error)
+ return memstick_exit_state_machine(card, *mrq, (*mrq)->error);
+
+ switch (card->state) {
+ case 0:
+ memstick_init_req(*mrq, MS_TPC_SET_RW_REG_ADRS,
(char *)&card->reg_addr,
sizeof(card->reg_addr));
- *mrq = &card->current_mrq;
- return 0;
- } else {
- complete(&card->mrq_complete);
- return -EAGAIN;
+ break;
+ case 1:
+ return memstick_exit_state_machine(card, *mrq, 0);
}
+
+ card->state++;
+ return 0;
}

+
static int h_memstick_default_bad(struct memstick_dev *card,
struct memstick_request **mrq)
{
@@ -281,18 +294,18 @@ static struct memstick_dev *memstick_alloc_card(struct memstick_host *host)
card->reg_addr.w_offset = offsetof(struct ms_register, id);
card->reg_addr.w_length = sizeof(id_reg);

+ host->card = card;
init_completion(&card->mrq_complete);
+ card->state = -1;
+ card->next_request = h_memstick_default_bad;

- host->card = card;
if (memstick_set_rw_addr(card))
goto err_out;

- card->next_request = h_memstick_read_dev_id;
- memstick_new_req(host);
- wait_for_completion(&card->mrq_complete);
-
- if (card->current_mrq.error)
+ if (memstick_run_state_machine(card,
+ h_memstick_read_dev_id, true))
goto err_out;
+
}
host->card = old_card;
return card;
@@ -406,11 +419,7 @@ EXPORT_SYMBOL(memstick_unregister_driver);
*/
int memstick_set_rw_addr(struct memstick_dev *card)
{
- card->next_request = h_memstick_set_rw_addr;
- memstick_new_req(card->host);
- wait_for_completion(&card->mrq_complete);
-
- return card->current_mrq.error;
+ return memstick_run_state_machine(card, h_memstick_set_rw_addr, true);
}
EXPORT_SYMBOL(memstick_set_rw_addr);

@@ -481,9 +490,6 @@ EXPORT_SYMBOL(memstick_run_state_machine);
int memstick_exit_state_machine(struct memstick_dev *card,
struct memstick_request *req, int error)
{
- if (error)
- req->error = error;
-
card->state = -1;
card->exit_error = error;
card->next_request = h_memstick_default_bad;
--
1.7.1


\
 
 \ /
  Last update: 2010-10-23 01:57    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site