[PATCH 10/29] memstick: mspro: create _setup_io helper.
From: Maxim Levitsky
Date: Fri Oct 22 2010 - 19:54:32 EST
This function contains common parts of IO setup
for the state machine, thus reduces the risk
of using the state machine in wrong way.
Signed-off-by: Maxim Levitsky <maximlevitsky@xxxxxxxxx>
---
drivers/memstick/core/mspro_block.c | 46 ++++++++++++++++++----------------
1 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index cf98fa8..0d8b30b 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -561,6 +561,26 @@ again:
/*** Data transfer ***/
+/* Common helper that prepares state for IO (read, write, read attributes) */
+static int mspro_block_setup_io(struct memstick_dev *card, int direction,
+ int sector, int pages, unsigned char command)
+{
+ struct mspro_block_data *msb = memstick_get_drvdata(card);
+
+ msb->current_sg_offset = 0;
+ msb->current_sg = msb->req_sg;
+ msb->data_transferred = 0;
+ msb->io_error = 0;
+
+ msb->transfer_cmd = command;
+
+ msb->arg.system = msb->system;
+ msb->arg.data_count = cpu_to_be16(pages);
+ msb->arg.data_address = cpu_to_be32(sector);
+ msb->data_dir = direction;
+ return 0;
+}
+
/*
* Start execution of next block request,
* or continue execution of the current one
@@ -602,18 +622,8 @@ again:
is_read = rq_data_dir(msb->block_req) == READ;
- msb->current_sg_offset = 0;
- msb->current_sg = msb->req_sg;
- msb->data_transferred = 0;
- msb->io_error = 0;
-
- msb->transfer_cmd = is_read ?
- MSPRO_CMD_READ_DATA :MSPRO_CMD_WRITE_DATA;
-
- msb->arg.system = msb->system;
- msb->arg.data_count = cpu_to_be16(pages);
- msb->arg.data_address = cpu_to_be32(sec);
- msb->data_dir = rq_data_dir(msb->block_req);
+ mspro_block_setup_io(card, rq_data_dir(msb->block_req), sec, pages,
+ is_read ? MSPRO_CMD_READ_DATA : MSPRO_CMD_WRITE_DATA);
dbg(card, "IO: %s: lba %x, pages %x", is_read ? "read" : "write",
(unsigned int)sec, pages);
@@ -834,16 +844,8 @@ static int mspro_block_read_attribute(struct memstick_dev *card,
dbg(card, "reading attribute space at offset %08x, size %d",
offset, len);
sg_init_one(&msb->req_sg[0], buffer, len);
- msb->current_sg_offset = 0;
- msb->current_sg = msb->req_sg;
- msb->data_transferred = 0;
- msb->io_error = 0;
- msb->transfer_cmd = MSPRO_CMD_READ_ATRB;
- msb->arg.system = msb->system;
- msb->arg.data_count = cpu_to_be16(len / msb->page_size);
- msb->arg.data_address = cpu_to_be32(offset / msb->page_size);
- msb->data_dir = READ;
-
+ mspro_block_setup_io(card, READ, offset / msb->page_size,
+ len / msb->page_size, MSPRO_CMD_READ_ATRB);
return memstick_run_state_machine(card,
h_mspro_block_transfer_data, true);
}
--
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/