From: Maxim Levitsky <maximlevitsky@gmail.com>
To: Alex Dubov <oakad@yahoo.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>,
Maxim Levitsky <maximlevitsky@gmail.com>
Subject: [PATCH 05/29] memstick: mspro_block: move declarations to header and refactor things a bit
Date: Sat, 23 Oct 2010 01:53:33 +0200 [thread overview]
Message-ID: <1287791637-10329-6-git-send-email-maximlevitsky@gmail.com> (raw)
In-Reply-To: <1287791637-10329-1-git-send-email-maximlevitsky@gmail.com>
This makes it much easier to lookup things and reduces size of mspro_block.c
Also add debbuging macros so that it becames possible to control
debbuging via module param.
Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
---
drivers/memstick/core/mspro_block.c | 157 ++-----------------------------
drivers/memstick/core/mspro_block.h | 176 +++++++++++++++++++++++++++++++++++
2 files changed, 185 insertions(+), 148 deletions(-)
create mode 100644 drivers/memstick/core/mspro_block.h
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index d3f1a08..5dc8fd7 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -20,158 +20,14 @@
#include <linux/slab.h>
#include <linux/smp_lock.h>
#include <linux/memstick.h>
-
-#define DRIVER_NAME "mspro_block"
+#include "mspro_block.h"
static int major;
-module_param(major, int, 0644);
-
-#define MSPRO_BLOCK_MAX_SEGS 32
-#define MSPRO_BLOCK_MAX_PAGES ((2 << 16) - 1)
-
-#define MSPRO_BLOCK_SIGNATURE 0xa5c3
-#define MSPRO_BLOCK_MAX_ATTRIBUTES 41
-
-#define MSPRO_BLOCK_PART_SHIFT 3
-
-enum {
- MSPRO_BLOCK_ID_SYSINFO = 0x10,
- MSPRO_BLOCK_ID_MODELNAME = 0x15,
- MSPRO_BLOCK_ID_MBR = 0x20,
- MSPRO_BLOCK_ID_PBR16 = 0x21,
- MSPRO_BLOCK_ID_PBR32 = 0x22,
- MSPRO_BLOCK_ID_SPECFILEVALUES1 = 0x25,
- MSPRO_BLOCK_ID_SPECFILEVALUES2 = 0x26,
- MSPRO_BLOCK_ID_DEVINFO = 0x30
-};
-
-struct mspro_sys_attr {
- size_t size;
- void *data;
- unsigned char id;
- char name[32];
- struct device_attribute dev_attr;
-};
-
-struct mspro_attr_entry {
- __be32 address;
- __be32 size;
- unsigned char id;
- unsigned char reserved[3];
-} __attribute__((packed));
-
-struct mspro_attribute {
- __be16 signature;
- unsigned short version;
- unsigned char count;
- unsigned char reserved[11];
- struct mspro_attr_entry entries[];
-} __attribute__((packed));
-
-struct mspro_sys_info {
- unsigned char class;
- unsigned char reserved0;
- __be16 block_size;
- __be16 block_count;
- __be16 user_block_count;
- __be16 page_size;
- unsigned char reserved1[2];
- unsigned char assembly_date[8];
- __be32 serial_number;
- unsigned char assembly_maker_code;
- unsigned char assembly_model_code[3];
- __be16 memory_maker_code;
- __be16 memory_model_code;
- unsigned char reserved2[4];
- unsigned char vcc;
- unsigned char vpp;
- __be16 controller_number;
- __be16 controller_function;
- __be16 start_sector;
- __be16 unit_size;
- unsigned char ms_sub_class;
- unsigned char reserved3[4];
- unsigned char interface_type;
- __be16 controller_code;
- unsigned char format_type;
- unsigned char reserved4;
- unsigned char device_type;
- unsigned char reserved5[7];
- unsigned char mspro_id[16];
- unsigned char reserved6[16];
-} __attribute__((packed));
-
-struct mspro_mbr {
- unsigned char boot_partition;
- unsigned char start_head;
- unsigned char start_sector;
- unsigned char start_cylinder;
- unsigned char partition_type;
- unsigned char end_head;
- unsigned char end_sector;
- unsigned char end_cylinder;
- unsigned int start_sectors;
- unsigned int sectors_per_partition;
-} __attribute__((packed));
-
-struct mspro_specfile {
- char name[8];
- char ext[3];
- unsigned char attr;
- unsigned char reserved[10];
- unsigned short time;
- unsigned short date;
- unsigned short cluster;
- unsigned int size;
-} __attribute__((packed));
-
-struct mspro_devinfo {
- __be16 cylinders;
- __be16 heads;
- __be16 bytes_per_track;
- __be16 bytes_per_sector;
- __be16 sectors_per_track;
- unsigned char reserved[6];
-} __attribute__((packed));
-
-struct mspro_block_data {
- struct memstick_dev *card;
- unsigned int usage_count;
- unsigned int caps;
- struct gendisk *disk;
- struct request_queue *queue;
- struct request *block_req;
- spinlock_t q_lock;
-
- unsigned short page_size;
- unsigned short cylinders;
- unsigned short heads;
- unsigned short sectors_per_track;
-
- unsigned char system;
- unsigned char read_only:1,
- eject:1,
- has_request:1,
- data_dir:1,
- active:1;
- unsigned char transfer_cmd;
-
- int (*mrq_handler)(struct memstick_dev *card,
- struct memstick_request **mrq);
-
- struct attribute_group attr_group;
-
- struct scatterlist req_sg[MSPRO_BLOCK_MAX_SEGS];
- unsigned int seg_count;
- unsigned int current_seg;
- unsigned int current_page;
-};
+static int debug;
static DEFINE_IDR(mspro_block_disk_idr);
static DEFINE_MUTEX(mspro_block_disk_lock);
-static int mspro_block_complete_req(struct memstick_dev *card, int error);
-
/*** Block device ***/
static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
@@ -1202,6 +1058,7 @@ static int mspro_block_init_disk(struct memstick_dev *card)
msb->cylinders = be16_to_cpu(dev_info->cylinders);
msb->heads = be16_to_cpu(dev_info->heads);
msb->sectors_per_track = be16_to_cpu(dev_info->sectors_per_track);
+ sg_init_table(msb->req_sg, MSPRO_BLOCK_MAX_SEGS);
msb->page_size = be16_to_cpu(sys_info->unit_size);
@@ -1257,7 +1114,7 @@ static int mspro_block_init_disk(struct memstick_dev *card)
capacity *= be16_to_cpu(sys_info->block_size);
capacity *= msb->page_size >> 9;
set_capacity(msb->disk, capacity);
- dev_dbg(&card->dev, "capacity set %ld\n", capacity);
+ dbg(card, "capacity set %ld", capacity);
add_disk(msb->disk);
msb->active = 1;
@@ -1345,7 +1202,7 @@ static void mspro_block_remove(struct memstick_dev *card)
spin_unlock_irqrestore(&msb->q_lock, flags);
del_gendisk(msb->disk);
- dev_dbg(&card->dev, "mspro block remove\n");
+ dbg(card, "mspro block remove");
blk_cleanup_queue(msb->queue);
msb->queue = NULL;
@@ -1485,6 +1342,10 @@ static void __exit mspro_block_exit(void)
module_init(mspro_block_init);
module_exit(mspro_block_exit);
+module_param(major, int, 0644);
+module_param(debug, int, 0644);
+
+
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Alex Dubov");
MODULE_DESCRIPTION("Sony MemoryStickPro block device driver");
diff --git a/drivers/memstick/core/mspro_block.h b/drivers/memstick/core/mspro_block.h
new file mode 100644
index 0000000..afb29f8
--- /dev/null
+++ b/drivers/memstick/core/mspro_block.h
@@ -0,0 +1,176 @@
+/*
+ * Sony MemoryStick Pro storage support
+ *
+ * Copyright (C) 2007 Alex Dubov <oakad@yahoo.com>
+ * Copyright (C) 2010 Maxim Levitsky <maximlevitsky@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Special thanks to Carlos Corbacho for providing various MemoryStick cards
+ * that made this driver possible.
+ *
+ */
+
+#define DRIVER_NAME "mspro_block"
+
+#define MSPRO_BLOCK_MAX_SEGS 32
+#define MSPRO_BLOCK_MAX_PAGES ((2 << 16) - 1)
+
+#define MSPRO_BLOCK_SIGNATURE 0xa5c3
+#define MSPRO_BLOCK_MAX_ATTRIBUTES 41
+
+#define MSPRO_BLOCK_PART_SHIFT 3
+
+enum {
+ MSPRO_BLOCK_ID_SYSINFO = 0x10,
+ MSPRO_BLOCK_ID_MODELNAME = 0x15,
+ MSPRO_BLOCK_ID_MBR = 0x20,
+ MSPRO_BLOCK_ID_PBR16 = 0x21,
+ MSPRO_BLOCK_ID_PBR32 = 0x22,
+ MSPRO_BLOCK_ID_SPECFILEVALUES1 = 0x25,
+ MSPRO_BLOCK_ID_SPECFILEVALUES2 = 0x26,
+ MSPRO_BLOCK_ID_DEVINFO = 0x30
+};
+
+struct mspro_sys_attr {
+ size_t size;
+ void *data;
+ unsigned char id;
+ char name[32];
+ struct device_attribute dev_attr;
+};
+
+struct mspro_attr_entry {
+ __be32 address;
+ __be32 size;
+ unsigned char id;
+ unsigned char reserved[3];
+} __packed;
+
+struct mspro_attribute {
+ __be16 signature;
+ unsigned short version;
+ unsigned char count;
+ unsigned char reserved[11];
+ struct mspro_attr_entry entries[];
+} __packed;
+
+struct mspro_sys_info {
+ unsigned char class;
+ unsigned char reserved0;
+ __be16 block_size;
+ __be16 block_count;
+ __be16 user_block_count;
+ __be16 page_size;
+ unsigned char reserved1[2];
+ unsigned char assembly_date[8];
+ __be32 serial_number;
+ unsigned char assembly_maker_code;
+ unsigned char assembly_model_code[3];
+ __be16 memory_maker_code;
+ __be16 memory_model_code;
+ unsigned char reserved2[4];
+ unsigned char vcc;
+ unsigned char vpp;
+ __be16 controller_number;
+ __be16 controller_function;
+ __be16 start_sector;
+ __be16 unit_size;
+ unsigned char ms_sub_class;
+ unsigned char reserved3[4];
+ unsigned char interface_type;
+ __be16 controller_code;
+ unsigned char format_type;
+ unsigned char reserved4;
+ unsigned char device_type;
+ unsigned char reserved5[7];
+ unsigned char mspro_id[16];
+ unsigned char reserved6[16];
+} __packed;
+
+struct mspro_mbr {
+ unsigned char boot_partition;
+ unsigned char start_head;
+ unsigned char start_sector;
+ unsigned char start_cylinder;
+ unsigned char partition_type;
+ unsigned char end_head;
+ unsigned char end_sector;
+ unsigned char end_cylinder;
+ unsigned int start_sectors;
+ unsigned int sectors_per_partition;
+} __packed;
+
+struct mspro_specfile {
+ char name[8];
+ char ext[3];
+ unsigned char attr;
+ unsigned char reserved[10];
+ unsigned short time;
+ unsigned short date;
+ unsigned short cluster;
+ unsigned int size;
+} __packed;
+
+struct mspro_devinfo {
+ __be16 cylinders;
+ __be16 heads;
+ __be16 bytes_per_track;
+ __be16 bytes_per_sector;
+ __be16 sectors_per_track;
+ unsigned char reserved[6];
+} __packed;
+
+
+
+struct mspro_block_data {
+ struct memstick_dev *card;
+ unsigned int usage_count;
+ unsigned int caps;
+ struct gendisk *disk;
+ struct request_queue *queue;
+ struct request *block_req;
+ spinlock_t q_lock;
+
+ unsigned short page_size;
+ unsigned short cylinders;
+ unsigned short heads;
+ unsigned short sectors_per_track;
+
+ unsigned char system;
+ unsigned char read_only:1,
+ eject:1,
+ has_request:1,
+ data_dir:1,
+ active:1;
+ unsigned char transfer_cmd;
+
+ int (*mrq_handler)(struct memstick_dev *card,
+ struct memstick_request **mrq);
+
+ struct attribute_group attr_group;
+
+ struct scatterlist req_sg[MSPRO_BLOCK_MAX_SEGS];
+ unsigned int seg_count;
+ unsigned int current_seg;
+ unsigned int current_page;
+};
+
+static int mspro_block_complete_req(struct memstick_dev *card, int error);
+static int mspro_block_switch_interface(struct memstick_dev *card);
+static int mspro_block_issue_req(struct memstick_dev *card, int chunk);
+
+#define __dbg(card, level, format, ...) \
+ do { \
+ if (debug >= level) \
+ printk(KERN_DEBUG \
+ "%s: " format "\n", dev_name(&card->dev) \
+ , ## __VA_ARGS__); \
+ else \
+ dev_dbg(&card->dev, format, ## __VA_ARGS__); \
+ } while (0)
+
+#define dbg(card, format, ...) __dbg(card, 1, format, ## __VA_ARGS__)
+#define dbg_v(card, format, ...) __dbg(card, 2, format, ## __VA_ARGS__)
--
1.7.1
next prev parent reply other threads:[~2010-10-22 23:59 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-22 23:53 [PATCH 0/29] My patch queue for memorystick subsystem Maxim Levitsky
2010-10-22 23:53 ` [PATCH 01/29] memstick: core: header cleanups Maxim Levitsky
2010-10-25 14:44 ` Alex Dubov
2010-10-26 1:10 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 02/29] memstick: core: reorder functions This patch just reorders functions in memstick.c So that host specific and card driver specific functions are now grouped together. This makes it easier to understand the code Maxim Levitsky
2010-10-25 14:50 ` Alex Dubov
2010-10-26 1:14 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 03/29] memstick: core: add new functions Maxim Levitsky
2010-10-25 14:56 ` Alex Dubov
2010-10-26 1:20 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 04/29] memstick: core: rework state machines Maxim Levitsky
2010-10-25 15:01 ` Alex Dubov
2010-10-26 1:34 ` Maxim Levitsky
2010-10-22 23:53 ` Maxim Levitsky [this message]
2010-10-25 15:07 ` [PATCH 05/29] memstick: mspro_block: move declarations to header and refactor things a bit Alex Dubov
2010-10-26 1:46 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 06/29] memstick: mspro: kill the BKL Maxim Levitsky
2010-10-25 15:12 ` Alex Dubov
2010-10-26 1:50 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 07/29] memstick: mspro: two fixes Maxim Levitsky
2010-10-25 15:13 ` Alex Dubov
2010-10-26 1:51 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 08/29] memstick: mspro: add comments to few functions Maxim Levitsky
2010-10-25 15:18 ` Alex Dubov
2010-10-26 1:54 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 09/29] memstick: rework state machines + attribute read function Maxim Levitsky
2010-10-25 15:23 ` Alex Dubov
2010-10-26 1:57 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 10/29] memstick: mspro: create _setup_io helper Maxim Levitsky
2010-10-25 15:25 ` Alex Dubov
2010-10-26 1:58 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 11/29] memstick: mspro: use MS_TPC_EX_SET_CMD Maxim Levitsky
2010-10-25 15:27 ` Alex Dubov
2010-10-26 2:00 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 12/29] memstick: mspro: rework interface switch Maxim Levitsky
2010-10-25 15:28 ` Alex Dubov
2010-10-26 2:01 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 13/29] memstick: core: stop passing pointer to card->current_mrq Maxim Levitsky
2010-10-25 15:41 ` Alex Dubov
2010-10-26 2:04 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 14/29] memstick: remove the memstick_set_rw_addr Maxim Levitsky
2010-10-25 15:55 ` Alex Dubov
2010-10-26 2:08 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 15/29] memstick: jmb38x_ms: Create header Maxim Levitsky
2010-10-25 15:56 ` Alex Dubov
2010-10-26 2:10 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 16/29] memstick: jmb38x_ms: s/jmb38x_ms/j38ms/g Maxim Levitsky
2010-10-25 15:58 ` Alex Dubov
2010-10-26 2:13 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 17/29] memstick: jmb38x_ms: move "reg_data" functions together Maxim Levitsky
2010-10-25 16:00 ` Alex Dubov
2010-10-26 2:14 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 18/29] memstick: jmb38x_ms: rename functions Maxim Levitsky
2010-10-25 16:00 ` Alex Dubov
2010-10-26 2:17 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 19/29] memstick: jmb38x_ms: add register read/write functions Maxim Levitsky
2010-10-25 16:03 ` Alex Dubov
2010-10-26 2:19 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 20/29] memstick: jmb38x_ms: rework PIO Maxim Levitsky
2010-10-25 16:05 ` Alex Dubov
2010-10-26 2:21 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 21/29] memstick: jmb38x_ms: rework TPC execution Maxim Levitsky
2010-10-25 16:08 ` Alex Dubov
2010-10-26 2:22 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 22/29] memstick: jmb38x_ms: rework ISR Maxim Levitsky
2010-10-25 16:11 ` Alex Dubov
2010-10-26 2:23 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 23/29] memstick: jmb38x_ms: use DMA for all TPCs with len greater that 8 by default Maxim Levitsky
2010-10-25 16:12 ` Alex Dubov
2010-10-26 2:29 ` Maxim Levitsky
2010-10-22 23:53 ` [PATCH 24/29] memstick: jmb38x_ms: rework processing of the TPC one after another Maxim Levitsky
2010-10-25 16:14 ` Alex Dubov
2010-10-22 23:53 ` [PATCH 25/29] memstick: jmb38x_ms: pass j38ms_host to few functions instead of memstick_host Maxim Levitsky
2010-10-22 23:53 ` [PATCH 26/29] memstick: jmb38x_ms: rework hardware setup/reset Maxim Levitsky
2010-10-25 16:17 ` Alex Dubov
2010-10-22 23:53 ` [PATCH 27/29] memstick: jmb38x_ms: minor additions Maxim Levitsky
2010-10-22 23:53 ` [PATCH 28/29] memstick: add support for legacy memorysticks Maxim Levitsky
2010-10-22 23:53 ` [PATCH 29/29] memstick: Add driver for Ricoh R5C592 Card reader Maxim Levitsky
2010-10-25 2:01 ` [PATCH 0/29] My patch queue for memorystick subsystem Maxim Levitsky
2010-10-25 14:39 ` Alex Dubov
2010-10-25 16:07 ` Andrew Morton
2010-10-25 16:10 ` Alex Dubov
2010-10-26 2:32 ` Maxim Levitsky
2010-10-25 16:25 ` Alex Dubov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1287791637-10329-6-git-send-email-maximlevitsky@gmail.com \
--to=maximlevitsky@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oakad@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome