1 // SPDX-License-Identifier: GPL-2.0-only
3 * Sony MemoryStick Pro storage support
5 * Copyright (C) 2007 Alex Dubov <oakad@yahoo.com>
7 * Special thanks to Carlos Corbacho for providing various MemoryStick cards
8 * that made this driver possible.
11 #include <linux/blk-mq.h>
12 #include <linux/idr.h>
13 #include <linux/hdreg.h>
14 #include <linux/kthread.h>
15 #include <linux/delay.h>
16 #include <linux/slab.h>
17 #include <linux/mutex.h>
18 #include <linux/memstick.h>
19 #include <linux/module.h>
21 #define DRIVER_NAME "mspro_block"
24 module_param(major
, int, 0644);
26 #define MSPRO_BLOCK_MAX_SEGS 32
27 #define MSPRO_BLOCK_MAX_PAGES ((2 << 16) - 1)
29 #define MSPRO_BLOCK_SIGNATURE 0xa5c3
30 #define MSPRO_BLOCK_MAX_ATTRIBUTES 41
32 #define MSPRO_BLOCK_PART_SHIFT 3
35 MSPRO_BLOCK_ID_SYSINFO
= 0x10,
36 MSPRO_BLOCK_ID_MODELNAME
= 0x15,
37 MSPRO_BLOCK_ID_MBR
= 0x20,
38 MSPRO_BLOCK_ID_PBR16
= 0x21,
39 MSPRO_BLOCK_ID_PBR32
= 0x22,
40 MSPRO_BLOCK_ID_SPECFILEVALUES1
= 0x25,
41 MSPRO_BLOCK_ID_SPECFILEVALUES2
= 0x26,
42 MSPRO_BLOCK_ID_DEVINFO
= 0x30
45 struct mspro_sys_attr
{
50 struct device_attribute dev_attr
;
53 struct mspro_attr_entry
{
57 unsigned char reserved
[3];
58 } __attribute__((packed
));
60 struct mspro_attribute
{
62 unsigned short version
;
64 unsigned char reserved
[11];
65 struct mspro_attr_entry entries
[];
66 } __attribute__((packed
));
68 struct mspro_sys_info
{
70 unsigned char reserved0
;
73 __be16 user_block_count
;
75 unsigned char reserved1
[2];
76 unsigned char assembly_date
[8];
78 unsigned char assembly_maker_code
;
79 unsigned char assembly_model_code
[3];
80 __be16 memory_maker_code
;
81 __be16 memory_model_code
;
82 unsigned char reserved2
[4];
85 __be16 controller_number
;
86 __be16 controller_function
;
89 unsigned char ms_sub_class
;
90 unsigned char reserved3
[4];
91 unsigned char interface_type
;
92 __be16 controller_code
;
93 unsigned char format_type
;
94 unsigned char reserved4
;
95 unsigned char device_type
;
96 unsigned char reserved5
[7];
97 unsigned char mspro_id
[16];
98 unsigned char reserved6
[16];
99 } __attribute__((packed
));
102 unsigned char boot_partition
;
103 unsigned char start_head
;
104 unsigned char start_sector
;
105 unsigned char start_cylinder
;
106 unsigned char partition_type
;
107 unsigned char end_head
;
108 unsigned char end_sector
;
109 unsigned char end_cylinder
;
110 unsigned int start_sectors
;
111 unsigned int sectors_per_partition
;
112 } __attribute__((packed
));
114 struct mspro_specfile
{
118 unsigned char reserved
[10];
121 unsigned short cluster
;
123 } __attribute__((packed
));
125 struct mspro_devinfo
{
128 __be16 bytes_per_track
;
129 __be16 bytes_per_sector
;
130 __be16 sectors_per_track
;
131 unsigned char reserved
[6];
132 } __attribute__((packed
));
134 struct mspro_block_data
{
135 struct memstick_dev
*card
;
136 unsigned int usage_count
;
138 struct gendisk
*disk
;
139 struct request_queue
*queue
;
140 struct request
*block_req
;
141 struct blk_mq_tag_set tag_set
;
144 unsigned short page_size
;
145 unsigned short cylinders
;
146 unsigned short heads
;
147 unsigned short sectors_per_track
;
149 unsigned char system
;
150 unsigned char read_only
:1,
154 unsigned char transfer_cmd
;
156 int (*mrq_handler
)(struct memstick_dev
*card
,
157 struct memstick_request
**mrq
);
160 /* Default request setup function for data access method preferred by
161 * this host instance.
163 void (*setup_transfer
)(struct memstick_dev
*card
,
164 u64 offset
, size_t length
);
166 struct attribute_group attr_group
;
168 struct scatterlist req_sg
[MSPRO_BLOCK_MAX_SEGS
];
169 unsigned int seg_count
;
170 unsigned int current_seg
;
171 unsigned int current_page
;
174 static DEFINE_IDR(mspro_block_disk_idr
);
175 static DEFINE_MUTEX(mspro_block_disk_lock
);
177 static int mspro_block_complete_req(struct memstick_dev
*card
, int error
);
179 /*** Block device ***/
181 static int mspro_block_bd_open(struct block_device
*bdev
, fmode_t mode
)
183 struct gendisk
*disk
= bdev
->bd_disk
;
184 struct mspro_block_data
*msb
= disk
->private_data
;
187 mutex_lock(&mspro_block_disk_lock
);
189 if (msb
&& msb
->card
) {
191 if ((mode
& FMODE_WRITE
) && msb
->read_only
)
197 mutex_unlock(&mspro_block_disk_lock
);
203 static void mspro_block_disk_release(struct gendisk
*disk
)
205 struct mspro_block_data
*msb
= disk
->private_data
;
206 int disk_id
= MINOR(disk_devt(disk
)) >> MSPRO_BLOCK_PART_SHIFT
;
208 mutex_lock(&mspro_block_disk_lock
);
211 if (msb
->usage_count
)
214 if (!msb
->usage_count
) {
216 disk
->private_data
= NULL
;
217 idr_remove(&mspro_block_disk_idr
, disk_id
);
222 mutex_unlock(&mspro_block_disk_lock
);
225 static void mspro_block_bd_release(struct gendisk
*disk
, fmode_t mode
)
227 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 const 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 int date_tz
= 0, date_tz_f
= 0;
319 if (x_sys
->assembly_date
[0] > 0x80U
) {
320 date_tz
= (~x_sys
->assembly_date
[0]) + 1;
321 date_tz_f
= date_tz
& 3;
325 } else if (x_sys
->assembly_date
[0] < 0x80U
) {
326 date_tz
= x_sys
->assembly_date
[0];
327 date_tz_f
= date_tz
& 3;
332 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "class: %x\n",
334 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "block size: %x\n",
335 be16_to_cpu(x_sys
->block_size
));
336 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "block count: %x\n",
337 be16_to_cpu(x_sys
->block_count
));
338 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "user block count: %x\n",
339 be16_to_cpu(x_sys
->user_block_count
));
340 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "page size: %x\n",
341 be16_to_cpu(x_sys
->page_size
));
342 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "assembly date: "
343 "GMT%+d:%d %04u-%02u-%02u %02u:%02u:%02u\n",
345 be16_to_cpup((__be16
*)&x_sys
->assembly_date
[1]),
346 x_sys
->assembly_date
[3], x_sys
->assembly_date
[4],
347 x_sys
->assembly_date
[5], x_sys
->assembly_date
[6],
348 x_sys
->assembly_date
[7]);
349 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "serial number: %x\n",
350 be32_to_cpu(x_sys
->serial_number
));
351 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
,
352 "assembly maker code: %x\n",
353 x_sys
->assembly_maker_code
);
354 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "assembly model code: "
355 "%02x%02x%02x\n", x_sys
->assembly_model_code
[0],
356 x_sys
->assembly_model_code
[1],
357 x_sys
->assembly_model_code
[2]);
358 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "memory maker code: %x\n",
359 be16_to_cpu(x_sys
->memory_maker_code
));
360 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "memory model code: %x\n",
361 be16_to_cpu(x_sys
->memory_model_code
));
362 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "vcc: %x\n",
364 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "vpp: %x\n",
366 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "controller number: %x\n",
367 be16_to_cpu(x_sys
->controller_number
));
368 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
,
369 "controller function: %x\n",
370 be16_to_cpu(x_sys
->controller_function
));
371 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start sector: %x\n",
372 be16_to_cpu(x_sys
->start_sector
));
373 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "unit size: %x\n",
374 be16_to_cpu(x_sys
->unit_size
));
375 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "sub class: %x\n",
376 x_sys
->ms_sub_class
);
377 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "interface type: %x\n",
378 x_sys
->interface_type
);
379 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "controller code: %x\n",
380 be16_to_cpu(x_sys
->controller_code
));
381 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "format type: %x\n",
383 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "device type: %x\n",
385 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "mspro id: %s\n",
390 static ssize_t
mspro_block_attr_show_modelname(struct device
*dev
,
391 struct device_attribute
*attr
,
394 struct mspro_sys_attr
*s_attr
= container_of(attr
,
395 struct mspro_sys_attr
,
398 return scnprintf(buffer
, PAGE_SIZE
, "%s", (char *)s_attr
->data
);
401 static ssize_t
mspro_block_attr_show_mbr(struct device
*dev
,
402 struct device_attribute
*attr
,
405 struct mspro_sys_attr
*x_attr
= container_of(attr
,
406 struct mspro_sys_attr
,
408 struct mspro_mbr
*x_mbr
= x_attr
->data
;
411 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "boot partition: %x\n",
412 x_mbr
->boot_partition
);
413 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start head: %x\n",
415 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start sector: %x\n",
416 x_mbr
->start_sector
);
417 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start cylinder: %x\n",
418 x_mbr
->start_cylinder
);
419 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "partition type: %x\n",
420 x_mbr
->partition_type
);
421 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "end head: %x\n",
423 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "end sector: %x\n",
425 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "end cylinder: %x\n",
426 x_mbr
->end_cylinder
);
427 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start sectors: %x\n",
428 x_mbr
->start_sectors
);
429 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
,
430 "sectors per partition: %x\n",
431 x_mbr
->sectors_per_partition
);
435 static ssize_t
mspro_block_attr_show_specfile(struct device
*dev
,
436 struct device_attribute
*attr
,
439 struct mspro_sys_attr
*x_attr
= container_of(attr
,
440 struct mspro_sys_attr
,
442 struct mspro_specfile
*x_spfile
= x_attr
->data
;
443 char name
[9], ext
[4];
446 memcpy(name
, x_spfile
->name
, 8);
448 memcpy(ext
, x_spfile
->ext
, 3);
451 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "name: %s\n", name
);
452 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "ext: %s\n", ext
);
453 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "attribute: %x\n",
455 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "time: %d:%d:%d\n",
456 x_spfile
->time
>> 11,
457 (x_spfile
->time
>> 5) & 0x3f,
458 (x_spfile
->time
& 0x1f) * 2);
459 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "date: %d-%d-%d\n",
460 (x_spfile
->date
>> 9) + 1980,
461 (x_spfile
->date
>> 5) & 0xf,
462 x_spfile
->date
& 0x1f);
463 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start cluster: %x\n",
465 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "size: %x\n",
470 static ssize_t
mspro_block_attr_show_devinfo(struct device
*dev
,
471 struct device_attribute
*attr
,
474 struct mspro_sys_attr
*x_attr
= container_of(attr
,
475 struct mspro_sys_attr
,
477 struct mspro_devinfo
*x_devinfo
= x_attr
->data
;
480 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "cylinders: %x\n",
481 be16_to_cpu(x_devinfo
->cylinders
));
482 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "heads: %x\n",
483 be16_to_cpu(x_devinfo
->heads
));
484 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "bytes per track: %x\n",
485 be16_to_cpu(x_devinfo
->bytes_per_track
));
486 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "bytes per sector: %x\n",
487 be16_to_cpu(x_devinfo
->bytes_per_sector
));
488 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "sectors per track: %x\n",
489 be16_to_cpu(x_devinfo
->sectors_per_track
));
493 static sysfs_show_t
mspro_block_attr_show(unsigned char tag
)
496 case MSPRO_BLOCK_ID_SYSINFO
:
497 return mspro_block_attr_show_sysinfo
;
498 case MSPRO_BLOCK_ID_MODELNAME
:
499 return mspro_block_attr_show_modelname
;
500 case MSPRO_BLOCK_ID_MBR
:
501 return mspro_block_attr_show_mbr
;
502 case MSPRO_BLOCK_ID_SPECFILEVALUES1
:
503 case MSPRO_BLOCK_ID_SPECFILEVALUES2
:
504 return mspro_block_attr_show_specfile
;
505 case MSPRO_BLOCK_ID_DEVINFO
:
506 return mspro_block_attr_show_devinfo
;
508 return mspro_block_attr_show_default
;
512 /*** Protocol handlers ***/
515 * Functions prefixed with "h_" are protocol callbacks. They can be called from
516 * interrupt context. Return value of 0 means that request processing is still
517 * ongoing, while special error value of -EAGAIN means that current request is
518 * finished (and request processor should come back some time later).
521 static int h_mspro_block_req_init(struct memstick_dev
*card
,
522 struct memstick_request
**mrq
)
524 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
526 *mrq
= &card
->current_mrq
;
527 card
->next_request
= msb
->mrq_handler
;
531 static int h_mspro_block_default(struct memstick_dev
*card
,
532 struct memstick_request
**mrq
)
534 return mspro_block_complete_req(card
, (*mrq
)->error
);
537 static int h_mspro_block_default_bad(struct memstick_dev
*card
,
538 struct memstick_request
**mrq
)
543 static int h_mspro_block_get_ro(struct memstick_dev
*card
,
544 struct memstick_request
**mrq
)
546 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
548 if (!(*mrq
)->error
) {
549 if ((*mrq
)->data
[offsetof(struct ms_status_register
, status0
)]
550 & MEMSTICK_STATUS0_WP
)
556 return mspro_block_complete_req(card
, (*mrq
)->error
);
559 static int h_mspro_block_wait_for_ced(struct memstick_dev
*card
,
560 struct memstick_request
**mrq
)
562 dev_dbg(&card
->dev
, "wait for ced: value %x\n", (*mrq
)->data
[0]);
564 if (!(*mrq
)->error
) {
565 if ((*mrq
)->data
[0] & (MEMSTICK_INT_CMDNAK
| MEMSTICK_INT_ERR
))
566 (*mrq
)->error
= -EFAULT
;
567 else if (!((*mrq
)->data
[0] & MEMSTICK_INT_CED
))
571 return mspro_block_complete_req(card
, (*mrq
)->error
);
574 static int h_mspro_block_transfer_data(struct memstick_dev
*card
,
575 struct memstick_request
**mrq
)
577 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
578 unsigned char t_val
= 0;
579 struct scatterlist t_sg
= { 0 };
583 return mspro_block_complete_req(card
, (*mrq
)->error
);
585 switch ((*mrq
)->tpc
) {
586 case MS_TPC_WRITE_REG
:
587 memstick_init_req(*mrq
, MS_TPC_SET_CMD
, &msb
->transfer_cmd
, 1);
588 (*mrq
)->need_card_int
= 1;
591 t_val
= (*mrq
)->int_reg
;
592 memstick_init_req(*mrq
, MS_TPC_GET_INT
, NULL
, 1);
593 if (msb
->caps
& MEMSTICK_CAP_AUTO_GET_INT
)
597 t_val
= (*mrq
)->data
[0];
599 if (t_val
& (MEMSTICK_INT_CMDNAK
| MEMSTICK_INT_ERR
)) {
600 t_val
= MSPRO_CMD_STOP
;
601 memstick_init_req(*mrq
, MS_TPC_SET_CMD
, &t_val
, 1);
602 card
->next_request
= h_mspro_block_default
;
606 if (msb
->current_page
607 == (msb
->req_sg
[msb
->current_seg
].length
609 msb
->current_page
= 0;
612 if (msb
->current_seg
== msb
->seg_count
) {
613 if (t_val
& MEMSTICK_INT_CED
) {
614 return mspro_block_complete_req(card
,
618 = h_mspro_block_wait_for_ced
;
619 memstick_init_req(*mrq
, MS_TPC_GET_INT
,
626 if (!(t_val
& MEMSTICK_INT_BREQ
)) {
627 memstick_init_req(*mrq
, MS_TPC_GET_INT
, NULL
, 1);
631 t_offset
= msb
->req_sg
[msb
->current_seg
].offset
;
632 t_offset
+= msb
->current_page
* msb
->page_size
;
635 nth_page(sg_page(&(msb
->req_sg
[msb
->current_seg
])),
636 t_offset
>> PAGE_SHIFT
),
637 msb
->page_size
, offset_in_page(t_offset
));
639 memstick_init_req_sg(*mrq
, msb
->data_dir
== READ
640 ? MS_TPC_READ_LONG_DATA
641 : MS_TPC_WRITE_LONG_DATA
,
643 (*mrq
)->need_card_int
= 1;
645 case MS_TPC_READ_LONG_DATA
:
646 case MS_TPC_WRITE_LONG_DATA
:
648 if (msb
->caps
& MEMSTICK_CAP_AUTO_GET_INT
) {
649 t_val
= (*mrq
)->int_reg
;
652 memstick_init_req(*mrq
, MS_TPC_GET_INT
, NULL
, 1);
661 /*** Transfer setup functions for different access methods. ***/
663 /** Setup data transfer request for SET_CMD TPC with arguments in card
666 * @card Current media instance
667 * @offset Target data offset in bytes
668 * @length Required transfer length in bytes.
670 static void h_mspro_block_setup_cmd(struct memstick_dev
*card
, u64 offset
,
673 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
674 struct mspro_param_register param
= {
675 .system
= msb
->system
,
676 .data_count
= cpu_to_be16((uint16_t)(length
/ msb
->page_size
)),
677 /* ISO C90 warning precludes direct initialization for now. */
682 do_div(offset
, msb
->page_size
);
683 param
.data_address
= cpu_to_be32((uint32_t)offset
);
685 card
->next_request
= h_mspro_block_req_init
;
686 msb
->mrq_handler
= h_mspro_block_transfer_data
;
687 memstick_init_req(&card
->current_mrq
, MS_TPC_WRITE_REG
,
688 ¶m
, sizeof(param
));
691 /*** Data transfer ***/
693 static int mspro_block_issue_req(struct memstick_dev
*card
)
695 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
700 msb
->current_page
= 0;
701 msb
->current_seg
= 0;
702 msb
->seg_count
= blk_rq_map_sg(msb
->block_req
->q
,
706 if (!msb
->seg_count
) {
707 unsigned int bytes
= blk_rq_cur_bytes(msb
->block_req
);
710 chunk
= blk_update_request(msb
->block_req
,
715 __blk_mq_end_request(msb
->block_req
,
717 msb
->block_req
= NULL
;
721 t_off
= blk_rq_pos(msb
->block_req
);
723 count
= blk_rq_bytes(msb
->block_req
);
725 msb
->setup_transfer(card
, t_off
, count
);
727 msb
->data_dir
= rq_data_dir(msb
->block_req
);
728 msb
->transfer_cmd
= msb
->data_dir
== READ
729 ? MSPRO_CMD_READ_DATA
730 : MSPRO_CMD_WRITE_DATA
;
732 memstick_new_req(card
->host
);
737 static int mspro_block_complete_req(struct memstick_dev
*card
, int error
)
739 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
742 unsigned int t_len
= 0;
745 spin_lock_irqsave(&msb
->q_lock
, flags
);
746 dev_dbg(&card
->dev
, "complete %d, %d\n", msb
->block_req
? 1 : 0,
749 if (msb
->block_req
) {
750 /* Nothing to do - not really an error */
751 if (error
== -EAGAIN
)
754 if (error
|| (card
->current_mrq
.tpc
== MSPRO_CMD_STOP
)) {
755 if (msb
->data_dir
== READ
) {
756 for (cnt
= 0; cnt
< msb
->current_seg
; cnt
++) {
757 t_len
+= msb
->req_sg
[cnt
].length
760 if (msb
->current_page
)
761 t_len
+= msb
->current_page
- 1;
763 t_len
*= msb
->page_size
;
767 t_len
= blk_rq_bytes(msb
->block_req
);
769 dev_dbg(&card
->dev
, "transferred %x (%d)\n", t_len
, error
);
772 t_len
= blk_rq_cur_bytes(msb
->block_req
);
774 chunk
= blk_update_request(msb
->block_req
,
775 errno_to_blk_status(error
), t_len
);
777 error
= mspro_block_issue_req(card
);
781 __blk_mq_end_request(msb
->block_req
,
782 errno_to_blk_status(error
));
783 msb
->block_req
= NULL
;
790 card
->next_request
= h_mspro_block_default_bad
;
791 complete_all(&card
->mrq_complete
);
793 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
797 static void mspro_block_stop(struct memstick_dev
*card
)
799 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
804 spin_lock_irqsave(&msb
->q_lock
, flags
);
805 if (!msb
->block_req
) {
806 blk_mq_stop_hw_queues(msb
->queue
);
809 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
814 wait_for_completion(&card
->mrq_complete
);
818 static void mspro_block_start(struct memstick_dev
*card
)
820 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
822 blk_mq_start_hw_queues(msb
->queue
);
825 static blk_status_t
mspro_queue_rq(struct blk_mq_hw_ctx
*hctx
,
826 const struct blk_mq_queue_data
*bd
)
828 struct memstick_dev
*card
= hctx
->queue
->queuedata
;
829 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
831 spin_lock_irq(&msb
->q_lock
);
833 if (msb
->block_req
) {
834 spin_unlock_irq(&msb
->q_lock
);
835 return BLK_STS_DEV_RESOURCE
;
839 spin_unlock_irq(&msb
->q_lock
);
840 blk_mq_start_request(bd
->rq
);
841 return BLK_STS_IOERR
;
844 msb
->block_req
= bd
->rq
;
845 blk_mq_start_request(bd
->rq
);
847 if (mspro_block_issue_req(card
))
848 msb
->block_req
= NULL
;
850 spin_unlock_irq(&msb
->q_lock
);
854 /*** Initialization ***/
856 static int mspro_block_wait_for_ced(struct memstick_dev
*card
)
858 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
860 card
->next_request
= h_mspro_block_req_init
;
861 msb
->mrq_handler
= h_mspro_block_wait_for_ced
;
862 memstick_init_req(&card
->current_mrq
, MS_TPC_GET_INT
, NULL
, 1);
863 memstick_new_req(card
->host
);
864 wait_for_completion(&card
->mrq_complete
);
865 return card
->current_mrq
.error
;
868 static int mspro_block_set_interface(struct memstick_dev
*card
,
869 unsigned char sys_reg
)
871 struct memstick_host
*host
= card
->host
;
872 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
873 struct mspro_param_register param
= {
880 card
->next_request
= h_mspro_block_req_init
;
881 msb
->mrq_handler
= h_mspro_block_default
;
882 memstick_init_req(&card
->current_mrq
, MS_TPC_WRITE_REG
, ¶m
,
884 memstick_new_req(host
);
885 wait_for_completion(&card
->mrq_complete
);
886 return card
->current_mrq
.error
;
889 static int mspro_block_switch_interface(struct memstick_dev
*card
)
891 struct memstick_host
*host
= card
->host
;
892 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
896 if (msb
->caps
& MEMSTICK_CAP_PAR4
)
897 rc
= mspro_block_set_interface(card
, MEMSTICK_SYS_PAR4
);
903 "%s: could not switch to 4-bit mode, error %d\n",
904 dev_name(&card
->dev
), rc
);
908 msb
->system
= MEMSTICK_SYS_PAR4
;
909 host
->set_param(host
, MEMSTICK_INTERFACE
, MEMSTICK_PAR4
);
910 printk(KERN_INFO
"%s: switching to 4-bit parallel mode\n",
911 dev_name(&card
->dev
));
913 if (msb
->caps
& MEMSTICK_CAP_PAR8
) {
914 rc
= mspro_block_set_interface(card
, MEMSTICK_SYS_PAR8
);
917 msb
->system
= MEMSTICK_SYS_PAR8
;
918 host
->set_param(host
, MEMSTICK_INTERFACE
,
921 "%s: switching to 8-bit parallel mode\n",
922 dev_name(&card
->dev
));
925 "%s: could not switch to 8-bit mode, error %d\n",
926 dev_name(&card
->dev
), rc
);
929 card
->next_request
= h_mspro_block_req_init
;
930 msb
->mrq_handler
= h_mspro_block_default
;
931 memstick_init_req(&card
->current_mrq
, MS_TPC_GET_INT
, NULL
, 1);
932 memstick_new_req(card
->host
);
933 wait_for_completion(&card
->mrq_complete
);
934 rc
= card
->current_mrq
.error
;
938 "%s: interface error, trying to fall back to serial\n",
939 dev_name(&card
->dev
));
940 msb
->system
= MEMSTICK_SYS_SERIAL
;
941 host
->set_param(host
, MEMSTICK_POWER
, MEMSTICK_POWER_OFF
);
943 host
->set_param(host
, MEMSTICK_POWER
, MEMSTICK_POWER_ON
);
944 host
->set_param(host
, MEMSTICK_INTERFACE
, MEMSTICK_SERIAL
);
946 rc
= memstick_set_rw_addr(card
);
948 rc
= mspro_block_set_interface(card
, msb
->system
);
952 rc
= mspro_block_wait_for_ced(card
);
956 if (msb
->caps
& MEMSTICK_CAP_PAR8
) {
957 msb
->caps
&= ~MEMSTICK_CAP_PAR8
;
965 /* Memory allocated for attributes by this function should be freed by
966 * mspro_block_data_clear, no matter if the initialization process succeeded
969 static int mspro_block_read_attributes(struct memstick_dev
*card
)
971 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
972 struct mspro_attribute
*attr
= NULL
;
973 struct mspro_sys_attr
*s_attr
= NULL
;
974 unsigned char *buffer
= NULL
;
975 int cnt
, rc
, attr_count
;
976 /* While normally physical device offsets, represented here by
977 * attr_offset and attr_len will be of large numeric types, we can be
978 * sure, that attributes are close enough to the beginning of the
979 * device, to save ourselves some trouble.
981 unsigned int addr
, attr_offset
= 0, attr_len
= msb
->page_size
;
983 attr
= kmalloc(msb
->page_size
, GFP_KERNEL
);
987 sg_init_one(&msb
->req_sg
[0], attr
, msb
->page_size
);
989 msb
->current_seg
= 0;
990 msb
->current_page
= 0;
991 msb
->data_dir
= READ
;
992 msb
->transfer_cmd
= MSPRO_CMD_READ_ATRB
;
994 msb
->setup_transfer(card
, attr_offset
, attr_len
);
996 memstick_new_req(card
->host
);
997 wait_for_completion(&card
->mrq_complete
);
998 if (card
->current_mrq
.error
) {
999 rc
= card
->current_mrq
.error
;
1003 if (be16_to_cpu(attr
->signature
) != MSPRO_BLOCK_SIGNATURE
) {
1004 printk(KERN_ERR
"%s: unrecognized device signature %x\n",
1005 dev_name(&card
->dev
), be16_to_cpu(attr
->signature
));
1010 if (attr
->count
> MSPRO_BLOCK_MAX_ATTRIBUTES
) {
1011 printk(KERN_WARNING
"%s: way too many attribute entries\n",
1012 dev_name(&card
->dev
));
1013 attr_count
= MSPRO_BLOCK_MAX_ATTRIBUTES
;
1015 attr_count
= attr
->count
;
1017 msb
->attr_group
.attrs
= kcalloc(attr_count
+ 1,
1018 sizeof(*msb
->attr_group
.attrs
),
1020 if (!msb
->attr_group
.attrs
) {
1024 msb
->attr_group
.name
= "media_attributes";
1026 buffer
= kmemdup(attr
, attr_len
, GFP_KERNEL
);
1032 for (cnt
= 0; cnt
< attr_count
; ++cnt
) {
1033 s_attr
= kzalloc(sizeof(struct mspro_sys_attr
), GFP_KERNEL
);
1036 goto out_free_buffer
;
1039 msb
->attr_group
.attrs
[cnt
] = &s_attr
->dev_attr
.attr
;
1040 addr
= be32_to_cpu(attr
->entries
[cnt
].address
);
1041 s_attr
->size
= be32_to_cpu(attr
->entries
[cnt
].size
);
1042 dev_dbg(&card
->dev
, "adding attribute %d: id %x, address %x, "
1043 "size %zx\n", cnt
, attr
->entries
[cnt
].id
, addr
,
1045 s_attr
->id
= attr
->entries
[cnt
].id
;
1046 if (mspro_block_attr_name(s_attr
->id
))
1047 snprintf(s_attr
->name
, sizeof(s_attr
->name
), "%s",
1048 mspro_block_attr_name(attr
->entries
[cnt
].id
));
1050 snprintf(s_attr
->name
, sizeof(s_attr
->name
),
1051 "attr_x%02x", attr
->entries
[cnt
].id
);
1053 sysfs_attr_init(&s_attr
->dev_attr
.attr
);
1054 s_attr
->dev_attr
.attr
.name
= s_attr
->name
;
1055 s_attr
->dev_attr
.attr
.mode
= S_IRUGO
;
1056 s_attr
->dev_attr
.show
= mspro_block_attr_show(s_attr
->id
);
1061 s_attr
->data
= kmalloc(s_attr
->size
, GFP_KERNEL
);
1062 if (!s_attr
->data
) {
1064 goto out_free_buffer
;
1067 if (((addr
/ msb
->page_size
) == (attr_offset
/ msb
->page_size
))
1068 && (((addr
+ s_attr
->size
- 1) / msb
->page_size
)
1069 == (attr_offset
/ msb
->page_size
))) {
1070 memcpy(s_attr
->data
, buffer
+ addr
% msb
->page_size
,
1075 attr_offset
= (addr
/ msb
->page_size
) * msb
->page_size
;
1077 if ((attr_offset
+ attr_len
) < (addr
+ s_attr
->size
)) {
1079 attr_len
= (((addr
+ s_attr
->size
) / msb
->page_size
)
1080 + 1 ) * msb
->page_size
- attr_offset
;
1081 buffer
= kmalloc(attr_len
, GFP_KERNEL
);
1088 sg_init_one(&msb
->req_sg
[0], buffer
, attr_len
);
1090 msb
->current_seg
= 0;
1091 msb
->current_page
= 0;
1092 msb
->data_dir
= READ
;
1093 msb
->transfer_cmd
= MSPRO_CMD_READ_ATRB
;
1095 dev_dbg(&card
->dev
, "reading attribute range %x, %x\n",
1096 attr_offset
, attr_len
);
1098 msb
->setup_transfer(card
, attr_offset
, attr_len
);
1099 memstick_new_req(card
->host
);
1100 wait_for_completion(&card
->mrq_complete
);
1101 if (card
->current_mrq
.error
) {
1102 rc
= card
->current_mrq
.error
;
1103 goto out_free_buffer
;
1106 memcpy(s_attr
->data
, buffer
+ addr
% msb
->page_size
,
1118 static int mspro_block_init_card(struct memstick_dev
*card
)
1120 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1121 struct memstick_host
*host
= card
->host
;
1124 msb
->system
= MEMSTICK_SYS_SERIAL
;
1125 msb
->setup_transfer
= h_mspro_block_setup_cmd
;
1127 card
->reg_addr
.r_offset
= offsetof(struct mspro_register
, status
);
1128 card
->reg_addr
.r_length
= sizeof(struct ms_status_register
);
1129 card
->reg_addr
.w_offset
= offsetof(struct mspro_register
, param
);
1130 card
->reg_addr
.w_length
= sizeof(struct mspro_param_register
);
1132 if (memstick_set_rw_addr(card
))
1135 msb
->caps
= host
->caps
;
1138 rc
= mspro_block_wait_for_ced(card
);
1142 rc
= mspro_block_switch_interface(card
);
1146 dev_dbg(&card
->dev
, "card activated\n");
1147 if (msb
->system
!= MEMSTICK_SYS_SERIAL
)
1148 msb
->caps
|= MEMSTICK_CAP_AUTO_GET_INT
;
1150 card
->next_request
= h_mspro_block_req_init
;
1151 msb
->mrq_handler
= h_mspro_block_get_ro
;
1152 memstick_init_req(&card
->current_mrq
, MS_TPC_READ_REG
, NULL
,
1153 sizeof(struct ms_status_register
));
1154 memstick_new_req(card
->host
);
1155 wait_for_completion(&card
->mrq_complete
);
1156 if (card
->current_mrq
.error
)
1157 return card
->current_mrq
.error
;
1159 dev_dbg(&card
->dev
, "card r/w status %d\n", msb
->read_only
? 0 : 1);
1161 msb
->page_size
= 512;
1162 rc
= mspro_block_read_attributes(card
);
1166 dev_dbg(&card
->dev
, "attributes loaded\n");
1171 static const struct blk_mq_ops mspro_mq_ops
= {
1172 .queue_rq
= mspro_queue_rq
,
1175 static int mspro_block_init_disk(struct memstick_dev
*card
)
1177 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1178 struct mspro_devinfo
*dev_info
= NULL
;
1179 struct mspro_sys_info
*sys_info
= NULL
;
1180 struct mspro_sys_attr
*s_attr
= NULL
;
1182 unsigned long capacity
;
1184 for (rc
= 0; msb
->attr_group
.attrs
[rc
]; ++rc
) {
1185 s_attr
= mspro_from_sysfs_attr(msb
->attr_group
.attrs
[rc
]);
1187 if (s_attr
->id
== MSPRO_BLOCK_ID_DEVINFO
)
1188 dev_info
= s_attr
->data
;
1189 else if (s_attr
->id
== MSPRO_BLOCK_ID_SYSINFO
)
1190 sys_info
= s_attr
->data
;
1193 if (!dev_info
|| !sys_info
)
1196 msb
->cylinders
= be16_to_cpu(dev_info
->cylinders
);
1197 msb
->heads
= be16_to_cpu(dev_info
->heads
);
1198 msb
->sectors_per_track
= be16_to_cpu(dev_info
->sectors_per_track
);
1200 msb
->page_size
= be16_to_cpu(sys_info
->unit_size
);
1202 mutex_lock(&mspro_block_disk_lock
);
1203 disk_id
= idr_alloc(&mspro_block_disk_idr
, card
, 0, 256, GFP_KERNEL
);
1204 mutex_unlock(&mspro_block_disk_lock
);
1208 msb
->disk
= alloc_disk(1 << MSPRO_BLOCK_PART_SHIFT
);
1211 goto out_release_id
;
1214 msb
->queue
= blk_mq_init_sq_queue(&msb
->tag_set
, &mspro_mq_ops
, 2,
1215 BLK_MQ_F_SHOULD_MERGE
);
1216 if (IS_ERR(msb
->queue
)) {
1217 rc
= PTR_ERR(msb
->queue
);
1222 msb
->queue
->queuedata
= card
;
1224 blk_queue_max_hw_sectors(msb
->queue
, MSPRO_BLOCK_MAX_PAGES
);
1225 blk_queue_max_segments(msb
->queue
, MSPRO_BLOCK_MAX_SEGS
);
1226 blk_queue_max_segment_size(msb
->queue
,
1227 MSPRO_BLOCK_MAX_PAGES
* msb
->page_size
);
1229 msb
->disk
->major
= major
;
1230 msb
->disk
->first_minor
= disk_id
<< MSPRO_BLOCK_PART_SHIFT
;
1231 msb
->disk
->fops
= &ms_block_bdops
;
1232 msb
->usage_count
= 1;
1233 msb
->disk
->private_data
= msb
;
1234 msb
->disk
->queue
= msb
->queue
;
1236 sprintf(msb
->disk
->disk_name
, "mspblk%d", disk_id
);
1238 blk_queue_logical_block_size(msb
->queue
, msb
->page_size
);
1240 capacity
= be16_to_cpu(sys_info
->user_block_count
);
1241 capacity
*= be16_to_cpu(sys_info
->block_size
);
1242 capacity
*= msb
->page_size
>> 9;
1243 set_capacity(msb
->disk
, capacity
);
1244 dev_dbg(&card
->dev
, "capacity set %ld\n", capacity
);
1246 device_add_disk(&card
->dev
, msb
->disk
, NULL
);
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
);
1294 spin_lock_init(&msb
->q_lock
);
1296 rc
= mspro_block_init_card(card
);
1301 rc
= sysfs_create_group(&card
->dev
.kobj
, &msb
->attr_group
);
1305 rc
= mspro_block_init_disk(card
);
1307 card
->check
= mspro_block_check_card
;
1308 card
->stop
= mspro_block_stop
;
1309 card
->start
= mspro_block_start
;
1313 sysfs_remove_group(&card
->dev
.kobj
, &msb
->attr_group
);
1315 memstick_set_drvdata(card
, NULL
);
1316 mspro_block_data_clear(msb
);
1321 static void mspro_block_remove(struct memstick_dev
*card
)
1323 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1324 unsigned long flags
;
1326 spin_lock_irqsave(&msb
->q_lock
, flags
);
1328 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
1329 blk_mq_start_hw_queues(msb
->queue
);
1331 del_gendisk(msb
->disk
);
1332 dev_dbg(&card
->dev
, "mspro block remove\n");
1334 blk_cleanup_queue(msb
->queue
);
1335 blk_mq_free_tag_set(&msb
->tag_set
);
1338 sysfs_remove_group(&card
->dev
.kobj
, &msb
->attr_group
);
1340 mutex_lock(&mspro_block_disk_lock
);
1341 mspro_block_data_clear(msb
);
1342 mutex_unlock(&mspro_block_disk_lock
);
1344 mspro_block_disk_release(msb
->disk
);
1345 memstick_set_drvdata(card
, NULL
);
1350 static int mspro_block_suspend(struct memstick_dev
*card
, pm_message_t state
)
1352 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1353 unsigned long flags
;
1355 blk_mq_stop_hw_queues(msb
->queue
);
1357 spin_lock_irqsave(&msb
->q_lock
, flags
);
1359 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
1364 static int mspro_block_resume(struct memstick_dev
*card
)
1366 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1369 #ifdef CONFIG_MEMSTICK_UNSAFE_RESUME
1371 struct mspro_block_data
*new_msb
;
1372 struct memstick_host
*host
= card
->host
;
1373 struct mspro_sys_attr
*s_attr
, *r_attr
;
1376 mutex_lock(&host
->lock
);
1377 new_msb
= kzalloc(sizeof(struct mspro_block_data
), GFP_KERNEL
);
1383 new_msb
->card
= card
;
1384 memstick_set_drvdata(card
, new_msb
);
1385 if (mspro_block_init_card(card
))
1388 for (cnt
= 0; new_msb
->attr_group
.attrs
[cnt
]
1389 && msb
->attr_group
.attrs
[cnt
]; ++cnt
) {
1390 s_attr
= mspro_from_sysfs_attr(new_msb
->attr_group
.attrs
[cnt
]);
1391 r_attr
= mspro_from_sysfs_attr(msb
->attr_group
.attrs
[cnt
]);
1393 if (s_attr
->id
== MSPRO_BLOCK_ID_SYSINFO
1394 && r_attr
->id
== s_attr
->id
) {
1395 if (memcmp(s_attr
->data
, r_attr
->data
, s_attr
->size
))
1404 memstick_set_drvdata(card
, msb
);
1405 mspro_block_data_clear(new_msb
);
1408 mutex_unlock(&host
->lock
);
1410 #endif /* CONFIG_MEMSTICK_UNSAFE_RESUME */
1412 blk_mq_start_hw_queues(msb
->queue
);
1418 #define mspro_block_suspend NULL
1419 #define mspro_block_resume NULL
1421 #endif /* CONFIG_PM */
1423 static struct memstick_device_id mspro_block_id_tbl
[] = {
1424 {MEMSTICK_MATCH_ALL
, MEMSTICK_TYPE_PRO
, MEMSTICK_CATEGORY_STORAGE_DUO
,
1425 MEMSTICK_CLASS_DUO
},
1430 static struct memstick_driver mspro_block_driver
= {
1432 .name
= DRIVER_NAME
,
1433 .owner
= THIS_MODULE
1435 .id_table
= mspro_block_id_tbl
,
1436 .probe
= mspro_block_probe
,
1437 .remove
= mspro_block_remove
,
1438 .suspend
= mspro_block_suspend
,
1439 .resume
= mspro_block_resume
1442 static int __init
mspro_block_init(void)
1446 rc
= register_blkdev(major
, DRIVER_NAME
);
1448 printk(KERN_ERR DRIVER_NAME
": failed to register "
1449 "major %d, error %d\n", major
, rc
);
1455 rc
= memstick_register_driver(&mspro_block_driver
);
1457 unregister_blkdev(major
, DRIVER_NAME
);
1461 static void __exit
mspro_block_exit(void)
1463 memstick_unregister_driver(&mspro_block_driver
);
1464 unregister_blkdev(major
, DRIVER_NAME
);
1465 idr_destroy(&mspro_block_disk_idr
);
1468 module_init(mspro_block_init
);
1469 module_exit(mspro_block_exit
);
1471 MODULE_LICENSE("GPL");
1472 MODULE_AUTHOR("Alex Dubov");
1473 MODULE_DESCRIPTION("Sony MemoryStickPro block device driver");
1474 MODULE_DEVICE_TABLE(memstick
, mspro_block_id_tbl
);