2 * Sony MemoryStick Pro storage support
4 * Copyright (C) 2007 Alex Dubov <oakad@yahoo.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Special thanks to Carlos Corbacho for providing various MemoryStick cards
11 * that made this driver possible.
15 #include <linux/blkdev.h>
16 #include <linux/idr.h>
17 #include <linux/hdreg.h>
18 #include <linux/kthread.h>
19 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
21 #include <linux/delay.h>
22 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
23 #include <linux/memstick.h>
25 #define DRIVER_NAME "mspro_block"
26 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
27 #define DRIVER_VERSION "0.2"
29 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
32 module_param(major
, int, 0644);
34 #define MSPRO_BLOCK_MAX_SEGS 32
35 #define MSPRO_BLOCK_MAX_PAGES ((2 << 16) - 1)
37 #define MSPRO_BLOCK_SIGNATURE 0xa5c3
38 #define MSPRO_BLOCK_MAX_ATTRIBUTES 41
41 MSPRO_BLOCK_ID_SYSINFO
= 0x10,
42 MSPRO_BLOCK_ID_MODELNAME
= 0x15,
43 MSPRO_BLOCK_ID_MBR
= 0x20,
44 MSPRO_BLOCK_ID_PBR16
= 0x21,
45 MSPRO_BLOCK_ID_PBR32
= 0x22,
46 MSPRO_BLOCK_ID_SPECFILEVALUES1
= 0x25,
47 MSPRO_BLOCK_ID_SPECFILEVALUES2
= 0x26,
48 MSPRO_BLOCK_ID_DEVINFO
= 0x30
51 struct mspro_sys_attr
{
56 struct device_attribute dev_attr
;
59 struct mspro_attr_entry
{
63 unsigned char reserved
[3];
64 } __attribute__((packed
));
66 struct mspro_attribute
{
67 unsigned short signature
;
68 unsigned short version
;
70 unsigned char reserved
[11];
71 struct mspro_attr_entry entries
[];
72 } __attribute__((packed
));
74 struct mspro_sys_info
{
76 unsigned char reserved0
;
77 unsigned short block_size
;
78 unsigned short block_count
;
79 unsigned short user_block_count
;
80 unsigned short page_size
;
81 unsigned char reserved1
[2];
82 unsigned char assembly_date
[8];
83 unsigned int serial_number
;
84 unsigned char assembly_maker_code
;
85 unsigned char assembly_model_code
[3];
86 unsigned short memory_maker_code
;
87 unsigned short memory_model_code
;
88 unsigned char reserved2
[4];
91 unsigned short controller_number
;
92 unsigned short controller_function
;
93 unsigned short start_sector
;
94 unsigned short unit_size
;
95 unsigned char ms_sub_class
;
96 unsigned char reserved3
[4];
97 unsigned char interface_type
;
98 unsigned short controller_code
;
99 unsigned char format_type
;
100 unsigned char reserved4
;
101 unsigned char device_type
;
102 unsigned char reserved5
[7];
103 unsigned char mspro_id
[16];
104 unsigned char reserved6
[16];
105 } __attribute__((packed
));
108 unsigned char boot_partition
;
109 unsigned char start_head
;
110 unsigned char start_sector
;
111 unsigned char start_cylinder
;
112 unsigned char partition_type
;
113 unsigned char end_head
;
114 unsigned char end_sector
;
115 unsigned char end_cylinder
;
116 unsigned int start_sectors
;
117 unsigned int sectors_per_partition
;
118 } __attribute__((packed
));
120 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
122 struct mspro_specfile
{
126 unsigned char reserved
[10];
129 unsigned short cluster
;
131 } __attribute__((packed
));
133 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
134 struct mspro_devinfo
{
135 unsigned short cylinders
;
136 unsigned short heads
;
137 unsigned short bytes_per_track
;
138 unsigned short bytes_per_sector
;
139 unsigned short sectors_per_track
;
140 unsigned char reserved
[6];
141 } __attribute__((packed
));
143 struct mspro_block_data
{
144 struct memstick_dev
*card
;
145 unsigned int usage_count
;
146 struct gendisk
*disk
;
147 struct request_queue
*queue
;
149 wait_queue_head_t q_wait
;
150 struct task_struct
*q_thread
;
152 unsigned short page_size
;
153 unsigned short cylinders
;
154 unsigned short heads
;
155 unsigned short sectors_per_track
;
157 unsigned char system
;
158 unsigned char read_only
:1,
162 unsigned char transfer_cmd
;
164 int (*mrq_handler
)(struct memstick_dev
*card
,
165 struct memstick_request
**mrq
);
167 struct attribute_group attr_group
;
169 struct scatterlist req_sg
[MSPRO_BLOCK_MAX_SEGS
];
170 unsigned int seg_count
;
171 unsigned int current_seg
;
172 unsigned short current_page
;
175 static DEFINE_IDR(mspro_block_disk_idr
);
176 static DEFINE_MUTEX(mspro_block_disk_lock
);
178 /*** Block device ***/
180 static int mspro_block_bd_open(struct inode
*inode
, struct file
*filp
)
182 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
183 struct mspro_block_data
*msb
= disk
->private_data
;
186 mutex_lock(&mspro_block_disk_lock
);
188 if (msb
&& msb
->card
) {
190 if ((filp
->f_mode
& FMODE_WRITE
) && msb
->read_only
)
196 mutex_unlock(&mspro_block_disk_lock
);
202 static int mspro_block_disk_release(struct gendisk
*disk
)
204 struct mspro_block_data
*msb
= disk
->private_data
;
205 int disk_id
= disk
->first_minor
>> MEMSTICK_PART_SHIFT
;
207 mutex_lock(&mspro_block_disk_lock
);
209 if (msb
->usage_count
) {
211 if (!msb
->usage_count
) {
213 disk
->private_data
= NULL
;
214 idr_remove(&mspro_block_disk_idr
, disk_id
);
219 mutex_unlock(&mspro_block_disk_lock
);
224 static int mspro_block_bd_release(struct inode
*inode
, struct file
*filp
)
226 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
227 return mspro_block_disk_release(disk
);
230 static int mspro_block_bd_getgeo(struct block_device
*bdev
,
231 struct hd_geometry
*geo
)
233 struct mspro_block_data
*msb
= bdev
->bd_disk
->private_data
;
235 geo
->heads
= msb
->heads
;
236 geo
->sectors
= msb
->sectors_per_track
;
237 geo
->cylinders
= msb
->cylinders
;
242 static struct block_device_operations ms_block_bdops
= {
243 .open
= mspro_block_bd_open
,
244 .release
= mspro_block_bd_release
,
245 .getgeo
= mspro_block_bd_getgeo
,
249 /*** Information ***/
251 static struct mspro_sys_attr
*mspro_from_sysfs_attr(struct attribute
*attr
)
253 struct device_attribute
*dev_attr
254 = container_of(attr
, struct device_attribute
, attr
);
255 return container_of(dev_attr
, struct mspro_sys_attr
, dev_attr
);
258 static const char *mspro_block_attr_name(unsigned char tag
)
261 case MSPRO_BLOCK_ID_SYSINFO
:
262 return "attr_sysinfo";
263 case MSPRO_BLOCK_ID_MODELNAME
:
264 return "attr_modelname";
265 case MSPRO_BLOCK_ID_MBR
:
267 case MSPRO_BLOCK_ID_PBR16
:
269 case MSPRO_BLOCK_ID_PBR32
:
271 case MSPRO_BLOCK_ID_SPECFILEVALUES1
:
272 return "attr_specfilevalues1";
273 case MSPRO_BLOCK_ID_SPECFILEVALUES2
:
274 return "attr_specfilevalues2";
275 case MSPRO_BLOCK_ID_DEVINFO
:
276 return "attr_devinfo";
282 typedef ssize_t (*sysfs_show_t
)(struct device
*dev
,
283 struct device_attribute
*attr
,
286 static ssize_t
mspro_block_attr_show_default(struct device
*dev
,
287 struct device_attribute
*attr
,
290 struct mspro_sys_attr
*s_attr
= container_of(attr
,
291 struct mspro_sys_attr
,
296 for (cnt
= 0; cnt
< s_attr
->size
; cnt
++) {
297 if (cnt
&& !(cnt
% 16)) {
302 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "%02x ",
303 ((unsigned char *)s_attr
->data
)[cnt
]);
308 static ssize_t
mspro_block_attr_show_sysinfo(struct device
*dev
,
309 struct device_attribute
*attr
,
312 struct mspro_sys_attr
*x_attr
= container_of(attr
,
313 struct mspro_sys_attr
,
315 struct mspro_sys_info
*x_sys
= x_attr
->data
;
317 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
319 int date_tz
= 0, date_tz_f
= 0;
321 if (x_sys
->assembly_date
[0] > 0x80U
) {
322 date_tz
= (~x_sys
->assembly_date
[0]) + 1;
323 date_tz_f
= date_tz
& 3;
327 } else if (x_sys
->assembly_date
[0] < 0x80U
) {
328 date_tz
= x_sys
->assembly_date
[0];
329 date_tz_f
= date_tz
& 3;
333 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
335 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "class: %x\n",
337 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "block size: %x\n",
338 be16_to_cpu(x_sys
->block_size
));
339 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "block count: %x\n",
340 be16_to_cpu(x_sys
->block_count
));
341 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "user block count: %x\n",
342 be16_to_cpu(x_sys
->user_block_count
));
343 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "page size: %x\n",
344 be16_to_cpu(x_sys
->page_size
));
345 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "assembly date: "
346 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
347 "%d %04u-%02u-%02u %02u:%02u:%02u\n",
348 x_sys
->assembly_date
[0],
350 "GMT%+d:%d %04u-%02u-%02u %02u:%02u:%02u\n",
352 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
353 be16_to_cpu(*(unsigned short *)
354 &x_sys
->assembly_date
[1]),
355 x_sys
->assembly_date
[3], x_sys
->assembly_date
[4],
356 x_sys
->assembly_date
[5], x_sys
->assembly_date
[6],
357 x_sys
->assembly_date
[7]);
358 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "serial number: %x\n",
359 be32_to_cpu(x_sys
->serial_number
));
360 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
,
361 "assembly maker code: %x\n",
362 x_sys
->assembly_maker_code
);
363 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "assembly model code: "
364 "%02x%02x%02x\n", x_sys
->assembly_model_code
[0],
365 x_sys
->assembly_model_code
[1],
366 x_sys
->assembly_model_code
[2]);
367 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "memory maker code: %x\n",
368 be16_to_cpu(x_sys
->memory_maker_code
));
369 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "memory model code: %x\n",
370 be16_to_cpu(x_sys
->memory_model_code
));
371 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "vcc: %x\n",
373 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "vpp: %x\n",
375 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "controller number: %x\n",
376 be16_to_cpu(x_sys
->controller_number
));
377 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
,
378 "controller function: %x\n",
379 be16_to_cpu(x_sys
->controller_function
));
380 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start sector: %x\n",
381 be16_to_cpu(x_sys
->start_sector
));
382 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "unit size: %x\n",
383 be16_to_cpu(x_sys
->unit_size
));
384 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "sub class: %x\n",
385 x_sys
->ms_sub_class
);
386 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "interface type: %x\n",
387 x_sys
->interface_type
);
388 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "controller code: %x\n",
389 be16_to_cpu(x_sys
->controller_code
));
390 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "format type: %x\n",
392 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "device type: %x\n",
394 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "mspro id: %s\n",
399 static ssize_t
mspro_block_attr_show_modelname(struct device
*dev
,
400 struct device_attribute
*attr
,
403 struct mspro_sys_attr
*s_attr
= container_of(attr
,
404 struct mspro_sys_attr
,
407 return scnprintf(buffer
, PAGE_SIZE
, "%s", (char *)s_attr
->data
);
410 static ssize_t
mspro_block_attr_show_mbr(struct device
*dev
,
411 struct device_attribute
*attr
,
414 struct mspro_sys_attr
*x_attr
= container_of(attr
,
415 struct mspro_sys_attr
,
417 struct mspro_mbr
*x_mbr
= x_attr
->data
;
420 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "boot partition: %x\n",
421 x_mbr
->boot_partition
);
422 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start head: %x\n",
424 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start sector: %x\n",
425 x_mbr
->start_sector
);
426 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start cylinder: %x\n",
427 x_mbr
->start_cylinder
);
428 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "partition type: %x\n",
429 x_mbr
->partition_type
);
430 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "end head: %x\n",
432 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "end sector: %x\n",
434 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "end cylinder: %x\n",
435 x_mbr
->end_cylinder
);
436 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start sectors: %x\n",
437 x_mbr
->start_sectors
);
438 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
,
439 "sectors per partition: %x\n",
440 x_mbr
->sectors_per_partition
);
444 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
446 static ssize_t
mspro_block_attr_show_specfile(struct device
*dev
,
447 struct device_attribute
*attr
,
450 struct mspro_sys_attr
*x_attr
= container_of(attr
,
451 struct mspro_sys_attr
,
453 struct mspro_specfile
*x_spfile
= x_attr
->data
;
454 char name
[9], ext
[4];
457 memcpy(name
, x_spfile
->name
, 8);
459 memcpy(ext
, x_spfile
->ext
, 3);
462 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "name: %s\n", name
);
463 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "ext: %s\n", ext
);
464 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "attribute: %x\n",
466 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "time: %d:%d:%d\n",
467 x_spfile
->time
>> 11,
468 (x_spfile
->time
>> 5) & 0x3f,
469 (x_spfile
->time
& 0x1f) * 2);
470 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "date: %d-%d-%d\n",
471 (x_spfile
->date
>> 9) + 1980,
472 (x_spfile
->date
>> 5) & 0xf,
473 x_spfile
->date
& 0x1f);
474 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start cluster: %x\n",
476 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "size: %x\n",
481 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
482 static ssize_t
mspro_block_attr_show_devinfo(struct device
*dev
,
483 struct device_attribute
*attr
,
486 struct mspro_sys_attr
*x_attr
= container_of(attr
,
487 struct mspro_sys_attr
,
489 struct mspro_devinfo
*x_devinfo
= x_attr
->data
;
492 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "cylinders: %x\n",
493 be16_to_cpu(x_devinfo
->cylinders
));
494 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "heads: %x\n",
495 be16_to_cpu(x_devinfo
->heads
));
496 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "bytes per track: %x\n",
497 be16_to_cpu(x_devinfo
->bytes_per_track
));
498 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "bytes per sector: %x\n",
499 be16_to_cpu(x_devinfo
->bytes_per_sector
));
500 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "sectors per track: %x\n",
501 be16_to_cpu(x_devinfo
->sectors_per_track
));
505 static sysfs_show_t
mspro_block_attr_show(unsigned char tag
)
508 case MSPRO_BLOCK_ID_SYSINFO
:
509 return mspro_block_attr_show_sysinfo
;
510 case MSPRO_BLOCK_ID_MODELNAME
:
511 return mspro_block_attr_show_modelname
;
512 case MSPRO_BLOCK_ID_MBR
:
513 return mspro_block_attr_show_mbr
;
514 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
516 case MSPRO_BLOCK_ID_SPECFILEVALUES1
:
517 case MSPRO_BLOCK_ID_SPECFILEVALUES2
:
518 return mspro_block_attr_show_specfile
;
519 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
520 case MSPRO_BLOCK_ID_DEVINFO
:
521 return mspro_block_attr_show_devinfo
;
523 return mspro_block_attr_show_default
;
527 /*** Protocol handlers ***/
530 * Functions prefixed with "h_" are protocol callbacks. They can be called from
531 * interrupt context. Return value of 0 means that request processing is still
532 * ongoing, while special error value of -EAGAIN means that current request is
533 * finished (and request processor should come back some time later).
536 static int h_mspro_block_req_init(struct memstick_dev
*card
,
537 struct memstick_request
**mrq
)
539 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
541 *mrq
= &card
->current_mrq
;
542 card
->next_request
= msb
->mrq_handler
;
546 static int h_mspro_block_default(struct memstick_dev
*card
,
547 struct memstick_request
**mrq
)
549 complete(&card
->mrq_complete
);
553 return (*mrq
)->error
;
556 static int h_mspro_block_get_ro(struct memstick_dev
*card
,
557 struct memstick_request
**mrq
)
559 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
562 complete(&card
->mrq_complete
);
563 return (*mrq
)->error
;
566 if ((*mrq
)->data
[offsetof(struct ms_status_register
, status0
)]
567 & MEMSTICK_STATUS0_WP
)
572 complete(&card
->mrq_complete
);
576 static int h_mspro_block_wait_for_ced(struct memstick_dev
*card
,
577 struct memstick_request
**mrq
)
580 complete(&card
->mrq_complete
);
581 return (*mrq
)->error
;
584 dev_dbg(&card
->dev
, "wait for ced: value %x\n", (*mrq
)->data
[0]);
586 if ((*mrq
)->data
[0] & (MEMSTICK_INT_CMDNAK
| MEMSTICK_INT_ERR
)) {
587 card
->current_mrq
.error
= -EFAULT
;
588 complete(&card
->mrq_complete
);
589 return card
->current_mrq
.error
;
592 if (!((*mrq
)->data
[0] & MEMSTICK_INT_CED
))
595 card
->current_mrq
.error
= 0;
596 complete(&card
->mrq_complete
);
601 static int h_mspro_block_transfer_data(struct memstick_dev
*card
,
602 struct memstick_request
**mrq
)
604 struct memstick_host
*host
= card
->host
;
605 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
606 unsigned char t_val
= 0;
607 struct scatterlist t_sg
= { 0 };
611 complete(&card
->mrq_complete
);
612 return (*mrq
)->error
;
615 switch ((*mrq
)->tpc
) {
616 case MS_TPC_WRITE_REG
:
617 memstick_init_req(*mrq
, MS_TPC_SET_CMD
, &msb
->transfer_cmd
, 1);
618 (*mrq
)->get_int_reg
= 1;
621 t_val
= (*mrq
)->int_reg
;
622 memstick_init_req(*mrq
, MS_TPC_GET_INT
, NULL
, 1);
623 if (host
->caps
& MEMSTICK_CAP_AUTO_GET_INT
)
627 t_val
= (*mrq
)->data
[0];
629 if (t_val
& (MEMSTICK_INT_CMDNAK
| MEMSTICK_INT_ERR
)) {
630 t_val
= MSPRO_CMD_STOP
;
631 memstick_init_req(*mrq
, MS_TPC_SET_CMD
, &t_val
, 1);
632 card
->next_request
= h_mspro_block_default
;
636 if (msb
->current_page
637 == (msb
->req_sg
[msb
->current_seg
].length
639 msb
->current_page
= 0;
642 if (msb
->current_seg
== msb
->seg_count
) {
643 if (t_val
& MEMSTICK_INT_CED
) {
644 complete(&card
->mrq_complete
);
648 = h_mspro_block_wait_for_ced
;
649 memstick_init_req(*mrq
, MS_TPC_GET_INT
,
656 if (!(t_val
& MEMSTICK_INT_BREQ
)) {
657 memstick_init_req(*mrq
, MS_TPC_GET_INT
, NULL
, 1);
661 t_offset
= msb
->req_sg
[msb
->current_seg
].offset
;
662 t_offset
+= msb
->current_page
* msb
->page_size
;
665 nth_page(sg_page(&(msb
->req_sg
[msb
->current_seg
])),
666 t_offset
>> PAGE_SHIFT
),
667 msb
->page_size
, offset_in_page(t_offset
));
669 memstick_init_req_sg(*mrq
, msb
->data_dir
== READ
670 ? MS_TPC_READ_LONG_DATA
671 : MS_TPC_WRITE_LONG_DATA
,
673 (*mrq
)->get_int_reg
= 1;
675 case MS_TPC_READ_LONG_DATA
:
676 case MS_TPC_WRITE_LONG_DATA
:
678 if (host
->caps
& MEMSTICK_CAP_AUTO_GET_INT
) {
679 t_val
= (*mrq
)->int_reg
;
682 memstick_init_req(*mrq
, MS_TPC_GET_INT
, NULL
, 1);
691 /*** Data transfer ***/
693 static void mspro_block_process_request(struct memstick_dev
*card
,
696 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
697 struct mspro_param_register param
;
699 unsigned short page_count
;
705 msb
->current_seg
= 0;
706 msb
->seg_count
= blk_rq_map_sg(req
->q
, req
, msb
->req_sg
);
708 if (msb
->seg_count
) {
709 msb
->current_page
= 0;
710 for (rc
= 0; rc
< msb
->seg_count
; rc
++)
711 page_count
+= msb
->req_sg
[rc
].length
715 sector_div(t_sec
, msb
->page_size
>> 9);
716 param
.system
= msb
->system
;
717 param
.data_count
= cpu_to_be16(page_count
);
718 param
.data_address
= cpu_to_be32((uint32_t)t_sec
);
719 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
723 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
725 msb
->data_dir
= rq_data_dir(req
);
726 msb
->transfer_cmd
= msb
->data_dir
== READ
727 ? MSPRO_CMD_READ_DATA
728 : MSPRO_CMD_WRITE_DATA
;
730 dev_dbg(&card
->dev
, "data transfer: cmd %x, "
731 "lba %x, count %x\n", msb
->transfer_cmd
,
732 be32_to_cpu(param
.data_address
),
735 card
->next_request
= h_mspro_block_req_init
;
736 msb
->mrq_handler
= h_mspro_block_transfer_data
;
737 memstick_init_req(&card
->current_mrq
, MS_TPC_WRITE_REG
,
738 ¶m
, sizeof(param
));
739 memstick_new_req(card
->host
);
740 wait_for_completion(&card
->mrq_complete
);
741 rc
= card
->current_mrq
.error
;
743 if (rc
|| (card
->current_mrq
.tpc
== MSPRO_CMD_STOP
)) {
744 for (cnt
= 0; cnt
< msb
->current_seg
; cnt
++)
745 page_count
+= msb
->req_sg
[cnt
].length
748 if (msb
->current_page
)
749 page_count
+= msb
->current_page
- 1;
751 if (page_count
&& (msb
->data_dir
== READ
))
752 rc
= msb
->page_size
* page_count
;
756 rc
= msb
->page_size
* page_count
;
760 spin_lock_irqsave(&msb
->q_lock
, flags
);
762 chunk
= __blk_end_request(req
, 0, rc
);
764 chunk
= __blk_end_request(req
, rc
, 0);
766 dev_dbg(&card
->dev
, "end chunk %d, %d\n", rc
, chunk
);
767 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
771 static int mspro_block_has_request(struct mspro_block_data
*msb
)
776 spin_lock_irqsave(&msb
->q_lock
, flags
);
777 if (kthread_should_stop() || msb
->has_request
)
779 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
783 static int mspro_block_queue_thread(void *data
)
785 struct memstick_dev
*card
= data
;
786 struct memstick_host
*host
= card
->host
;
787 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
792 wait_event(msb
->q_wait
, mspro_block_has_request(msb
));
793 dev_dbg(&card
->dev
, "thread iter\n");
795 spin_lock_irqsave(&msb
->q_lock
, flags
);
796 req
= elv_next_request(msb
->queue
);
797 dev_dbg(&card
->dev
, "next req %p\n", req
);
799 msb
->has_request
= 0;
800 if (kthread_should_stop()) {
801 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
805 msb
->has_request
= 1;
806 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
809 mutex_lock(&host
->lock
);
810 mspro_block_process_request(card
, req
);
811 mutex_unlock(&host
->lock
);
814 dev_dbg(&card
->dev
, "thread finished\n");
818 static void mspro_block_request(struct request_queue
*q
)
820 struct memstick_dev
*card
= q
->queuedata
;
821 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
822 struct request
*req
= NULL
;
825 msb
->has_request
= 1;
826 wake_up_all(&msb
->q_wait
);
828 while ((req
= elv_next_request(q
)) != NULL
)
829 end_queued_request(req
, -ENODEV
);
833 /*** Initialization ***/
835 static int mspro_block_wait_for_ced(struct memstick_dev
*card
)
837 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
839 card
->next_request
= h_mspro_block_req_init
;
840 msb
->mrq_handler
= h_mspro_block_wait_for_ced
;
841 memstick_init_req(&card
->current_mrq
, MS_TPC_GET_INT
, NULL
, 1);
842 memstick_new_req(card
->host
);
843 wait_for_completion(&card
->mrq_complete
);
844 return card
->current_mrq
.error
;
847 static int mspro_block_switch_to_parallel(struct memstick_dev
*card
)
849 struct memstick_host
*host
= card
->host
;
850 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
851 struct mspro_param_register param
= {
852 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
855 .system
= MEMSTICK_SYS_PAR4
,
856 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
859 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
863 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
866 card
->next_request
= h_mspro_block_req_init
;
867 msb
->mrq_handler
= h_mspro_block_default
;
868 memstick_init_req(&card
->current_mrq
, MS_TPC_WRITE_REG
, ¶m
,
870 memstick_new_req(host
);
871 wait_for_completion(&card
->mrq_complete
);
872 if (card
->current_mrq
.error
)
873 return card
->current_mrq
.error
;
875 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
877 host
->set_param(host
, MEMSTICK_INTERFACE
, MEMSTICK_PARALLEL
);
879 msb
->system
= MEMSTICK_SYS_PAR4
;
880 host
->set_param(host
, MEMSTICK_INTERFACE
, MEMSTICK_PAR4
);
881 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
883 card
->next_request
= h_mspro_block_req_init
;
884 msb
->mrq_handler
= h_mspro_block_default
;
885 memstick_init_req(&card
->current_mrq
, MS_TPC_GET_INT
, NULL
, 1);
886 memstick_new_req(card
->host
);
887 wait_for_completion(&card
->mrq_complete
);
889 if (card
->current_mrq
.error
) {
890 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
893 msb
->system
= MEMSTICK_SYS_SERIAL
;
894 host
->set_param(host
, MEMSTICK_POWER
, MEMSTICK_POWER_OFF
);
896 host
->set_param(host
, MEMSTICK_POWER
, MEMSTICK_POWER_ON
);
897 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
898 host
->set_param(host
, MEMSTICK_INTERFACE
, MEMSTICK_SERIAL
);
899 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
902 if (memstick_set_rw_addr(card
))
903 return card
->current_mrq
.error
;
905 param
.system
= msb
->system
;
907 card
->next_request
= h_mspro_block_req_init
;
908 msb
->mrq_handler
= h_mspro_block_default
;
909 memstick_init_req(&card
->current_mrq
, MS_TPC_WRITE_REG
, ¶m
,
911 memstick_new_req(host
);
912 wait_for_completion(&card
->mrq_complete
);
914 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
921 /* Memory allocated for attributes by this function should be freed by
922 * mspro_block_data_clear, no matter if the initialization process succeded
925 static int mspro_block_read_attributes(struct memstick_dev
*card
)
927 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
928 struct mspro_param_register param
= {
929 .system
= msb
->system
,
930 .data_count
= cpu_to_be16(1),
932 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
936 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
938 struct mspro_attribute
*attr
= NULL
;
939 struct mspro_sys_attr
*s_attr
= NULL
;
940 unsigned char *buffer
= NULL
;
941 int cnt
, rc
, attr_count
;
943 unsigned short page_count
;
945 attr
= kmalloc(msb
->page_size
, GFP_KERNEL
);
949 sg_init_one(&msb
->req_sg
[0], attr
, msb
->page_size
);
951 msb
->current_seg
= 0;
952 msb
->current_page
= 0;
953 msb
->data_dir
= READ
;
954 msb
->transfer_cmd
= MSPRO_CMD_READ_ATRB
;
956 card
->next_request
= h_mspro_block_req_init
;
957 msb
->mrq_handler
= h_mspro_block_transfer_data
;
958 memstick_init_req(&card
->current_mrq
, MS_TPC_WRITE_REG
, ¶m
,
960 memstick_new_req(card
->host
);
961 wait_for_completion(&card
->mrq_complete
);
962 if (card
->current_mrq
.error
) {
963 rc
= card
->current_mrq
.error
;
967 if (be16_to_cpu(attr
->signature
) != MSPRO_BLOCK_SIGNATURE
) {
968 printk(KERN_ERR
"%s: unrecognized device signature %x\n",
969 card
->dev
.bus_id
, be16_to_cpu(attr
->signature
));
974 if (attr
->count
> MSPRO_BLOCK_MAX_ATTRIBUTES
) {
975 printk(KERN_WARNING
"%s: way too many attribute entries\n",
977 attr_count
= MSPRO_BLOCK_MAX_ATTRIBUTES
;
979 attr_count
= attr
->count
;
981 msb
->attr_group
.attrs
= kzalloc((attr_count
+ 1)
982 * sizeof(struct attribute
),
984 if (!msb
->attr_group
.attrs
) {
988 msb
->attr_group
.name
= "media_attributes";
990 buffer
= kmalloc(msb
->page_size
, GFP_KERNEL
);
995 memcpy(buffer
, (char *)attr
, msb
->page_size
);
998 for (cnt
= 0; cnt
< attr_count
; ++cnt
) {
999 s_attr
= kzalloc(sizeof(struct mspro_sys_attr
), GFP_KERNEL
);
1002 goto out_free_buffer
;
1005 msb
->attr_group
.attrs
[cnt
] = &s_attr
->dev_attr
.attr
;
1006 addr
= be32_to_cpu(attr
->entries
[cnt
].address
);
1007 rc
= be32_to_cpu(attr
->entries
[cnt
].size
);
1008 dev_dbg(&card
->dev
, "adding attribute %d: id %x, address %x, "
1009 "size %x\n", cnt
, attr
->entries
[cnt
].id
, addr
, rc
);
1010 s_attr
->id
= attr
->entries
[cnt
].id
;
1011 if (mspro_block_attr_name(s_attr
->id
))
1012 snprintf(s_attr
->name
, sizeof(s_attr
->name
), "%s",
1013 mspro_block_attr_name(attr
->entries
[cnt
].id
));
1015 snprintf(s_attr
->name
, sizeof(s_attr
->name
),
1016 "attr_x%02x", attr
->entries
[cnt
].id
);
1018 s_attr
->dev_attr
.attr
.name
= s_attr
->name
;
1019 s_attr
->dev_attr
.attr
.mode
= S_IRUGO
;
1020 s_attr
->dev_attr
.attr
.owner
= THIS_MODULE
;
1021 s_attr
->dev_attr
.show
= mspro_block_attr_show(s_attr
->id
);
1027 s_attr
->data
= kmalloc(rc
, GFP_KERNEL
);
1028 if (!s_attr
->data
) {
1030 goto out_free_buffer
;
1033 if (((addr
/ msb
->page_size
)
1034 == be32_to_cpu(param
.data_address
))
1035 && (((addr
+ rc
- 1) / msb
->page_size
)
1036 == be32_to_cpu(param
.data_address
))) {
1037 memcpy(s_attr
->data
, buffer
+ addr
% msb
->page_size
,
1042 if (page_count
<= (rc
/ msb
->page_size
)) {
1044 page_count
= (rc
/ msb
->page_size
) + 1;
1045 buffer
= kmalloc(page_count
* msb
->page_size
,
1053 param
.system
= msb
->system
;
1054 param
.data_count
= cpu_to_be16((rc
/ msb
->page_size
) + 1);
1055 param
.data_address
= cpu_to_be32(addr
/ msb
->page_size
);
1056 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
1057 param
.cmd_param
= 0;
1059 param
.tpc_param
= 0;
1060 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
1062 sg_init_one(&msb
->req_sg
[0], buffer
,
1063 be16_to_cpu(param
.data_count
) * msb
->page_size
);
1065 msb
->current_seg
= 0;
1066 msb
->current_page
= 0;
1067 msb
->data_dir
= READ
;
1068 msb
->transfer_cmd
= MSPRO_CMD_READ_ATRB
;
1070 dev_dbg(&card
->dev
, "reading attribute pages %x, %x\n",
1071 be32_to_cpu(param
.data_address
),
1072 be16_to_cpu(param
.data_count
));
1074 card
->next_request
= h_mspro_block_req_init
;
1075 msb
->mrq_handler
= h_mspro_block_transfer_data
;
1076 memstick_init_req(&card
->current_mrq
, MS_TPC_WRITE_REG
,
1077 (char *)¶m
, sizeof(param
));
1078 memstick_new_req(card
->host
);
1079 wait_for_completion(&card
->mrq_complete
);
1080 if (card
->current_mrq
.error
) {
1081 rc
= card
->current_mrq
.error
;
1082 goto out_free_buffer
;
1085 memcpy(s_attr
->data
, buffer
+ addr
% msb
->page_size
, rc
);
1096 static int mspro_block_init_card(struct memstick_dev
*card
)
1098 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1099 struct memstick_host
*host
= card
->host
;
1102 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
1105 msb
->system
= MEMSTICK_SYS_SERIAL
;
1106 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
1107 card
->reg_addr
.r_offset
= offsetof(struct mspro_register
, status
);
1108 card
->reg_addr
.r_length
= sizeof(struct ms_status_register
);
1109 card
->reg_addr
.w_offset
= offsetof(struct mspro_register
, param
);
1110 card
->reg_addr
.w_length
= sizeof(struct mspro_param_register
);
1112 if (memstick_set_rw_addr(card
))
1115 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
1116 if (host
->caps
& MEMSTICK_CAP_PARALLEL
) {
1118 if (host
->caps
& MEMSTICK_CAP_PAR4
) {
1119 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c
1120 if (mspro_block_switch_to_parallel(card
))
1121 printk(KERN_WARNING
"%s: could not switch to "
1122 "parallel interface\n", card
->dev
.bus_id
);
1125 rc
= mspro_block_wait_for_ced(card
);
1128 dev_dbg(&card
->dev
, "card activated\n");
1130 card
->next_request
= h_mspro_block_req_init
;
1131 msb
->mrq_handler
= h_mspro_block_get_ro
;
1132 memstick_init_req(&card
->current_mrq
, MS_TPC_READ_REG
, NULL
,
1133 sizeof(struct ms_status_register
));
1134 memstick_new_req(card
->host
);
1135 wait_for_completion(&card
->mrq_complete
);
1136 if (card
->current_mrq
.error
)
1137 return card
->current_mrq
.error
;
1139 dev_dbg(&card
->dev
, "card r/w status %d\n", msb
->read_only
? 0 : 1);
1141 msb
->page_size
= 512;
1142 rc
= mspro_block_read_attributes(card
);
1146 dev_dbg(&card
->dev
, "attributes loaded\n");
1151 static int mspro_block_init_disk(struct memstick_dev
*card
)
1153 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1154 struct memstick_host
*host
= card
->host
;
1155 struct mspro_devinfo
*dev_info
= NULL
;
1156 struct mspro_sys_info
*sys_info
= NULL
;
1157 struct mspro_sys_attr
*s_attr
= NULL
;
1159 u64 limit
= BLK_BOUNCE_HIGH
;
1160 unsigned long capacity
;
1162 if (host
->cdev
.dev
->dma_mask
&& *(host
->cdev
.dev
->dma_mask
))
1163 limit
= *(host
->cdev
.dev
->dma_mask
);
1165 for (rc
= 0; msb
->attr_group
.attrs
[rc
]; ++rc
) {
1166 s_attr
= mspro_from_sysfs_attr(msb
->attr_group
.attrs
[rc
]);
1168 if (s_attr
->id
== MSPRO_BLOCK_ID_DEVINFO
)
1169 dev_info
= s_attr
->data
;
1170 else if (s_attr
->id
== MSPRO_BLOCK_ID_SYSINFO
)
1171 sys_info
= s_attr
->data
;
1174 if (!dev_info
|| !sys_info
)
1177 msb
->cylinders
= be16_to_cpu(dev_info
->cylinders
);
1178 msb
->heads
= be16_to_cpu(dev_info
->heads
);
1179 msb
->sectors_per_track
= be16_to_cpu(dev_info
->sectors_per_track
);
1181 msb
->page_size
= be16_to_cpu(sys_info
->unit_size
);
1183 if (!idr_pre_get(&mspro_block_disk_idr
, GFP_KERNEL
))
1186 mutex_lock(&mspro_block_disk_lock
);
1187 rc
= idr_get_new(&mspro_block_disk_idr
, card
, &disk_id
);
1188 mutex_unlock(&mspro_block_disk_lock
);
1193 if ((disk_id
<< MEMSTICK_PART_SHIFT
) > 255) {
1195 goto out_release_id
;
1198 msb
->disk
= alloc_disk(1 << MEMSTICK_PART_SHIFT
);
1201 goto out_release_id
;
1204 spin_lock_init(&msb
->q_lock
);
1205 init_waitqueue_head(&msb
->q_wait
);
1207 msb
->queue
= blk_init_queue(mspro_block_request
, &msb
->q_lock
);
1213 msb
->queue
->queuedata
= card
;
1215 blk_queue_bounce_limit(msb
->queue
, limit
);
1216 blk_queue_max_sectors(msb
->queue
, MSPRO_BLOCK_MAX_PAGES
);
1217 blk_queue_max_phys_segments(msb
->queue
, MSPRO_BLOCK_MAX_SEGS
);
1218 blk_queue_max_hw_segments(msb
->queue
, MSPRO_BLOCK_MAX_SEGS
);
1219 blk_queue_max_segment_size(msb
->queue
,
1220 MSPRO_BLOCK_MAX_PAGES
* msb
->page_size
);
1222 msb
->disk
->major
= major
;
1223 msb
->disk
->first_minor
= disk_id
<< MEMSTICK_PART_SHIFT
;
1224 msb
->disk
->fops
= &ms_block_bdops
;
1225 msb
->usage_count
= 1;
1226 msb
->disk
->private_data
= msb
;
1227 msb
->disk
->queue
= msb
->queue
;
1228 msb
->disk
->driverfs_dev
= &card
->dev
;
1230 sprintf(msb
->disk
->disk_name
, "mspblk%d", disk_id
);
1232 blk_queue_hardsect_size(msb
->queue
, msb
->page_size
);
1234 capacity
= be16_to_cpu(sys_info
->user_block_count
);
1235 capacity
*= be16_to_cpu(sys_info
->block_size
);
1236 capacity
*= msb
->page_size
>> 9;
1237 set_capacity(msb
->disk
, capacity
);
1238 dev_dbg(&card
->dev
, "capacity set %ld\n", capacity
);
1239 msb
->q_thread
= kthread_run(mspro_block_queue_thread
, card
,
1241 if (IS_ERR(msb
->q_thread
))
1244 mutex_unlock(&host
->lock
);
1245 add_disk(msb
->disk
);
1246 mutex_lock(&host
->lock
);
1251 put_disk(msb
->disk
);
1253 mutex_lock(&mspro_block_disk_lock
);
1254 idr_remove(&mspro_block_disk_idr
, disk_id
);
1255 mutex_unlock(&mspro_block_disk_lock
);
1259 static void mspro_block_data_clear(struct mspro_block_data
*msb
)
1262 struct mspro_sys_attr
*s_attr
;
1264 if (msb
->attr_group
.attrs
) {
1265 for (cnt
= 0; msb
->attr_group
.attrs
[cnt
]; ++cnt
) {
1266 s_attr
= mspro_from_sysfs_attr(msb
->attr_group
1268 kfree(s_attr
->data
);
1271 kfree(msb
->attr_group
.attrs
);
1277 static int mspro_block_check_card(struct memstick_dev
*card
)
1279 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1281 return (msb
->active
== 1);
1284 static int mspro_block_probe(struct memstick_dev
*card
)
1286 struct mspro_block_data
*msb
;
1289 msb
= kzalloc(sizeof(struct mspro_block_data
), GFP_KERNEL
);
1292 memstick_set_drvdata(card
, msb
);
1295 rc
= mspro_block_init_card(card
);
1300 rc
= sysfs_create_group(&card
->dev
.kobj
, &msb
->attr_group
);
1304 rc
= mspro_block_init_disk(card
);
1306 card
->check
= mspro_block_check_card
;
1310 sysfs_remove_group(&card
->dev
.kobj
, &msb
->attr_group
);
1312 memstick_set_drvdata(card
, NULL
);
1313 mspro_block_data_clear(msb
);
1318 static void mspro_block_remove(struct memstick_dev
*card
)
1320 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1321 struct task_struct
*q_thread
= NULL
;
1322 unsigned long flags
;
1324 del_gendisk(msb
->disk
);
1325 dev_dbg(&card
->dev
, "mspro block remove\n");
1326 spin_lock_irqsave(&msb
->q_lock
, flags
);
1327 q_thread
= msb
->q_thread
;
1328 msb
->q_thread
= NULL
;
1330 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
1333 mutex_unlock(&card
->host
->lock
);
1334 kthread_stop(q_thread
);
1335 mutex_lock(&card
->host
->lock
);
1338 dev_dbg(&card
->dev
, "queue thread stopped\n");
1340 blk_cleanup_queue(msb
->queue
);
1342 sysfs_remove_group(&card
->dev
.kobj
, &msb
->attr_group
);
1344 mutex_lock(&mspro_block_disk_lock
);
1345 mspro_block_data_clear(msb
);
1346 mutex_unlock(&mspro_block_disk_lock
);
1348 mspro_block_disk_release(msb
->disk
);
1349 memstick_set_drvdata(card
, NULL
);
1354 static int mspro_block_suspend(struct memstick_dev
*card
, pm_message_t state
)
1356 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1357 struct task_struct
*q_thread
= NULL
;
1358 unsigned long flags
;
1360 spin_lock_irqsave(&msb
->q_lock
, flags
);
1361 q_thread
= msb
->q_thread
;
1362 msb
->q_thread
= NULL
;
1364 blk_stop_queue(msb
->queue
);
1365 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
1368 kthread_stop(q_thread
);
1373 static int mspro_block_resume(struct memstick_dev
*card
)
1375 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1376 unsigned long flags
;
1379 #ifdef CONFIG_MEMSTICK_UNSAFE_RESUME
1381 struct mspro_block_data
*new_msb
;
1382 struct memstick_host
*host
= card
->host
;
1383 struct mspro_sys_attr
*s_attr
, *r_attr
;
1386 mutex_lock(&host
->lock
);
1387 new_msb
= kzalloc(sizeof(struct mspro_block_data
), GFP_KERNEL
);
1393 new_msb
->card
= card
;
1394 memstick_set_drvdata(card
, new_msb
);
1395 if (mspro_block_init_card(card
))
1398 for (cnt
= 0; new_msb
->attr_group
.attrs
[cnt
]
1399 && msb
->attr_group
.attrs
[cnt
]; ++cnt
) {
1400 s_attr
= mspro_from_sysfs_attr(new_msb
->attr_group
.attrs
[cnt
]);
1401 r_attr
= mspro_from_sysfs_attr(msb
->attr_group
.attrs
[cnt
]);
1403 if (s_attr
->id
== MSPRO_BLOCK_ID_SYSINFO
1404 && r_attr
->id
== s_attr
->id
) {
1405 if (memcmp(s_attr
->data
, r_attr
->data
, s_attr
->size
))
1408 memstick_set_drvdata(card
, msb
);
1409 msb
->q_thread
= kthread_run(mspro_block_queue_thread
,
1410 card
, DRIVER_NAME
"d");
1411 if (IS_ERR(msb
->q_thread
))
1412 msb
->q_thread
= NULL
;
1421 memstick_set_drvdata(card
, msb
);
1422 mspro_block_data_clear(new_msb
);
1425 mutex_unlock(&host
->lock
);
1427 #endif /* CONFIG_MEMSTICK_UNSAFE_RESUME */
1429 spin_lock_irqsave(&msb
->q_lock
, flags
);
1430 blk_start_queue(msb
->queue
);
1431 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
1437 #define mspro_block_suspend NULL
1438 #define mspro_block_resume NULL
1440 #endif /* CONFIG_PM */
1442 static struct memstick_device_id mspro_block_id_tbl
[] = {
1443 {MEMSTICK_MATCH_ALL
, MEMSTICK_TYPE_PRO
, MEMSTICK_CATEGORY_STORAGE_DUO
,
1444 MEMSTICK_CLASS_GENERIC_DUO
},
1449 static struct memstick_driver mspro_block_driver
= {
1451 .name
= DRIVER_NAME
,
1452 .owner
= THIS_MODULE
1454 .id_table
= mspro_block_id_tbl
,
1455 .probe
= mspro_block_probe
,
1456 .remove
= mspro_block_remove
,
1457 .suspend
= mspro_block_suspend
,
1458 .resume
= mspro_block_resume
1461 static int __init
mspro_block_init(void)
1465 rc
= register_blkdev(major
, DRIVER_NAME
);
1467 printk(KERN_ERR DRIVER_NAME
": failed to register "
1468 "major %d, error %d\n", major
, rc
);
1474 rc
= memstick_register_driver(&mspro_block_driver
);
1476 unregister_blkdev(major
, DRIVER_NAME
);
1480 static void __exit
mspro_block_exit(void)
1482 memstick_unregister_driver(&mspro_block_driver
);
1483 unregister_blkdev(major
, DRIVER_NAME
);
1484 idr_destroy(&mspro_block_disk_idr
);
1487 module_init(mspro_block_init
);
1488 module_exit(mspro_block_exit
);
1490 MODULE_LICENSE("GPL");
1491 MODULE_AUTHOR("Alex Dubov");
1492 MODULE_DESCRIPTION("Sony MemoryStickPro block device driver");
1493 MODULE_DEVICE_TABLE(memstick
, mspro_block_id_tbl
);
1494 <<<<<<< HEAD
:drivers
/memstick
/core
/mspro_block
.c
1495 MODULE_VERSION(DRIVER_VERSION
);
1497 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/memstick
/core
/mspro_block
.c