2008-02-10 02:20:54 +08:00
|
|
|
/*
|
|
|
|
* Sony MemoryStick Pro storage support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Alex Dubov <oakad@yahoo.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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/idr.h>
|
|
|
|
#include <linux/hdreg.h>
|
|
|
|
#include <linux/kthread.h>
|
2008-03-11 02:43:42 +08:00
|
|
|
#include <linux/delay.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2010-06-02 20:28:52 +08:00
|
|
|
#include <linux/mutex.h>
|
2008-02-10 02:20:54 +08:00
|
|
|
#include <linux/memstick.h>
|
2011-07-04 03:12:37 +08:00
|
|
|
#include <linux/module.h>
|
2008-02-10 02:20:54 +08:00
|
|
|
|
|
|
|
#define DRIVER_NAME "mspro_block"
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2008-09-13 17:33:26 +08:00
|
|
|
#define MSPRO_BLOCK_PART_SHIFT 3
|
|
|
|
|
2008-02-10 02:20:54 +08:00
|
|
|
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 {
|
2009-01-10 08:40:56 +08:00
|
|
|
__be32 address;
|
|
|
|
__be32 size;
|
2008-02-10 02:20:54 +08:00
|
|
|
unsigned char id;
|
|
|
|
unsigned char reserved[3];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct mspro_attribute {
|
2009-01-10 08:40:56 +08:00
|
|
|
__be16 signature;
|
2008-02-10 02:20:54 +08:00
|
|
|
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;
|
2009-01-10 08:40:56 +08:00
|
|
|
__be16 block_size;
|
|
|
|
__be16 block_count;
|
|
|
|
__be16 user_block_count;
|
|
|
|
__be16 page_size;
|
2008-02-10 02:20:54 +08:00
|
|
|
unsigned char reserved1[2];
|
|
|
|
unsigned char assembly_date[8];
|
2009-01-10 08:40:56 +08:00
|
|
|
__be32 serial_number;
|
2008-02-10 02:20:54 +08:00
|
|
|
unsigned char assembly_maker_code;
|
|
|
|
unsigned char assembly_model_code[3];
|
2009-01-10 08:40:56 +08:00
|
|
|
__be16 memory_maker_code;
|
|
|
|
__be16 memory_model_code;
|
2008-02-10 02:20:54 +08:00
|
|
|
unsigned char reserved2[4];
|
|
|
|
unsigned char vcc;
|
|
|
|
unsigned char vpp;
|
2009-01-10 08:40:56 +08:00
|
|
|
__be16 controller_number;
|
|
|
|
__be16 controller_function;
|
|
|
|
__be16 start_sector;
|
|
|
|
__be16 unit_size;
|
2008-02-10 02:20:54 +08:00
|
|
|
unsigned char ms_sub_class;
|
|
|
|
unsigned char reserved3[4];
|
|
|
|
unsigned char interface_type;
|
2009-01-10 08:40:56 +08:00
|
|
|
__be16 controller_code;
|
2008-02-10 02:20:54 +08:00
|
|
|
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));
|
|
|
|
|
2008-03-11 02:43:41 +08:00
|
|
|
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));
|
|
|
|
|
2008-02-10 02:20:54 +08:00
|
|
|
struct mspro_devinfo {
|
2009-01-10 08:40:56 +08:00
|
|
|
__be16 cylinders;
|
|
|
|
__be16 heads;
|
|
|
|
__be16 bytes_per_track;
|
|
|
|
__be16 bytes_per_sector;
|
|
|
|
__be16 sectors_per_track;
|
2008-02-10 02:20:54 +08:00
|
|
|
unsigned char reserved[6];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct mspro_block_data {
|
|
|
|
struct memstick_dev *card;
|
|
|
|
unsigned int usage_count;
|
2008-03-20 08:01:06 +08:00
|
|
|
unsigned int caps;
|
2008-02-10 02:20:54 +08:00
|
|
|
struct gendisk *disk;
|
|
|
|
struct request_queue *queue;
|
2008-07-26 10:45:02 +08:00
|
|
|
struct request *block_req;
|
2008-02-10 02:20:54 +08:00
|
|
|
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,
|
2008-07-26 10:45:02 +08:00
|
|
|
eject:1,
|
2008-02-10 02:20:54 +08:00
|
|
|
has_request:1,
|
2008-07-26 10:45:02 +08:00
|
|
|
data_dir:1,
|
|
|
|
active:1;
|
2008-02-10 02:20:54 +08:00
|
|
|
unsigned char transfer_cmd;
|
|
|
|
|
|
|
|
int (*mrq_handler)(struct memstick_dev *card,
|
|
|
|
struct memstick_request **mrq);
|
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
|
|
|
|
/* Default request setup function for data access method preferred by
|
|
|
|
* this host instance.
|
|
|
|
*/
|
|
|
|
void (*setup_transfer)(struct memstick_dev *card,
|
|
|
|
u64 offset, size_t length);
|
|
|
|
|
2008-02-10 02:20:54 +08:00
|
|
|
struct attribute_group attr_group;
|
|
|
|
|
|
|
|
struct scatterlist req_sg[MSPRO_BLOCK_MAX_SEGS];
|
|
|
|
unsigned int seg_count;
|
|
|
|
unsigned int current_seg;
|
2008-07-26 10:45:02 +08:00
|
|
|
unsigned int current_page;
|
2008-02-10 02:20:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static DEFINE_IDR(mspro_block_disk_idr);
|
|
|
|
static DEFINE_MUTEX(mspro_block_disk_lock);
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
static int mspro_block_complete_req(struct memstick_dev *card, int error);
|
|
|
|
|
2008-02-10 02:20:54 +08:00
|
|
|
/*** Block device ***/
|
|
|
|
|
2008-03-02 23:31:38 +08:00
|
|
|
static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
|
2008-02-10 02:20:54 +08:00
|
|
|
{
|
2008-03-02 23:31:38 +08:00
|
|
|
struct gendisk *disk = bdev->bd_disk;
|
2008-02-10 02:20:54 +08:00
|
|
|
struct mspro_block_data *msb = disk->private_data;
|
|
|
|
int rc = -ENXIO;
|
|
|
|
|
|
|
|
mutex_lock(&mspro_block_disk_lock);
|
|
|
|
|
|
|
|
if (msb && msb->card) {
|
|
|
|
msb->usage_count++;
|
2008-03-02 23:31:38 +08:00
|
|
|
if ((mode & FMODE_WRITE) && msb->read_only)
|
2008-02-10 02:20:54 +08:00
|
|
|
rc = -EROFS;
|
|
|
|
else
|
|
|
|
rc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&mspro_block_disk_lock);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-06 09:52:57 +08:00
|
|
|
static void mspro_block_disk_release(struct gendisk *disk)
|
2008-02-10 02:20:54 +08:00
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = disk->private_data;
|
2008-09-03 15:01:48 +08:00
|
|
|
int disk_id = MINOR(disk_devt(disk)) >> MSPRO_BLOCK_PART_SHIFT;
|
2008-02-10 02:20:54 +08:00
|
|
|
|
|
|
|
mutex_lock(&mspro_block_disk_lock);
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
if (msb) {
|
|
|
|
if (msb->usage_count)
|
|
|
|
msb->usage_count--;
|
|
|
|
|
2008-02-10 02:20:54 +08:00
|
|
|
if (!msb->usage_count) {
|
|
|
|
kfree(msb);
|
|
|
|
disk->private_data = NULL;
|
|
|
|
idr_remove(&mspro_block_disk_idr, disk_id);
|
|
|
|
put_disk(disk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&mspro_block_disk_lock);
|
|
|
|
}
|
|
|
|
|
2013-05-06 09:52:57 +08:00
|
|
|
static void mspro_block_bd_release(struct gendisk *disk, fmode_t mode)
|
2008-02-10 02:20:54 +08:00
|
|
|
{
|
2013-05-06 09:52:57 +08:00
|
|
|
mspro_block_disk_release(disk);
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mspro_block_bd_getgeo(struct block_device *bdev,
|
|
|
|
struct hd_geometry *geo)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = bdev->bd_disk->private_data;
|
|
|
|
|
|
|
|
geo->heads = msb->heads;
|
|
|
|
geo->sectors = msb->sectors_per_track;
|
|
|
|
geo->cylinders = msb->cylinders;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-22 08:01:13 +08:00
|
|
|
static const struct block_device_operations ms_block_bdops = {
|
2008-03-02 23:31:38 +08:00
|
|
|
.open = mspro_block_bd_open,
|
|
|
|
.release = mspro_block_bd_release,
|
2008-02-10 02:20:54 +08:00
|
|
|
.getgeo = mspro_block_bd_getgeo,
|
|
|
|
.owner = THIS_MODULE
|
|
|
|
};
|
|
|
|
|
|
|
|
/*** Information ***/
|
|
|
|
|
|
|
|
static struct mspro_sys_attr *mspro_from_sysfs_attr(struct attribute *attr)
|
|
|
|
{
|
|
|
|
struct device_attribute *dev_attr
|
|
|
|
= container_of(attr, struct device_attribute, attr);
|
|
|
|
return container_of(dev_attr, struct mspro_sys_attr, dev_attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *mspro_block_attr_name(unsigned char tag)
|
|
|
|
{
|
|
|
|
switch (tag) {
|
|
|
|
case MSPRO_BLOCK_ID_SYSINFO:
|
|
|
|
return "attr_sysinfo";
|
|
|
|
case MSPRO_BLOCK_ID_MODELNAME:
|
|
|
|
return "attr_modelname";
|
|
|
|
case MSPRO_BLOCK_ID_MBR:
|
|
|
|
return "attr_mbr";
|
|
|
|
case MSPRO_BLOCK_ID_PBR16:
|
|
|
|
return "attr_pbr16";
|
|
|
|
case MSPRO_BLOCK_ID_PBR32:
|
|
|
|
return "attr_pbr32";
|
|
|
|
case MSPRO_BLOCK_ID_SPECFILEVALUES1:
|
|
|
|
return "attr_specfilevalues1";
|
|
|
|
case MSPRO_BLOCK_ID_SPECFILEVALUES2:
|
|
|
|
return "attr_specfilevalues2";
|
|
|
|
case MSPRO_BLOCK_ID_DEVINFO:
|
|
|
|
return "attr_devinfo";
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef ssize_t (*sysfs_show_t)(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buffer);
|
|
|
|
|
|
|
|
static ssize_t mspro_block_attr_show_default(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buffer)
|
|
|
|
{
|
|
|
|
struct mspro_sys_attr *s_attr = container_of(attr,
|
|
|
|
struct mspro_sys_attr,
|
|
|
|
dev_attr);
|
|
|
|
|
|
|
|
ssize_t cnt, rc = 0;
|
|
|
|
|
|
|
|
for (cnt = 0; cnt < s_attr->size; cnt++) {
|
|
|
|
if (cnt && !(cnt % 16)) {
|
|
|
|
if (PAGE_SIZE - rc)
|
|
|
|
buffer[rc++] = '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "%02x ",
|
|
|
|
((unsigned char *)s_attr->data)[cnt]);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t mspro_block_attr_show_sysinfo(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buffer)
|
|
|
|
{
|
|
|
|
struct mspro_sys_attr *x_attr = container_of(attr,
|
|
|
|
struct mspro_sys_attr,
|
|
|
|
dev_attr);
|
|
|
|
struct mspro_sys_info *x_sys = x_attr->data;
|
|
|
|
ssize_t rc = 0;
|
2008-03-11 02:43:42 +08:00
|
|
|
int date_tz = 0, date_tz_f = 0;
|
|
|
|
|
|
|
|
if (x_sys->assembly_date[0] > 0x80U) {
|
|
|
|
date_tz = (~x_sys->assembly_date[0]) + 1;
|
|
|
|
date_tz_f = date_tz & 3;
|
|
|
|
date_tz >>= 2;
|
|
|
|
date_tz = -date_tz;
|
|
|
|
date_tz_f *= 15;
|
|
|
|
} else if (x_sys->assembly_date[0] < 0x80U) {
|
|
|
|
date_tz = x_sys->assembly_date[0];
|
|
|
|
date_tz_f = date_tz & 3;
|
|
|
|
date_tz >>= 2;
|
|
|
|
date_tz_f *= 15;
|
|
|
|
}
|
2008-02-10 02:20:54 +08:00
|
|
|
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "class: %x\n",
|
|
|
|
x_sys->class);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "block size: %x\n",
|
|
|
|
be16_to_cpu(x_sys->block_size));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "block count: %x\n",
|
|
|
|
be16_to_cpu(x_sys->block_count));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "user block count: %x\n",
|
|
|
|
be16_to_cpu(x_sys->user_block_count));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "page size: %x\n",
|
|
|
|
be16_to_cpu(x_sys->page_size));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "assembly date: "
|
2008-03-11 02:43:42 +08:00
|
|
|
"GMT%+d:%d %04u-%02u-%02u %02u:%02u:%02u\n",
|
|
|
|
date_tz, date_tz_f,
|
2009-01-10 08:40:56 +08:00
|
|
|
be16_to_cpup((__be16 *)&x_sys->assembly_date[1]),
|
2008-02-10 02:20:54 +08:00
|
|
|
x_sys->assembly_date[3], x_sys->assembly_date[4],
|
|
|
|
x_sys->assembly_date[5], x_sys->assembly_date[6],
|
|
|
|
x_sys->assembly_date[7]);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "serial number: %x\n",
|
|
|
|
be32_to_cpu(x_sys->serial_number));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc,
|
|
|
|
"assembly maker code: %x\n",
|
|
|
|
x_sys->assembly_maker_code);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "assembly model code: "
|
|
|
|
"%02x%02x%02x\n", x_sys->assembly_model_code[0],
|
|
|
|
x_sys->assembly_model_code[1],
|
|
|
|
x_sys->assembly_model_code[2]);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "memory maker code: %x\n",
|
|
|
|
be16_to_cpu(x_sys->memory_maker_code));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "memory model code: %x\n",
|
|
|
|
be16_to_cpu(x_sys->memory_model_code));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "vcc: %x\n",
|
|
|
|
x_sys->vcc);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "vpp: %x\n",
|
|
|
|
x_sys->vpp);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "controller number: %x\n",
|
|
|
|
be16_to_cpu(x_sys->controller_number));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc,
|
|
|
|
"controller function: %x\n",
|
|
|
|
be16_to_cpu(x_sys->controller_function));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "start sector: %x\n",
|
|
|
|
be16_to_cpu(x_sys->start_sector));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "unit size: %x\n",
|
|
|
|
be16_to_cpu(x_sys->unit_size));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "sub class: %x\n",
|
|
|
|
x_sys->ms_sub_class);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "interface type: %x\n",
|
|
|
|
x_sys->interface_type);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "controller code: %x\n",
|
|
|
|
be16_to_cpu(x_sys->controller_code));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "format type: %x\n",
|
|
|
|
x_sys->format_type);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "device type: %x\n",
|
|
|
|
x_sys->device_type);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "mspro id: %s\n",
|
|
|
|
x_sys->mspro_id);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t mspro_block_attr_show_modelname(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buffer)
|
|
|
|
{
|
|
|
|
struct mspro_sys_attr *s_attr = container_of(attr,
|
|
|
|
struct mspro_sys_attr,
|
|
|
|
dev_attr);
|
|
|
|
|
|
|
|
return scnprintf(buffer, PAGE_SIZE, "%s", (char *)s_attr->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t mspro_block_attr_show_mbr(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buffer)
|
|
|
|
{
|
|
|
|
struct mspro_sys_attr *x_attr = container_of(attr,
|
|
|
|
struct mspro_sys_attr,
|
|
|
|
dev_attr);
|
|
|
|
struct mspro_mbr *x_mbr = x_attr->data;
|
|
|
|
ssize_t rc = 0;
|
|
|
|
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "boot partition: %x\n",
|
|
|
|
x_mbr->boot_partition);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "start head: %x\n",
|
|
|
|
x_mbr->start_head);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "start sector: %x\n",
|
|
|
|
x_mbr->start_sector);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "start cylinder: %x\n",
|
|
|
|
x_mbr->start_cylinder);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "partition type: %x\n",
|
|
|
|
x_mbr->partition_type);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "end head: %x\n",
|
|
|
|
x_mbr->end_head);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "end sector: %x\n",
|
|
|
|
x_mbr->end_sector);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "end cylinder: %x\n",
|
|
|
|
x_mbr->end_cylinder);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "start sectors: %x\n",
|
|
|
|
x_mbr->start_sectors);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc,
|
|
|
|
"sectors per partition: %x\n",
|
|
|
|
x_mbr->sectors_per_partition);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-03-11 02:43:41 +08:00
|
|
|
static ssize_t mspro_block_attr_show_specfile(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buffer)
|
|
|
|
{
|
|
|
|
struct mspro_sys_attr *x_attr = container_of(attr,
|
|
|
|
struct mspro_sys_attr,
|
|
|
|
dev_attr);
|
|
|
|
struct mspro_specfile *x_spfile = x_attr->data;
|
|
|
|
char name[9], ext[4];
|
|
|
|
ssize_t rc = 0;
|
|
|
|
|
|
|
|
memcpy(name, x_spfile->name, 8);
|
|
|
|
name[8] = 0;
|
|
|
|
memcpy(ext, x_spfile->ext, 3);
|
|
|
|
ext[3] = 0;
|
|
|
|
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "name: %s\n", name);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "ext: %s\n", ext);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "attribute: %x\n",
|
|
|
|
x_spfile->attr);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "time: %d:%d:%d\n",
|
|
|
|
x_spfile->time >> 11,
|
|
|
|
(x_spfile->time >> 5) & 0x3f,
|
|
|
|
(x_spfile->time & 0x1f) * 2);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "date: %d-%d-%d\n",
|
|
|
|
(x_spfile->date >> 9) + 1980,
|
|
|
|
(x_spfile->date >> 5) & 0xf,
|
|
|
|
x_spfile->date & 0x1f);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "start cluster: %x\n",
|
|
|
|
x_spfile->cluster);
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "size: %x\n",
|
|
|
|
x_spfile->size);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-02-10 02:20:54 +08:00
|
|
|
static ssize_t mspro_block_attr_show_devinfo(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buffer)
|
|
|
|
{
|
|
|
|
struct mspro_sys_attr *x_attr = container_of(attr,
|
|
|
|
struct mspro_sys_attr,
|
|
|
|
dev_attr);
|
|
|
|
struct mspro_devinfo *x_devinfo = x_attr->data;
|
|
|
|
ssize_t rc = 0;
|
|
|
|
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "cylinders: %x\n",
|
|
|
|
be16_to_cpu(x_devinfo->cylinders));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "heads: %x\n",
|
|
|
|
be16_to_cpu(x_devinfo->heads));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "bytes per track: %x\n",
|
|
|
|
be16_to_cpu(x_devinfo->bytes_per_track));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "bytes per sector: %x\n",
|
|
|
|
be16_to_cpu(x_devinfo->bytes_per_sector));
|
|
|
|
rc += scnprintf(buffer + rc, PAGE_SIZE - rc, "sectors per track: %x\n",
|
|
|
|
be16_to_cpu(x_devinfo->sectors_per_track));
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static sysfs_show_t mspro_block_attr_show(unsigned char tag)
|
|
|
|
{
|
|
|
|
switch (tag) {
|
|
|
|
case MSPRO_BLOCK_ID_SYSINFO:
|
|
|
|
return mspro_block_attr_show_sysinfo;
|
|
|
|
case MSPRO_BLOCK_ID_MODELNAME:
|
|
|
|
return mspro_block_attr_show_modelname;
|
|
|
|
case MSPRO_BLOCK_ID_MBR:
|
|
|
|
return mspro_block_attr_show_mbr;
|
2008-03-11 02:43:41 +08:00
|
|
|
case MSPRO_BLOCK_ID_SPECFILEVALUES1:
|
|
|
|
case MSPRO_BLOCK_ID_SPECFILEVALUES2:
|
|
|
|
return mspro_block_attr_show_specfile;
|
2008-02-10 02:20:54 +08:00
|
|
|
case MSPRO_BLOCK_ID_DEVINFO:
|
|
|
|
return mspro_block_attr_show_devinfo;
|
|
|
|
default:
|
|
|
|
return mspro_block_attr_show_default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** Protocol handlers ***/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions prefixed with "h_" are protocol callbacks. They can be called from
|
|
|
|
* interrupt context. Return value of 0 means that request processing is still
|
|
|
|
* ongoing, while special error value of -EAGAIN means that current request is
|
|
|
|
* finished (and request processor should come back some time later).
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int h_mspro_block_req_init(struct memstick_dev *card,
|
|
|
|
struct memstick_request **mrq)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
|
|
|
|
*mrq = &card->current_mrq;
|
|
|
|
card->next_request = msb->mrq_handler;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int h_mspro_block_default(struct memstick_dev *card,
|
|
|
|
struct memstick_request **mrq)
|
|
|
|
{
|
2008-07-26 10:45:02 +08:00
|
|
|
return mspro_block_complete_req(card, (*mrq)->error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int h_mspro_block_default_bad(struct memstick_dev *card,
|
|
|
|
struct memstick_request **mrq)
|
|
|
|
{
|
|
|
|
return -ENXIO;
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int h_mspro_block_get_ro(struct memstick_dev *card,
|
|
|
|
struct memstick_request **mrq)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
if (!(*mrq)->error) {
|
|
|
|
if ((*mrq)->data[offsetof(struct ms_status_register, status0)]
|
|
|
|
& MEMSTICK_STATUS0_WP)
|
|
|
|
msb->read_only = 1;
|
|
|
|
else
|
|
|
|
msb->read_only = 0;
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
return mspro_block_complete_req(card, (*mrq)->error);
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int h_mspro_block_wait_for_ced(struct memstick_dev *card,
|
|
|
|
struct memstick_request **mrq)
|
|
|
|
{
|
|
|
|
dev_dbg(&card->dev, "wait for ced: value %x\n", (*mrq)->data[0]);
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
if (!(*mrq)->error) {
|
|
|
|
if ((*mrq)->data[0] & (MEMSTICK_INT_CMDNAK | MEMSTICK_INT_ERR))
|
|
|
|
(*mrq)->error = -EFAULT;
|
|
|
|
else if (!((*mrq)->data[0] & MEMSTICK_INT_CED))
|
|
|
|
return 0;
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
return mspro_block_complete_req(card, (*mrq)->error);
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int h_mspro_block_transfer_data(struct memstick_dev *card,
|
|
|
|
struct memstick_request **mrq)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
unsigned char t_val = 0;
|
|
|
|
struct scatterlist t_sg = { 0 };
|
|
|
|
size_t t_offset;
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
if ((*mrq)->error)
|
|
|
|
return mspro_block_complete_req(card, (*mrq)->error);
|
2008-02-10 02:20:54 +08:00
|
|
|
|
|
|
|
switch ((*mrq)->tpc) {
|
|
|
|
case MS_TPC_WRITE_REG:
|
|
|
|
memstick_init_req(*mrq, MS_TPC_SET_CMD, &msb->transfer_cmd, 1);
|
2008-03-20 08:01:06 +08:00
|
|
|
(*mrq)->need_card_int = 1;
|
2008-02-10 02:20:54 +08:00
|
|
|
return 0;
|
|
|
|
case MS_TPC_SET_CMD:
|
|
|
|
t_val = (*mrq)->int_reg;
|
|
|
|
memstick_init_req(*mrq, MS_TPC_GET_INT, NULL, 1);
|
2008-03-20 08:01:06 +08:00
|
|
|
if (msb->caps & MEMSTICK_CAP_AUTO_GET_INT)
|
2008-02-10 02:20:54 +08:00
|
|
|
goto has_int_reg;
|
|
|
|
return 0;
|
|
|
|
case MS_TPC_GET_INT:
|
|
|
|
t_val = (*mrq)->data[0];
|
|
|
|
has_int_reg:
|
|
|
|
if (t_val & (MEMSTICK_INT_CMDNAK | MEMSTICK_INT_ERR)) {
|
|
|
|
t_val = MSPRO_CMD_STOP;
|
|
|
|
memstick_init_req(*mrq, MS_TPC_SET_CMD, &t_val, 1);
|
|
|
|
card->next_request = h_mspro_block_default;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msb->current_page
|
|
|
|
== (msb->req_sg[msb->current_seg].length
|
|
|
|
/ msb->page_size)) {
|
|
|
|
msb->current_page = 0;
|
|
|
|
msb->current_seg++;
|
|
|
|
|
|
|
|
if (msb->current_seg == msb->seg_count) {
|
|
|
|
if (t_val & MEMSTICK_INT_CED) {
|
2008-07-26 10:45:02 +08:00
|
|
|
return mspro_block_complete_req(card,
|
|
|
|
0);
|
2008-02-10 02:20:54 +08:00
|
|
|
} else {
|
|
|
|
card->next_request
|
|
|
|
= h_mspro_block_wait_for_ced;
|
|
|
|
memstick_init_req(*mrq, MS_TPC_GET_INT,
|
|
|
|
NULL, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(t_val & MEMSTICK_INT_BREQ)) {
|
|
|
|
memstick_init_req(*mrq, MS_TPC_GET_INT, NULL, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
t_offset = msb->req_sg[msb->current_seg].offset;
|
|
|
|
t_offset += msb->current_page * msb->page_size;
|
|
|
|
|
|
|
|
sg_set_page(&t_sg,
|
|
|
|
nth_page(sg_page(&(msb->req_sg[msb->current_seg])),
|
|
|
|
t_offset >> PAGE_SHIFT),
|
|
|
|
msb->page_size, offset_in_page(t_offset));
|
|
|
|
|
|
|
|
memstick_init_req_sg(*mrq, msb->data_dir == READ
|
|
|
|
? MS_TPC_READ_LONG_DATA
|
|
|
|
: MS_TPC_WRITE_LONG_DATA,
|
|
|
|
&t_sg);
|
2008-03-20 08:01:06 +08:00
|
|
|
(*mrq)->need_card_int = 1;
|
2008-02-10 02:20:54 +08:00
|
|
|
return 0;
|
|
|
|
case MS_TPC_READ_LONG_DATA:
|
|
|
|
case MS_TPC_WRITE_LONG_DATA:
|
|
|
|
msb->current_page++;
|
2008-03-20 08:01:06 +08:00
|
|
|
if (msb->caps & MEMSTICK_CAP_AUTO_GET_INT) {
|
2008-02-10 02:20:54 +08:00
|
|
|
t_val = (*mrq)->int_reg;
|
|
|
|
goto has_int_reg;
|
|
|
|
} else {
|
|
|
|
memstick_init_req(*mrq, MS_TPC_GET_INT, NULL, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
/*** Transfer setup functions for different access methods. ***/
|
|
|
|
|
|
|
|
/** Setup data transfer request for SET_CMD TPC with arguments in card
|
|
|
|
* registers.
|
|
|
|
*
|
|
|
|
* @card Current media instance
|
|
|
|
* @offset Target data offset in bytes
|
|
|
|
* @length Required transfer length in bytes.
|
|
|
|
*/
|
|
|
|
static void h_mspro_block_setup_cmd(struct memstick_dev *card, u64 offset,
|
|
|
|
size_t length)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
struct mspro_param_register param = {
|
|
|
|
.system = msb->system,
|
|
|
|
.data_count = cpu_to_be16((uint16_t)(length / msb->page_size)),
|
|
|
|
/* ISO C90 warning precludes direct initialization for now. */
|
|
|
|
.data_address = 0,
|
|
|
|
.tpc_param = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
do_div(offset, msb->page_size);
|
|
|
|
param.data_address = cpu_to_be32((uint32_t)offset);
|
|
|
|
|
|
|
|
card->next_request = h_mspro_block_req_init;
|
|
|
|
msb->mrq_handler = h_mspro_block_transfer_data;
|
|
|
|
memstick_init_req(&card->current_mrq, MS_TPC_WRITE_REG,
|
|
|
|
¶m, sizeof(param));
|
|
|
|
}
|
|
|
|
|
2008-02-10 02:20:54 +08:00
|
|
|
/*** Data transfer ***/
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
static int mspro_block_issue_req(struct memstick_dev *card, int chunk)
|
2008-02-10 02:20:54 +08:00
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
2011-01-13 09:01:05 +08:00
|
|
|
u64 t_off;
|
2008-07-26 10:45:02 +08:00
|
|
|
unsigned int count;
|
2008-02-10 02:20:54 +08:00
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
try_again:
|
|
|
|
while (chunk) {
|
|
|
|
msb->current_page = 0;
|
2008-02-10 02:20:54 +08:00
|
|
|
msb->current_seg = 0;
|
2008-07-26 10:45:02 +08:00
|
|
|
msb->seg_count = blk_rq_map_sg(msb->block_req->q,
|
|
|
|
msb->block_req,
|
|
|
|
msb->req_sg);
|
2008-02-10 02:20:54 +08:00
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
if (!msb->seg_count) {
|
2009-05-08 10:54:15 +08:00
|
|
|
chunk = __blk_end_request_cur(msb->block_req, -ENOMEM);
|
2008-07-26 10:45:02 +08:00
|
|
|
continue;
|
|
|
|
}
|
2008-02-10 02:20:54 +08:00
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
t_off = blk_rq_pos(msb->block_req);
|
|
|
|
t_off <<= 9;
|
2009-05-07 21:24:45 +08:00
|
|
|
count = blk_rq_bytes(msb->block_req);
|
2008-02-10 02:20:54 +08:00
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
msb->setup_transfer(card, t_off, count);
|
2008-07-26 10:45:02 +08:00
|
|
|
|
|
|
|
msb->data_dir = rq_data_dir(msb->block_req);
|
|
|
|
msb->transfer_cmd = msb->data_dir == READ
|
|
|
|
? MSPRO_CMD_READ_DATA
|
|
|
|
: MSPRO_CMD_WRITE_DATA;
|
|
|
|
|
|
|
|
memstick_new_req(card->host);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-08 10:54:16 +08:00
|
|
|
dev_dbg(&card->dev, "blk_fetch\n");
|
|
|
|
msb->block_req = blk_fetch_request(msb->queue);
|
2008-07-26 10:45:02 +08:00
|
|
|
if (!msb->block_req) {
|
|
|
|
dev_dbg(&card->dev, "issue end\n");
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(&card->dev, "trying again\n");
|
|
|
|
chunk = 1;
|
|
|
|
goto try_again;
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
static int mspro_block_complete_req(struct memstick_dev *card, int error)
|
2008-02-10 02:20:54 +08:00
|
|
|
{
|
2008-07-26 10:45:02 +08:00
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
int chunk, cnt;
|
|
|
|
unsigned int t_len = 0;
|
2008-02-10 02:20:54 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&msb->q_lock, flags);
|
2008-07-26 10:45:02 +08:00
|
|
|
dev_dbg(&card->dev, "complete %d, %d\n", msb->has_request ? 1 : 0,
|
|
|
|
error);
|
|
|
|
|
|
|
|
if (msb->has_request) {
|
|
|
|
/* Nothing to do - not really an error */
|
|
|
|
if (error == -EAGAIN)
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
if (error || (card->current_mrq.tpc == MSPRO_CMD_STOP)) {
|
|
|
|
if (msb->data_dir == READ) {
|
|
|
|
for (cnt = 0; cnt < msb->current_seg; cnt++)
|
|
|
|
t_len += msb->req_sg[cnt].length
|
|
|
|
/ msb->page_size;
|
|
|
|
|
|
|
|
if (msb->current_page)
|
|
|
|
t_len += msb->current_page - 1;
|
|
|
|
|
|
|
|
t_len *= msb->page_size;
|
|
|
|
}
|
|
|
|
} else
|
2009-05-07 21:24:45 +08:00
|
|
|
t_len = blk_rq_bytes(msb->block_req);
|
2008-07-26 10:45:02 +08:00
|
|
|
|
|
|
|
dev_dbg(&card->dev, "transferred %x (%d)\n", t_len, error);
|
|
|
|
|
|
|
|
if (error && !t_len)
|
|
|
|
t_len = blk_rq_cur_bytes(msb->block_req);
|
|
|
|
|
|
|
|
chunk = __blk_end_request(msb->block_req, error, t_len);
|
|
|
|
|
|
|
|
error = mspro_block_issue_req(card, chunk);
|
|
|
|
|
|
|
|
if (!error)
|
|
|
|
goto out;
|
|
|
|
else
|
|
|
|
msb->has_request = 0;
|
|
|
|
} else {
|
|
|
|
if (!error)
|
|
|
|
error = -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
card->next_request = h_mspro_block_default_bad;
|
|
|
|
complete_all(&card->mrq_complete);
|
|
|
|
out:
|
2008-02-10 02:20:54 +08:00
|
|
|
spin_unlock_irqrestore(&msb->q_lock, flags);
|
2008-07-26 10:45:02 +08:00
|
|
|
return error;
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
|
|
|
|
2008-07-26 10:45:01 +08:00
|
|
|
static void mspro_block_stop(struct memstick_dev *card)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
int rc = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
spin_lock_irqsave(&msb->q_lock, flags);
|
|
|
|
if (!msb->has_request) {
|
|
|
|
blk_stop_queue(msb->queue);
|
|
|
|
rc = 1;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&msb->q_lock, flags);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
|
|
|
|
wait_for_completion(&card->mrq_complete);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mspro_block_start(struct memstick_dev *card)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&msb->q_lock, flags);
|
|
|
|
blk_start_queue(msb->queue);
|
|
|
|
spin_unlock_irqrestore(&msb->q_lock, flags);
|
|
|
|
}
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
static int mspro_block_prepare_req(struct request_queue *q, struct request *req)
|
2008-02-10 02:20:54 +08:00
|
|
|
{
|
2010-08-08 00:17:56 +08:00
|
|
|
if (req->cmd_type != REQ_TYPE_FS &&
|
|
|
|
req->cmd_type != REQ_TYPE_BLOCK_PC) {
|
2008-07-26 10:45:02 +08:00
|
|
|
blk_dump_rq_flags(req, "MSPro unsupported request");
|
|
|
|
return BLKPREP_KILL;
|
|
|
|
}
|
2008-02-10 02:20:54 +08:00
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
req->cmd_flags |= REQ_DONTPREP;
|
2008-02-10 02:20:54 +08:00
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
return BLKPREP_OK;
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
static void mspro_block_submit_req(struct request_queue *q)
|
2008-02-10 02:20:54 +08:00
|
|
|
{
|
|
|
|
struct memstick_dev *card = q->queuedata;
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
struct request *req = NULL;
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
if (msb->has_request)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (msb->eject) {
|
2009-05-08 10:54:16 +08:00
|
|
|
while ((req = blk_fetch_request(q)) != NULL)
|
2009-04-23 10:05:19 +08:00
|
|
|
__blk_end_request_all(req, -ENODEV);
|
2008-07-26 10:45:02 +08:00
|
|
|
|
|
|
|
return;
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
2008-07-26 10:45:02 +08:00
|
|
|
|
|
|
|
msb->has_request = 1;
|
|
|
|
if (mspro_block_issue_req(card, 0))
|
|
|
|
msb->has_request = 0;
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** Initialization ***/
|
|
|
|
|
|
|
|
static int mspro_block_wait_for_ced(struct memstick_dev *card)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
|
|
|
|
card->next_request = h_mspro_block_req_init;
|
|
|
|
msb->mrq_handler = h_mspro_block_wait_for_ced;
|
|
|
|
memstick_init_req(&card->current_mrq, MS_TPC_GET_INT, NULL, 1);
|
|
|
|
memstick_new_req(card->host);
|
|
|
|
wait_for_completion(&card->mrq_complete);
|
|
|
|
return card->current_mrq.error;
|
|
|
|
}
|
|
|
|
|
2008-03-20 08:01:07 +08:00
|
|
|
static int mspro_block_set_interface(struct memstick_dev *card,
|
|
|
|
unsigned char sys_reg)
|
2008-02-10 02:20:54 +08:00
|
|
|
{
|
|
|
|
struct memstick_host *host = card->host;
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
struct mspro_param_register param = {
|
2008-03-20 08:01:07 +08:00
|
|
|
.system = sys_reg,
|
2008-02-10 02:20:54 +08:00
|
|
|
.data_count = 0,
|
|
|
|
.data_address = 0,
|
2008-03-11 02:43:37 +08:00
|
|
|
.tpc_param = 0
|
2008-02-10 02:20:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
card->next_request = h_mspro_block_req_init;
|
|
|
|
msb->mrq_handler = h_mspro_block_default;
|
|
|
|
memstick_init_req(&card->current_mrq, MS_TPC_WRITE_REG, ¶m,
|
|
|
|
sizeof(param));
|
|
|
|
memstick_new_req(host);
|
|
|
|
wait_for_completion(&card->mrq_complete);
|
2008-03-20 08:01:07 +08:00
|
|
|
return card->current_mrq.error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mspro_block_switch_interface(struct memstick_dev *card)
|
|
|
|
{
|
|
|
|
struct memstick_host *host = card->host;
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
int rc = 0;
|
|
|
|
|
2008-09-13 17:33:26 +08:00
|
|
|
try_again:
|
2008-03-20 08:01:07 +08:00
|
|
|
if (msb->caps & MEMSTICK_CAP_PAR4)
|
|
|
|
rc = mspro_block_set_interface(card, MEMSTICK_SYS_PAR4);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"%s: could not switch to 4-bit mode, error %d\n",
|
2009-01-07 02:44:38 +08:00
|
|
|
dev_name(&card->dev), rc);
|
2008-03-20 08:01:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2008-02-10 02:20:54 +08:00
|
|
|
|
2008-03-11 02:43:37 +08:00
|
|
|
msb->system = MEMSTICK_SYS_PAR4;
|
|
|
|
host->set_param(host, MEMSTICK_INTERFACE, MEMSTICK_PAR4);
|
2008-03-20 08:01:07 +08:00
|
|
|
printk(KERN_INFO "%s: switching to 4-bit parallel mode\n",
|
2009-01-07 02:44:38 +08:00
|
|
|
dev_name(&card->dev));
|
2008-03-20 08:01:07 +08:00
|
|
|
|
|
|
|
if (msb->caps & MEMSTICK_CAP_PAR8) {
|
|
|
|
rc = mspro_block_set_interface(card, MEMSTICK_SYS_PAR8);
|
|
|
|
|
|
|
|
if (!rc) {
|
|
|
|
msb->system = MEMSTICK_SYS_PAR8;
|
|
|
|
host->set_param(host, MEMSTICK_INTERFACE,
|
|
|
|
MEMSTICK_PAR8);
|
|
|
|
printk(KERN_INFO
|
|
|
|
"%s: switching to 8-bit parallel mode\n",
|
2009-01-07 02:44:38 +08:00
|
|
|
dev_name(&card->dev));
|
2008-03-20 08:01:07 +08:00
|
|
|
} else
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"%s: could not switch to 8-bit mode, error %d\n",
|
2009-01-07 02:44:38 +08:00
|
|
|
dev_name(&card->dev), rc);
|
2008-03-20 08:01:07 +08:00
|
|
|
}
|
2008-02-10 02:20:54 +08:00
|
|
|
|
|
|
|
card->next_request = h_mspro_block_req_init;
|
|
|
|
msb->mrq_handler = h_mspro_block_default;
|
|
|
|
memstick_init_req(&card->current_mrq, MS_TPC_GET_INT, NULL, 1);
|
|
|
|
memstick_new_req(card->host);
|
|
|
|
wait_for_completion(&card->mrq_complete);
|
2008-03-20 08:01:07 +08:00
|
|
|
rc = card->current_mrq.error;
|
2008-02-10 02:20:54 +08:00
|
|
|
|
2008-03-20 08:01:07 +08:00
|
|
|
if (rc) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"%s: interface error, trying to fall back to serial\n",
|
2009-01-07 02:44:38 +08:00
|
|
|
dev_name(&card->dev));
|
2008-03-11 02:43:42 +08:00
|
|
|
msb->system = MEMSTICK_SYS_SERIAL;
|
|
|
|
host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF);
|
2008-03-20 08:01:07 +08:00
|
|
|
msleep(10);
|
2008-03-11 02:43:42 +08:00
|
|
|
host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_ON);
|
2008-02-10 02:20:54 +08:00
|
|
|
host->set_param(host, MEMSTICK_INTERFACE, MEMSTICK_SERIAL);
|
2008-03-11 02:43:42 +08:00
|
|
|
|
2008-03-20 08:01:07 +08:00
|
|
|
rc = memstick_set_rw_addr(card);
|
|
|
|
if (!rc)
|
|
|
|
rc = mspro_block_set_interface(card, msb->system);
|
2008-09-13 17:33:26 +08:00
|
|
|
|
|
|
|
if (!rc) {
|
|
|
|
msleep(150);
|
|
|
|
rc = mspro_block_wait_for_ced(card);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (msb->caps & MEMSTICK_CAP_PAR8) {
|
|
|
|
msb->caps &= ~MEMSTICK_CAP_PAR8;
|
|
|
|
goto try_again;
|
|
|
|
}
|
|
|
|
}
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
2008-03-20 08:01:07 +08:00
|
|
|
return rc;
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Memory allocated for attributes by this function should be freed by
|
2011-03-31 09:57:33 +08:00
|
|
|
* mspro_block_data_clear, no matter if the initialization process succeeded
|
2008-02-10 02:20:54 +08:00
|
|
|
* or failed.
|
|
|
|
*/
|
|
|
|
static int mspro_block_read_attributes(struct memstick_dev *card)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
struct mspro_attribute *attr = NULL;
|
|
|
|
struct mspro_sys_attr *s_attr = NULL;
|
|
|
|
unsigned char *buffer = NULL;
|
|
|
|
int cnt, rc, attr_count;
|
2011-01-13 09:01:05 +08:00
|
|
|
/* While normally physical device offsets, represented here by
|
|
|
|
* attr_offset and attr_len will be of large numeric types, we can be
|
|
|
|
* sure, that attributes are close enough to the beginning of the
|
|
|
|
* device, to save ourselves some trouble.
|
|
|
|
*/
|
|
|
|
unsigned int addr, attr_offset = 0, attr_len = msb->page_size;
|
2008-02-10 02:20:54 +08:00
|
|
|
|
|
|
|
attr = kmalloc(msb->page_size, GFP_KERNEL);
|
|
|
|
if (!attr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
sg_init_one(&msb->req_sg[0], attr, msb->page_size);
|
|
|
|
msb->seg_count = 1;
|
|
|
|
msb->current_seg = 0;
|
|
|
|
msb->current_page = 0;
|
|
|
|
msb->data_dir = READ;
|
|
|
|
msb->transfer_cmd = MSPRO_CMD_READ_ATRB;
|
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
msb->setup_transfer(card, attr_offset, attr_len);
|
|
|
|
|
2008-02-10 02:20:54 +08:00
|
|
|
memstick_new_req(card->host);
|
|
|
|
wait_for_completion(&card->mrq_complete);
|
|
|
|
if (card->current_mrq.error) {
|
|
|
|
rc = card->current_mrq.error;
|
|
|
|
goto out_free_attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (be16_to_cpu(attr->signature) != MSPRO_BLOCK_SIGNATURE) {
|
|
|
|
printk(KERN_ERR "%s: unrecognized device signature %x\n",
|
2009-01-07 02:44:38 +08:00
|
|
|
dev_name(&card->dev), be16_to_cpu(attr->signature));
|
2008-02-10 02:20:54 +08:00
|
|
|
rc = -ENODEV;
|
|
|
|
goto out_free_attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr->count > MSPRO_BLOCK_MAX_ATTRIBUTES) {
|
|
|
|
printk(KERN_WARNING "%s: way too many attribute entries\n",
|
2009-01-07 02:44:38 +08:00
|
|
|
dev_name(&card->dev));
|
2008-02-10 02:20:54 +08:00
|
|
|
attr_count = MSPRO_BLOCK_MAX_ATTRIBUTES;
|
|
|
|
} else
|
|
|
|
attr_count = attr->count;
|
|
|
|
|
2013-11-13 07:11:39 +08:00
|
|
|
msb->attr_group.attrs = kcalloc(attr_count + 1,
|
|
|
|
sizeof(*msb->attr_group.attrs),
|
2008-02-10 02:20:54 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!msb->attr_group.attrs) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out_free_attr;
|
|
|
|
}
|
|
|
|
msb->attr_group.name = "media_attributes";
|
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
buffer = kmalloc(attr_len, GFP_KERNEL);
|
2008-02-10 02:20:54 +08:00
|
|
|
if (!buffer) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out_free_attr;
|
|
|
|
}
|
2011-01-13 09:01:05 +08:00
|
|
|
memcpy(buffer, (char *)attr, attr_len);
|
2008-02-10 02:20:54 +08:00
|
|
|
|
|
|
|
for (cnt = 0; cnt < attr_count; ++cnt) {
|
|
|
|
s_attr = kzalloc(sizeof(struct mspro_sys_attr), GFP_KERNEL);
|
|
|
|
if (!s_attr) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out_free_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
msb->attr_group.attrs[cnt] = &s_attr->dev_attr.attr;
|
|
|
|
addr = be32_to_cpu(attr->entries[cnt].address);
|
2011-01-13 09:01:05 +08:00
|
|
|
s_attr->size = be32_to_cpu(attr->entries[cnt].size);
|
2008-02-10 02:20:54 +08:00
|
|
|
dev_dbg(&card->dev, "adding attribute %d: id %x, address %x, "
|
2011-01-13 09:01:05 +08:00
|
|
|
"size %zx\n", cnt, attr->entries[cnt].id, addr,
|
|
|
|
s_attr->size);
|
2008-02-10 02:20:54 +08:00
|
|
|
s_attr->id = attr->entries[cnt].id;
|
|
|
|
if (mspro_block_attr_name(s_attr->id))
|
|
|
|
snprintf(s_attr->name, sizeof(s_attr->name), "%s",
|
|
|
|
mspro_block_attr_name(attr->entries[cnt].id));
|
|
|
|
else
|
|
|
|
snprintf(s_attr->name, sizeof(s_attr->name),
|
|
|
|
"attr_x%02x", attr->entries[cnt].id);
|
|
|
|
|
2010-08-12 05:17:52 +08:00
|
|
|
sysfs_attr_init(&s_attr->dev_attr.attr);
|
2008-02-10 02:20:54 +08:00
|
|
|
s_attr->dev_attr.attr.name = s_attr->name;
|
|
|
|
s_attr->dev_attr.attr.mode = S_IRUGO;
|
|
|
|
s_attr->dev_attr.show = mspro_block_attr_show(s_attr->id);
|
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
if (!s_attr->size)
|
2008-02-10 02:20:54 +08:00
|
|
|
continue;
|
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
s_attr->data = kmalloc(s_attr->size, GFP_KERNEL);
|
2008-02-10 02:20:54 +08:00
|
|
|
if (!s_attr->data) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out_free_buffer;
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
if (((addr / msb->page_size) == (attr_offset / msb->page_size))
|
|
|
|
&& (((addr + s_attr->size - 1) / msb->page_size)
|
|
|
|
== (attr_offset / msb->page_size))) {
|
2008-02-10 02:20:54 +08:00
|
|
|
memcpy(s_attr->data, buffer + addr % msb->page_size,
|
2011-01-13 09:01:05 +08:00
|
|
|
s_attr->size);
|
2008-02-10 02:20:54 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
attr_offset = (addr / msb->page_size) * msb->page_size;
|
|
|
|
|
|
|
|
if ((attr_offset + attr_len) < (addr + s_attr->size)) {
|
2008-02-10 02:20:54 +08:00
|
|
|
kfree(buffer);
|
2011-01-13 09:01:05 +08:00
|
|
|
attr_len = (((addr + s_attr->size) / msb->page_size)
|
|
|
|
+ 1 ) * msb->page_size - attr_offset;
|
|
|
|
buffer = kmalloc(attr_len, GFP_KERNEL);
|
2008-02-10 02:20:54 +08:00
|
|
|
if (!buffer) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out_free_attr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
sg_init_one(&msb->req_sg[0], buffer, attr_len);
|
2008-02-10 02:20:54 +08:00
|
|
|
msb->seg_count = 1;
|
|
|
|
msb->current_seg = 0;
|
|
|
|
msb->current_page = 0;
|
|
|
|
msb->data_dir = READ;
|
|
|
|
msb->transfer_cmd = MSPRO_CMD_READ_ATRB;
|
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
dev_dbg(&card->dev, "reading attribute range %x, %x\n",
|
|
|
|
attr_offset, attr_len);
|
2008-02-10 02:20:54 +08:00
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
msb->setup_transfer(card, attr_offset, attr_len);
|
2008-02-10 02:20:54 +08:00
|
|
|
memstick_new_req(card->host);
|
|
|
|
wait_for_completion(&card->mrq_complete);
|
|
|
|
if (card->current_mrq.error) {
|
|
|
|
rc = card->current_mrq.error;
|
|
|
|
goto out_free_buffer;
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:01:05 +08:00
|
|
|
memcpy(s_attr->data, buffer + addr % msb->page_size,
|
|
|
|
s_attr->size);
|
2008-02-10 02:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
out_free_buffer:
|
|
|
|
kfree(buffer);
|
|
|
|
out_free_attr:
|
|
|
|
kfree(attr);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mspro_block_init_card(struct memstick_dev *card)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
struct memstick_host *host = card->host;
|
|
|
|
int rc = 0;
|
|
|
|
|
2008-03-11 02:43:37 +08:00
|
|
|
msb->system = MEMSTICK_SYS_SERIAL;
|
2011-01-13 09:01:05 +08:00
|
|
|
msb->setup_transfer = h_mspro_block_setup_cmd;
|
|
|
|
|
2008-02-10 02:20:54 +08:00
|
|
|
card->reg_addr.r_offset = offsetof(struct mspro_register, status);
|
|
|
|
card->reg_addr.r_length = sizeof(struct ms_status_register);
|
|
|
|
card->reg_addr.w_offset = offsetof(struct mspro_register, param);
|
|
|
|
card->reg_addr.w_length = sizeof(struct mspro_param_register);
|
|
|
|
|
|
|
|
if (memstick_set_rw_addr(card))
|
|
|
|
return -EIO;
|
|
|
|
|
2008-03-20 08:01:06 +08:00
|
|
|
msb->caps = host->caps;
|
2008-09-13 17:33:26 +08:00
|
|
|
|
|
|
|
msleep(150);
|
|
|
|
rc = mspro_block_wait_for_ced(card);
|
2008-03-20 08:01:07 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2008-02-10 02:20:54 +08:00
|
|
|
|
2008-09-13 17:33:26 +08:00
|
|
|
rc = mspro_block_switch_interface(card);
|
2008-02-10 02:20:54 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2008-09-13 17:33:26 +08:00
|
|
|
|
2008-02-10 02:20:54 +08:00
|
|
|
dev_dbg(&card->dev, "card activated\n");
|
2008-03-20 08:01:06 +08:00
|
|
|
if (msb->system != MEMSTICK_SYS_SERIAL)
|
|
|
|
msb->caps |= MEMSTICK_CAP_AUTO_GET_INT;
|
2008-02-10 02:20:54 +08:00
|
|
|
|
|
|
|
card->next_request = h_mspro_block_req_init;
|
|
|
|
msb->mrq_handler = h_mspro_block_get_ro;
|
|
|
|
memstick_init_req(&card->current_mrq, MS_TPC_READ_REG, NULL,
|
|
|
|
sizeof(struct ms_status_register));
|
|
|
|
memstick_new_req(card->host);
|
|
|
|
wait_for_completion(&card->mrq_complete);
|
|
|
|
if (card->current_mrq.error)
|
|
|
|
return card->current_mrq.error;
|
|
|
|
|
|
|
|
dev_dbg(&card->dev, "card r/w status %d\n", msb->read_only ? 0 : 1);
|
|
|
|
|
|
|
|
msb->page_size = 512;
|
|
|
|
rc = mspro_block_read_attributes(card);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
dev_dbg(&card->dev, "attributes loaded\n");
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mspro_block_init_disk(struct memstick_dev *card)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
struct memstick_host *host = card->host;
|
|
|
|
struct mspro_devinfo *dev_info = NULL;
|
|
|
|
struct mspro_sys_info *sys_info = NULL;
|
|
|
|
struct mspro_sys_attr *s_attr = NULL;
|
|
|
|
int rc, disk_id;
|
|
|
|
u64 limit = BLK_BOUNCE_HIGH;
|
|
|
|
unsigned long capacity;
|
|
|
|
|
2008-03-04 07:13:36 +08:00
|
|
|
if (host->dev.dma_mask && *(host->dev.dma_mask))
|
|
|
|
limit = *(host->dev.dma_mask);
|
2008-02-10 02:20:54 +08:00
|
|
|
|
|
|
|
for (rc = 0; msb->attr_group.attrs[rc]; ++rc) {
|
|
|
|
s_attr = mspro_from_sysfs_attr(msb->attr_group.attrs[rc]);
|
|
|
|
|
|
|
|
if (s_attr->id == MSPRO_BLOCK_ID_DEVINFO)
|
|
|
|
dev_info = s_attr->data;
|
|
|
|
else if (s_attr->id == MSPRO_BLOCK_ID_SYSINFO)
|
|
|
|
sys_info = s_attr->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dev_info || !sys_info)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
msb->page_size = be16_to_cpu(sys_info->unit_size);
|
|
|
|
|
2011-01-13 09:01:04 +08:00
|
|
|
mutex_lock(&mspro_block_disk_lock);
|
2013-02-28 09:04:28 +08:00
|
|
|
disk_id = idr_alloc(&mspro_block_disk_idr, card, 0, 256, GFP_KERNEL);
|
2008-02-10 02:20:54 +08:00
|
|
|
mutex_unlock(&mspro_block_disk_lock);
|
2013-02-28 09:04:28 +08:00
|
|
|
if (disk_id < 0)
|
|
|
|
return disk_id;
|
2008-02-10 02:20:54 +08:00
|
|
|
|
2008-09-13 17:33:26 +08:00
|
|
|
msb->disk = alloc_disk(1 << MSPRO_BLOCK_PART_SHIFT);
|
2008-02-10 02:20:54 +08:00
|
|
|
if (!msb->disk) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out_release_id;
|
|
|
|
}
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
msb->queue = blk_init_queue(mspro_block_submit_req, &msb->q_lock);
|
2008-02-10 02:20:54 +08:00
|
|
|
if (!msb->queue) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out_put_disk;
|
|
|
|
}
|
|
|
|
|
|
|
|
msb->queue->queuedata = card;
|
2008-07-26 10:45:02 +08:00
|
|
|
blk_queue_prep_rq(msb->queue, mspro_block_prepare_req);
|
2008-02-10 02:20:54 +08:00
|
|
|
|
|
|
|
blk_queue_bounce_limit(msb->queue, limit);
|
2010-02-26 13:20:38 +08:00
|
|
|
blk_queue_max_hw_sectors(msb->queue, MSPRO_BLOCK_MAX_PAGES);
|
2010-02-26 13:20:39 +08:00
|
|
|
blk_queue_max_segments(msb->queue, MSPRO_BLOCK_MAX_SEGS);
|
2008-02-10 02:20:54 +08:00
|
|
|
blk_queue_max_segment_size(msb->queue,
|
|
|
|
MSPRO_BLOCK_MAX_PAGES * msb->page_size);
|
|
|
|
|
|
|
|
msb->disk->major = major;
|
2008-09-13 17:33:26 +08:00
|
|
|
msb->disk->first_minor = disk_id << MSPRO_BLOCK_PART_SHIFT;
|
2008-02-10 02:20:54 +08:00
|
|
|
msb->disk->fops = &ms_block_bdops;
|
|
|
|
msb->usage_count = 1;
|
|
|
|
msb->disk->private_data = msb;
|
|
|
|
msb->disk->queue = msb->queue;
|
|
|
|
msb->disk->driverfs_dev = &card->dev;
|
|
|
|
|
|
|
|
sprintf(msb->disk->disk_name, "mspblk%d", disk_id);
|
|
|
|
|
2009-05-23 05:17:49 +08:00
|
|
|
blk_queue_logical_block_size(msb->queue, msb->page_size);
|
2008-02-10 02:20:54 +08:00
|
|
|
|
|
|
|
capacity = be16_to_cpu(sys_info->user_block_count);
|
|
|
|
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);
|
|
|
|
|
|
|
|
add_disk(msb->disk);
|
|
|
|
msb->active = 1;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_put_disk:
|
|
|
|
put_disk(msb->disk);
|
|
|
|
out_release_id:
|
|
|
|
mutex_lock(&mspro_block_disk_lock);
|
|
|
|
idr_remove(&mspro_block_disk_idr, disk_id);
|
|
|
|
mutex_unlock(&mspro_block_disk_lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mspro_block_data_clear(struct mspro_block_data *msb)
|
|
|
|
{
|
|
|
|
int cnt;
|
|
|
|
struct mspro_sys_attr *s_attr;
|
|
|
|
|
|
|
|
if (msb->attr_group.attrs) {
|
|
|
|
for (cnt = 0; msb->attr_group.attrs[cnt]; ++cnt) {
|
|
|
|
s_attr = mspro_from_sysfs_attr(msb->attr_group
|
|
|
|
.attrs[cnt]);
|
|
|
|
kfree(s_attr->data);
|
|
|
|
kfree(s_attr);
|
|
|
|
}
|
|
|
|
kfree(msb->attr_group.attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
msb->card = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mspro_block_check_card(struct memstick_dev *card)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
|
|
|
|
return (msb->active == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mspro_block_probe(struct memstick_dev *card)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
msb = kzalloc(sizeof(struct mspro_block_data), GFP_KERNEL);
|
|
|
|
if (!msb)
|
|
|
|
return -ENOMEM;
|
|
|
|
memstick_set_drvdata(card, msb);
|
|
|
|
msb->card = card;
|
2008-07-26 10:45:02 +08:00
|
|
|
spin_lock_init(&msb->q_lock);
|
2008-02-10 02:20:54 +08:00
|
|
|
|
|
|
|
rc = mspro_block_init_card(card);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
rc = sysfs_create_group(&card->dev.kobj, &msb->attr_group);
|
|
|
|
if (rc)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
rc = mspro_block_init_disk(card);
|
|
|
|
if (!rc) {
|
|
|
|
card->check = mspro_block_check_card;
|
2008-07-26 10:45:01 +08:00
|
|
|
card->stop = mspro_block_stop;
|
|
|
|
card->start = mspro_block_start;
|
2008-02-10 02:20:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sysfs_remove_group(&card->dev.kobj, &msb->attr_group);
|
|
|
|
out_free:
|
|
|
|
memstick_set_drvdata(card, NULL);
|
|
|
|
mspro_block_data_clear(msb);
|
|
|
|
kfree(msb);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mspro_block_remove(struct memstick_dev *card)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&msb->q_lock, flags);
|
2008-07-26 10:45:02 +08:00
|
|
|
msb->eject = 1;
|
|
|
|
blk_start_queue(msb->queue);
|
2008-02-10 02:20:54 +08:00
|
|
|
spin_unlock_irqrestore(&msb->q_lock, flags);
|
|
|
|
|
2010-08-12 05:17:52 +08:00
|
|
|
del_gendisk(msb->disk);
|
|
|
|
dev_dbg(&card->dev, "mspro block remove\n");
|
|
|
|
|
2008-02-10 02:20:54 +08:00
|
|
|
blk_cleanup_queue(msb->queue);
|
2008-07-26 10:45:02 +08:00
|
|
|
msb->queue = NULL;
|
2008-02-10 02:20:54 +08:00
|
|
|
|
|
|
|
sysfs_remove_group(&card->dev.kobj, &msb->attr_group);
|
|
|
|
|
|
|
|
mutex_lock(&mspro_block_disk_lock);
|
|
|
|
mspro_block_data_clear(msb);
|
|
|
|
mutex_unlock(&mspro_block_disk_lock);
|
|
|
|
|
|
|
|
mspro_block_disk_release(msb->disk);
|
|
|
|
memstick_set_drvdata(card, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
|
|
|
static int mspro_block_suspend(struct memstick_dev *card, pm_message_t state)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&msb->q_lock, flags);
|
|
|
|
blk_stop_queue(msb->queue);
|
2008-07-26 10:45:02 +08:00
|
|
|
msb->active = 0;
|
2008-02-10 02:20:54 +08:00
|
|
|
spin_unlock_irqrestore(&msb->q_lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mspro_block_resume(struct memstick_dev *card)
|
|
|
|
{
|
|
|
|
struct mspro_block_data *msb = memstick_get_drvdata(card);
|
|
|
|
unsigned long flags;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
#ifdef CONFIG_MEMSTICK_UNSAFE_RESUME
|
|
|
|
|
|
|
|
struct mspro_block_data *new_msb;
|
|
|
|
struct memstick_host *host = card->host;
|
|
|
|
struct mspro_sys_attr *s_attr, *r_attr;
|
|
|
|
unsigned char cnt;
|
|
|
|
|
|
|
|
mutex_lock(&host->lock);
|
|
|
|
new_msb = kzalloc(sizeof(struct mspro_block_data), GFP_KERNEL);
|
|
|
|
if (!new_msb) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_msb->card = card;
|
|
|
|
memstick_set_drvdata(card, new_msb);
|
|
|
|
if (mspro_block_init_card(card))
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
for (cnt = 0; new_msb->attr_group.attrs[cnt]
|
|
|
|
&& msb->attr_group.attrs[cnt]; ++cnt) {
|
|
|
|
s_attr = mspro_from_sysfs_attr(new_msb->attr_group.attrs[cnt]);
|
|
|
|
r_attr = mspro_from_sysfs_attr(msb->attr_group.attrs[cnt]);
|
|
|
|
|
|
|
|
if (s_attr->id == MSPRO_BLOCK_ID_SYSINFO
|
|
|
|
&& r_attr->id == s_attr->id) {
|
|
|
|
if (memcmp(s_attr->data, r_attr->data, s_attr->size))
|
|
|
|
break;
|
|
|
|
|
2008-07-26 10:45:02 +08:00
|
|
|
msb->active = 1;
|
2008-02-10 02:20:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
memstick_set_drvdata(card, msb);
|
|
|
|
mspro_block_data_clear(new_msb);
|
|
|
|
kfree(new_msb);
|
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&host->lock);
|
|
|
|
|
|
|
|
#endif /* CONFIG_MEMSTICK_UNSAFE_RESUME */
|
|
|
|
|
|
|
|
spin_lock_irqsave(&msb->q_lock, flags);
|
|
|
|
blk_start_queue(msb->queue);
|
|
|
|
spin_unlock_irqrestore(&msb->q_lock, flags);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define mspro_block_suspend NULL
|
|
|
|
#define mspro_block_resume NULL
|
|
|
|
|
|
|
|
#endif /* CONFIG_PM */
|
|
|
|
|
|
|
|
static struct memstick_device_id mspro_block_id_tbl[] = {
|
|
|
|
{MEMSTICK_MATCH_ALL, MEMSTICK_TYPE_PRO, MEMSTICK_CATEGORY_STORAGE_DUO,
|
2008-09-13 17:33:26 +08:00
|
|
|
MEMSTICK_CLASS_DUO},
|
2008-02-10 02:20:54 +08:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static struct memstick_driver mspro_block_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.owner = THIS_MODULE
|
|
|
|
},
|
|
|
|
.id_table = mspro_block_id_tbl,
|
|
|
|
.probe = mspro_block_probe,
|
|
|
|
.remove = mspro_block_remove,
|
|
|
|
.suspend = mspro_block_suspend,
|
|
|
|
.resume = mspro_block_resume
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init mspro_block_init(void)
|
|
|
|
{
|
|
|
|
int rc = -ENOMEM;
|
|
|
|
|
|
|
|
rc = register_blkdev(major, DRIVER_NAME);
|
|
|
|
if (rc < 0) {
|
|
|
|
printk(KERN_ERR DRIVER_NAME ": failed to register "
|
|
|
|
"major %d, error %d\n", major, rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
if (!major)
|
|
|
|
major = rc;
|
|
|
|
|
|
|
|
rc = memstick_register_driver(&mspro_block_driver);
|
|
|
|
if (rc)
|
|
|
|
unregister_blkdev(major, DRIVER_NAME);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit mspro_block_exit(void)
|
|
|
|
{
|
|
|
|
memstick_unregister_driver(&mspro_block_driver);
|
|
|
|
unregister_blkdev(major, DRIVER_NAME);
|
|
|
|
idr_destroy(&mspro_block_disk_idr);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mspro_block_init);
|
|
|
|
module_exit(mspro_block_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Alex Dubov");
|
|
|
|
MODULE_DESCRIPTION("Sony MemoryStickPro block device driver");
|
|
|
|
MODULE_DEVICE_TABLE(memstick, mspro_block_id_tbl);
|