1 /* Driver for Realtek RTS51xx USB card reader
3 * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2, or (at your option) any
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, see <http://www.gnu.org/licenses/>.
19 * wwang (wei_wang@realsil.com.cn)
20 * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
22 * Edwin Rong (edwin_rong@realsil.com.cn)
23 * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
26 #include <linux/blkdev.h>
27 #include <linux/kthread.h>
28 #include <linux/sched.h>
29 #include <linux/slab.h>
30 #include <linux/vmalloc.h>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_eh.h>
34 #include <scsi/scsi_device.h>
38 #include "rts51x_chip.h"
39 #include "rts51x_scsi.h"
40 #include "rts51x_card.h"
41 #include "rts51x_transport.h"
42 #include "rts51x_sys.h"
47 void scsi_show_command(struct scsi_cmnd
*srb
)
50 int i
, unknown_cmd
= 0;
52 switch (srb
->cmnd
[0]) {
54 what
= (char *)"TEST_UNIT_READY";
57 what
= (char *)"REZERO_UNIT";
60 what
= (char *)"REQUEST_SENSE";
63 what
= (char *)"FORMAT_UNIT";
65 case READ_BLOCK_LIMITS
:
66 what
= (char *)"READ_BLOCK_LIMITS";
69 what
= (char *)"REASSIGN_BLOCKS";
72 what
= (char *)"READ_6";
75 what
= (char *)"WRITE_6";
78 what
= (char *)"SEEK_6";
81 what
= (char *)"READ_REVERSE";
84 what
= (char *)"WRITE_FILEMARKS";
87 what
= (char *)"SPACE";
90 what
= (char *)"INQUIRY";
92 case RECOVER_BUFFERED_DATA
:
93 what
= (char *)"RECOVER_BUFFERED_DATA";
96 what
= (char *)"MODE_SELECT";
99 what
= (char *)"RESERVE";
102 what
= (char *)"RELEASE";
105 what
= (char *)"COPY";
108 what
= (char *)"ERASE";
111 what
= (char *)"MODE_SENSE";
114 what
= (char *)"START_STOP";
116 case RECEIVE_DIAGNOSTIC
:
117 what
= (char *)"RECEIVE_DIAGNOSTIC";
119 case SEND_DIAGNOSTIC
:
120 what
= (char *)"SEND_DIAGNOSTIC";
122 case ALLOW_MEDIUM_REMOVAL
:
123 what
= (char *)"ALLOW_MEDIUM_REMOVAL";
126 what
= (char *)"SET_WINDOW";
129 what
= (char *)"READ_CAPACITY";
132 what
= (char *)"READ_10";
135 what
= (char *)"WRITE_10";
138 what
= (char *)"SEEK_10";
141 what
= (char *)"WRITE_VERIFY";
144 what
= (char *)"VERIFY";
147 what
= (char *)"SEARCH_HIGH";
150 what
= (char *)"SEARCH_EQUAL";
153 what
= (char *)"SEARCH_LOW";
156 what
= (char *)"SET_LIMITS";
159 what
= (char *)"READ_POSITION";
161 case SYNCHRONIZE_CACHE
:
162 what
= (char *)"SYNCHRONIZE_CACHE";
164 case LOCK_UNLOCK_CACHE
:
165 what
= (char *)"LOCK_UNLOCK_CACHE";
167 case READ_DEFECT_DATA
:
168 what
= (char *)"READ_DEFECT_DATA";
171 what
= (char *)"MEDIUM_SCAN";
174 what
= (char *)"COMPARE";
177 what
= (char *)"COPY_VERIFY";
180 what
= (char *)"WRITE_BUFFER";
183 what
= (char *)"READ_BUFFER";
186 what
= (char *)"UPDATE_BLOCK";
189 what
= (char *)"READ_LONG";
192 what
= (char *)"WRITE_LONG";
194 case CHANGE_DEFINITION
:
195 what
= (char *)"CHANGE_DEFINITION";
198 what
= (char *)"WRITE_SAME";
200 case GPCMD_READ_SUBCHANNEL
:
201 what
= (char *)"READ SUBCHANNEL";
204 what
= (char *)"READ_TOC";
206 case GPCMD_READ_HEADER
:
207 what
= (char *)"READ HEADER";
209 case GPCMD_PLAY_AUDIO_10
:
210 what
= (char *)"PLAY AUDIO (10)";
212 case GPCMD_PLAY_AUDIO_MSF
:
213 what
= (char *)"PLAY AUDIO MSF";
215 case GPCMD_GET_EVENT_STATUS_NOTIFICATION
:
216 what
= (char *)"GET EVENT/STATUS NOTIFICATION";
218 case GPCMD_PAUSE_RESUME
:
219 what
= (char *)"PAUSE/RESUME";
222 what
= (char *)"LOG_SELECT";
225 what
= (char *)"LOG_SENSE";
227 case GPCMD_STOP_PLAY_SCAN
:
228 what
= (char *)"STOP PLAY/SCAN";
230 case GPCMD_READ_DISC_INFO
:
231 what
= (char *)"READ DISC INFORMATION";
233 case GPCMD_READ_TRACK_RZONE_INFO
:
234 what
= (char *)"READ TRACK INFORMATION";
236 case GPCMD_RESERVE_RZONE_TRACK
:
237 what
= (char *)"RESERVE TRACK";
240 what
= (char *)"SEND OPC";
243 what
= (char *)"MODE_SELECT_10";
245 case GPCMD_REPAIR_RZONE_TRACK
:
246 what
= (char *)"REPAIR TRACK";
249 what
= (char *)"READ MASTER CUE";
252 what
= (char *)"MODE_SENSE_10";
254 case GPCMD_CLOSE_TRACK
:
255 what
= (char *)"CLOSE TRACK/SESSION";
258 what
= (char *)"READ BUFFER CAPACITY";
261 what
= (char *)"SEND CUE SHEET";
264 what
= (char *)"BLANK";
267 what
= (char *)"REPORT LUNS";
270 what
= (char *)"MOVE_MEDIUM or PLAY AUDIO (12)";
273 what
= (char *)"READ_12";
276 what
= (char *)"WRITE_12";
278 case WRITE_VERIFY_12
:
279 what
= (char *)"WRITE_VERIFY_12";
282 what
= (char *)"SEARCH_HIGH_12";
284 case SEARCH_EQUAL_12
:
285 what
= (char *)"SEARCH_EQUAL_12";
288 what
= (char *)"SEARCH_LOW_12";
290 case SEND_VOLUME_TAG
:
291 what
= (char *)"SEND_VOLUME_TAG";
293 case READ_ELEMENT_STATUS
:
294 what
= (char *)"READ_ELEMENT_STATUS";
296 case GPCMD_READ_CD_MSF
:
297 what
= (char *)"READ CD MSF";
300 what
= (char *)"SCAN";
302 case GPCMD_SET_SPEED
:
303 what
= (char *)"SET CD SPEED";
305 case GPCMD_MECHANISM_STATUS
:
306 what
= (char *)"MECHANISM STATUS";
309 what
= (char *)"READ CD";
312 what
= (char *)"WRITE CONTINUE";
315 what
= (char *)"WRITE_LONG_2";
318 what
= (char *)"Realtek's vendor command";
321 what
= (char *)"(unknown command)";
326 if (srb
->cmnd
[0] != TEST_UNIT_READY
)
327 RTS51X_DEBUGP("Command %s (%d bytes)\n", what
, srb
->cmd_len
);
330 for (i
= 0; i
< srb
->cmd_len
&& i
< 16; i
++)
331 RTS51X_DEBUGPN(" %02x", srb
->cmnd
[i
]);
332 RTS51X_DEBUGPN("\n");
336 void set_sense_type(struct rts51x_chip
*chip
, unsigned int lun
, int sense_type
)
338 switch (sense_type
) {
339 case SENSE_TYPE_MEDIA_CHANGE
:
340 set_sense_data(chip
, lun
, CUR_ERR
, 0x06, 0, 0x28, 0, 0, 0);
343 case SENSE_TYPE_MEDIA_NOT_PRESENT
:
344 set_sense_data(chip
, lun
, CUR_ERR
, 0x02, 0, 0x3A, 0, 0, 0);
347 case SENSE_TYPE_MEDIA_LBA_OVER_RANGE
:
348 set_sense_data(chip
, lun
, CUR_ERR
, 0x05, 0, 0x21, 0, 0, 0);
351 case SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT
:
352 set_sense_data(chip
, lun
, CUR_ERR
, 0x05, 0, 0x25, 0, 0, 0);
355 case SENSE_TYPE_MEDIA_WRITE_PROTECT
:
356 set_sense_data(chip
, lun
, CUR_ERR
, 0x07, 0, 0x27, 0, 0, 0);
359 case SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR
:
360 set_sense_data(chip
, lun
, CUR_ERR
, 0x03, 0, 0x11, 0, 0, 0);
363 case SENSE_TYPE_MEDIA_WRITE_ERR
:
364 set_sense_data(chip
, lun
, CUR_ERR
, 0x03, 0, 0x0C, 0x02, 0, 0);
367 case SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
:
368 set_sense_data(chip
, lun
, CUR_ERR
, ILGAL_REQ
, 0,
369 ASC_INVLD_CDB
, ASCQ_INVLD_CDB
, CDB_ILLEGAL
, 1);
372 case SENSE_TYPE_FORMAT_IN_PROGRESS
:
373 set_sense_data(chip
, lun
, CUR_ERR
, 0x02, 0, 0x04, 0x04, 0, 0);
376 case SENSE_TYPE_FORMAT_CMD_FAILED
:
377 set_sense_data(chip
, lun
, CUR_ERR
, 0x03, 0, 0x31, 0x01, 0, 0);
380 #ifdef SUPPORT_MAGIC_GATE
381 case SENSE_TYPE_MG_KEY_FAIL_NOT_ESTAB
:
382 set_sense_data(chip
, lun
, CUR_ERR
, 0x05, 0, 0x6F, 0x02, 0, 0);
385 case SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN
:
386 set_sense_data(chip
, lun
, CUR_ERR
, 0x05, 0, 0x6F, 0x00, 0, 0);
389 case SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM
:
390 set_sense_data(chip
, lun
, CUR_ERR
, 0x02, 0, 0x30, 0x00, 0, 0);
393 case SENSE_TYPE_MG_WRITE_ERR
:
394 set_sense_data(chip
, lun
, CUR_ERR
, 0x03, 0, 0x0C, 0x00, 0, 0);
398 #ifdef SUPPORT_SD_LOCK
399 case SENSE_TYPE_MEDIA_READ_FORBIDDEN
:
400 set_sense_data(chip
, lun
, CUR_ERR
, 0x07, 0, 0x11, 0x13, 0, 0);
404 case SENSE_TYPE_NO_SENSE
:
406 set_sense_data(chip
, lun
, CUR_ERR
, 0, 0, 0, 0, 0, 0);
411 void set_sense_data(struct rts51x_chip
*chip
, unsigned int lun
, u8 err_code
,
412 u8 sense_key
, u32 info
, u8 asc
, u8 ascq
, u8 sns_key_info0
,
415 struct sense_data_t
*sense
= &(chip
->sense_buffer
[lun
]);
417 sense
->err_code
= err_code
;
418 sense
->sense_key
= sense_key
;
419 sense
->info
[0] = (u8
) (info
>> 24);
420 sense
->info
[1] = (u8
) (info
>> 16);
421 sense
->info
[2] = (u8
) (info
>> 8);
422 sense
->info
[3] = (u8
) info
;
424 sense
->ad_sense_len
= sizeof(struct sense_data_t
) - 8;
427 if (sns_key_info0
!= 0) {
428 sense
->sns_key_info
[0] = SKSV
| sns_key_info0
;
429 sense
->sns_key_info
[1] = (sns_key_info1
& 0xf0) >> 8;
430 sense
->sns_key_info
[2] = sns_key_info1
& 0x0f;
434 static int test_unit_ready(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
436 unsigned int lun
= SCSI_LUN(srb
);
438 rts51x_init_cards(chip
);
440 if (!check_card_ready(chip
, lun
)) {
441 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
442 return TRANSPORT_FAILED
;
445 if (!check_lun_mc(chip
, lun
)) {
446 set_lun_mc(chip
, lun
);
447 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_CHANGE
);
448 return TRANSPORT_FAILED
;
450 #ifdef SUPPORT_SD_LOCK
451 if (get_lun_card(chip
, SCSI_LUN(srb
)) == SD_CARD
) {
452 struct sd_info
*sd_card
= &(chip
->sd_card
);
453 if (sd_card
->sd_lock_notify
) {
454 sd_card
->sd_lock_notify
= 0;
455 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_CHANGE
);
456 return TRANSPORT_FAILED
;
457 } else if (sd_card
->sd_lock_status
& SD_LOCKED
) {
458 set_sense_type(chip
, lun
,
459 SENSE_TYPE_MEDIA_READ_FORBIDDEN
);
460 return TRANSPORT_FAILED
;
465 return TRANSPORT_GOOD
;
468 unsigned char formatter_inquiry_str
[20] = {
469 'M', 'E', 'M', 'O', 'R', 'Y', 'S', 'T', 'I', 'C', 'K',
470 '-', 'M', 'G', /* Byte[47:49] */
471 0x0B, /* Byte[50]: MG, MS, MSPro, MSXC */
472 0x00, /* Byte[51]: Category Specific Commands */
473 0x00, /* Byte[52]: Access Control and feature */
474 0x20, 0x20, 0x20, /* Byte[53:55] */
477 static int inquiry(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
479 unsigned int lun
= SCSI_LUN(srb
);
480 char *inquiry_default
= (char *)"Generic-xD/SD/M.S. 1.00 ";
481 char *inquiry_string
;
482 unsigned char sendbytes
;
484 u8 card
= get_lun_card(chip
, lun
);
485 int pro_formatter_flag
= 0;
486 unsigned char inquiry_buf
[] = {
487 QULIFIRE
| DRCT_ACCESS_DEV
,
494 REL_ADR
| WBUS_32
| WBUS_16
| SYNC
| LINKED
| CMD_QUE
| SFT_RE
,
497 inquiry_string
= inquiry_default
;
499 buf
= vmalloc(scsi_bufflen(srb
));
501 TRACE_RET(chip
, TRANSPORT_ERROR
);
503 if (MS_FORMATTER_ENABLED(chip
) && (get_lun2card(chip
, lun
) & MS_CARD
)) {
504 if (!card
|| (card
== MS_CARD
))
505 pro_formatter_flag
= 1;
508 if (pro_formatter_flag
) {
509 if (scsi_bufflen(srb
) < 56)
510 sendbytes
= (unsigned char)(scsi_bufflen(srb
));
514 if (scsi_bufflen(srb
) < 36)
515 sendbytes
= (unsigned char)(scsi_bufflen(srb
));
521 memcpy(buf
, inquiry_buf
, 8);
522 memcpy(buf
+ 8, inquiry_string
, sendbytes
- 8);
523 if (pro_formatter_flag
)
524 buf
[4] = 0x33; /* Additional Length */
526 memcpy(buf
, inquiry_buf
, sendbytes
);
529 if (pro_formatter_flag
) {
531 memcpy(buf
+ 36, formatter_inquiry_str
, sendbytes
- 36);
534 scsi_set_resid(srb
, 0);
536 rts51x_set_xfer_buf(buf
, scsi_bufflen(srb
), srb
);
539 return TRANSPORT_GOOD
;
542 static int start_stop_unit(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
544 unsigned int lun
= SCSI_LUN(srb
);
546 scsi_set_resid(srb
, scsi_bufflen(srb
));
548 if (srb
->cmnd
[1] == 1)
549 return TRANSPORT_GOOD
;
551 switch (srb
->cmnd
[0x4]) {
554 return TRANSPORT_GOOD
;
557 /* Media shall be unload */
558 if (check_card_ready(chip
, lun
))
559 eject_card(chip
, lun
);
560 return TRANSPORT_GOOD
;
562 case MAKE_MEDIUM_READY
:
564 if (check_card_ready(chip
, lun
)) {
565 return TRANSPORT_GOOD
;
567 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
568 TRACE_RET(chip
, TRANSPORT_FAILED
);
574 TRACE_RET(chip
, TRANSPORT_ERROR
);
577 static int allow_medium_removal(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
581 prevent
= srb
->cmnd
[4] & 0x1;
583 scsi_set_resid(srb
, 0);
586 set_sense_type(chip
, SCSI_LUN(srb
),
587 SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
588 TRACE_RET(chip
, TRANSPORT_FAILED
);
591 return TRANSPORT_GOOD
;
594 static void ms_mode_sense(struct rts51x_chip
*chip
, u8 cmd
,
595 int lun
, u8
*buf
, int buf_len
)
597 struct ms_info
*ms_card
= &(chip
->ms_card
);
599 int data_size
= buf_len
;
600 int support_format
= 0;
603 if (cmd
== MODE_SENSE
) {
605 if (data_size
> 0x68)
607 buf
[i
++] = 0x67; /* Mode Data Length */
609 sys_info_offset
= 12;
610 if (data_size
> 0x6C)
612 buf
[i
++] = 0x00; /* Mode Data Length (MSB) */
613 buf
[i
++] = 0x6A; /* Mode Data Length (LSB) */
616 /* Medium Type Code */
617 if (check_card_ready(chip
, lun
)) {
618 if (CHK_MSXC(ms_card
)) {
621 } else if (CHK_MSPRO(ms_card
)) {
629 if (check_card_wp(chip
, lun
))
634 buf
[i
++] = 0x00; /* MediaType */
635 buf
[i
++] = 0x00; /* WP */
638 buf
[i
++] = 0x00; /* Reserved */
640 if (cmd
== MODE_SENSE_10
) {
641 buf
[i
++] = 0x00; /* Reserved */
642 buf
[i
++] = 0x00; /* Block descriptor length(MSB) */
643 buf
[i
++] = 0x00; /* Block descriptor length(LSB) */
645 /* The Following Data is the content of "Page 0x20" */
647 buf
[i
++] = 0x20; /* Page Code */
649 buf
[i
++] = 0x62; /* Page Length */
651 buf
[i
++] = 0x00; /* No Access Control */
652 if (data_size
>= 12) {
654 buf
[i
++] = 0xC0; /* SF, SGM */
659 /* The Following Data is the content of "Page 0x20" */
661 buf
[i
++] = 0x20; /* Page Code */
663 buf
[i
++] = 0x62; /* Page Length */
665 buf
[i
++] = 0x00; /* No Access Control */
666 if (data_size
>= 8) {
668 buf
[i
++] = 0xC0; /* SF, SGM */
674 if (data_size
> sys_info_offset
) {
675 /* 96 Bytes Attribute Data */
676 int len
= data_size
- sys_info_offset
;
677 len
= (len
< 96) ? len
: 96;
679 memcpy(buf
+ sys_info_offset
, ms_card
->raw_sys_info
, len
);
683 static int mode_sense(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
685 unsigned int lun
= SCSI_LUN(srb
);
686 unsigned int dataSize
;
688 int pro_formatter_flag
;
689 unsigned char pageCode
, *buf
;
690 u8 card
= get_lun_card(chip
, lun
);
692 if (!check_card_ready(chip
, lun
)) {
693 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
694 scsi_set_resid(srb
, scsi_bufflen(srb
));
695 TRACE_RET(chip
, TRANSPORT_FAILED
);
698 pro_formatter_flag
= 0;
700 /* In Combo mode, device responses ModeSense command as a MS LUN
701 * when no card is inserted */
702 if ((get_lun2card(chip
, lun
) & MS_CARD
)) {
703 if (!card
|| (card
== MS_CARD
)) {
705 if (chip
->option
.mspro_formatter_enable
)
706 pro_formatter_flag
= 1;
710 buf
= kmalloc(dataSize
, GFP_KERNEL
);
712 TRACE_RET(chip
, TRANSPORT_ERROR
);
714 pageCode
= srb
->cmnd
[2] & 0x3f;
716 if ((pageCode
== 0x3F) || (pageCode
== 0x1C) ||
717 (pageCode
== 0x00) || (pro_formatter_flag
&& (pageCode
== 0x20))) {
718 if (srb
->cmnd
[0] == MODE_SENSE
) {
719 if ((pageCode
== 0x3F) || (pageCode
== 0x20)) {
720 ms_mode_sense(chip
, srb
->cmnd
[0], lun
, buf
,
726 if (check_card_wp(chip
, lun
))
732 if ((pageCode
== 0x3F) || (pageCode
== 0x20)) {
733 ms_mode_sense(chip
, srb
->cmnd
[0], lun
, buf
,
740 if (check_card_wp(chip
, lun
))
750 status
= TRANSPORT_GOOD
;
752 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
753 scsi_set_resid(srb
, scsi_bufflen(srb
));
754 status
= TRANSPORT_FAILED
;
757 if (status
== TRANSPORT_GOOD
) {
758 unsigned int len
= min(scsi_bufflen(srb
), dataSize
);
759 rts51x_set_xfer_buf(buf
, len
, srb
);
760 scsi_set_resid(srb
, scsi_bufflen(srb
) - len
);
767 static int request_sense(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
769 struct sense_data_t
*sense
;
770 unsigned int lun
= SCSI_LUN(srb
);
771 struct ms_info
*ms_card
= &(chip
->ms_card
);
772 unsigned char *tmp
, *buf
;
774 sense
= &(chip
->sense_buffer
[lun
]);
776 if ((get_lun_card(chip
, lun
) == MS_CARD
)
777 && PRO_UNDER_FORMATTING(ms_card
)) {
778 mspro_format_sense(chip
, lun
);
781 buf
= vmalloc(scsi_bufflen(srb
));
783 TRACE_RET(chip
, TRANSPORT_ERROR
);
785 tmp
= (unsigned char *)sense
;
786 memcpy(buf
, tmp
, scsi_bufflen(srb
));
788 rts51x_set_xfer_buf(buf
, scsi_bufflen(srb
), srb
);
791 scsi_set_resid(srb
, 0);
792 /* Reset Sense Data */
793 set_sense_type(chip
, lun
, SENSE_TYPE_NO_SENSE
);
794 return TRANSPORT_GOOD
;
797 static int read_write(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
799 #ifdef SUPPORT_SD_LOCK
800 struct sd_info
*sd_card
= &(chip
->sd_card
);
802 unsigned int lun
= SCSI_LUN(srb
);
807 if (!check_card_ready(chip
, lun
) || (chip
->capacity
[lun
] == 0)) {
808 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
809 TRACE_RET(chip
, TRANSPORT_FAILED
);
812 if (!check_lun_mc(chip
, lun
)) {
813 set_lun_mc(chip
, lun
);
814 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_CHANGE
);
815 return TRANSPORT_FAILED
;
818 rts51x_prepare_run(chip
);
819 RTS51X_SET_STAT(chip
, STAT_RUN
);
821 #ifdef SUPPORT_SD_LOCK
822 if (sd_card
->sd_erase_status
) {
823 /* Accessing to any card is forbidden
824 * until the erase procedure of SD is completed */
825 RTS51X_DEBUGP("SD card being erased!\n");
826 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_READ_FORBIDDEN
);
827 TRACE_RET(chip
, TRANSPORT_FAILED
);
830 if (get_lun_card(chip
, lun
) == SD_CARD
) {
831 if (sd_card
->sd_lock_status
& SD_LOCKED
) {
832 RTS51X_DEBUGP("SD card locked!\n");
833 set_sense_type(chip
, lun
,
834 SENSE_TYPE_MEDIA_READ_FORBIDDEN
);
835 TRACE_RET(chip
, TRANSPORT_FAILED
);
840 if ((srb
->cmnd
[0] == READ_10
) || (srb
->cmnd
[0] == WRITE_10
)) {
842 ((u32
) srb
->cmnd
[2] << 24) |
843 ((u32
) srb
->cmnd
[3] << 16) |
844 ((u32
) srb
->cmnd
[4] << 8) |
845 ((u32
) srb
->cmnd
[5]);
846 sec_cnt
= ((u16
) (srb
->cmnd
[7]) << 8) | srb
->cmnd
[8];
847 } else if ((srb
->cmnd
[0] == READ_6
) || (srb
->cmnd
[0] == WRITE_6
)) {
848 start_sec
= ((u32
) (srb
->cmnd
[1] & 0x1F) << 16) |
849 ((u32
) srb
->cmnd
[2] << 8) | ((u32
) srb
->cmnd
[3]);
850 sec_cnt
= srb
->cmnd
[4];
851 } else if ((srb
->cmnd
[0] == VENDOR_CMND
) &&
852 (srb
->cmnd
[1] == SCSI_APP_CMD
) &&
853 ((srb
->cmnd
[2] == PP_READ10
) ||
854 (srb
->cmnd
[2] == PP_WRITE10
))) {
855 start_sec
= ((u32
) srb
->cmnd
[4] << 24) |
856 ((u32
) srb
->cmnd
[5] << 16) |
857 ((u32
) srb
->cmnd
[6] << 8) |
858 ((u32
) srb
->cmnd
[7]);
859 sec_cnt
= ((u16
) (srb
->cmnd
[9]) << 8) | srb
->cmnd
[10];
861 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
862 TRACE_RET(chip
, TRANSPORT_FAILED
);
865 if ((start_sec
> chip
->capacity
[lun
]) ||
866 ((start_sec
+ sec_cnt
) > chip
->capacity
[lun
])) {
867 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_LBA_OVER_RANGE
);
868 TRACE_RET(chip
, TRANSPORT_FAILED
);
872 scsi_set_resid(srb
, 0);
873 return TRANSPORT_GOOD
;
876 if ((srb
->sc_data_direction
== DMA_TO_DEVICE
)
877 && check_card_wp(chip
, lun
)) {
878 RTS51X_DEBUGP("Write protected card!\n");
879 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_WRITE_PROTECT
);
880 TRACE_RET(chip
, TRANSPORT_FAILED
);
883 retval
= card_rw(srb
, chip
, start_sec
, sec_cnt
);
884 if (retval
!= STATUS_SUCCESS
) {
886 if (chip
->need_release
& chip
->lun2card
[lun
]) {
887 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
890 if (srb
->sc_data_direction
== DMA_FROM_DEVICE
) {
891 set_sense_type(chip
, lun
,
892 SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR
);
894 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_WRITE_ERR
);
899 TRACE_RET(chip
, TRANSPORT_FAILED
);
902 scsi_set_resid(srb
, 0);
904 return TRANSPORT_GOOD
;
907 static int read_format_capacity(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
910 unsigned int lun
= SCSI_LUN(srb
);
911 unsigned int buf_len
;
912 u8 card
= get_lun_card(chip
, lun
);
916 if (!check_card_ready(chip
, lun
)) {
917 if (!chip
->option
.mspro_formatter_enable
) {
918 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
919 TRACE_RET(chip
, TRANSPORT_FAILED
);
923 buf_len
= (scsi_bufflen(srb
) > 12) ? 0x14 : 12;
925 buf
= kmalloc(buf_len
, GFP_KERNEL
);
927 TRACE_RET(chip
, TRANSPORT_ERROR
);
933 /* Capacity List Length */
934 if ((buf_len
> 12) && chip
->option
.mspro_formatter_enable
&&
935 (chip
->lun2card
[lun
] & MS_CARD
) && (!card
|| (card
== MS_CARD
))) {
944 if (check_card_ready(chip
, lun
)) {
945 buf
[i
++] = (unsigned char)((chip
->capacity
[lun
]) >> 24);
946 buf
[i
++] = (unsigned char)((chip
->capacity
[lun
]) >> 16);
947 buf
[i
++] = (unsigned char)((chip
->capacity
[lun
]) >> 8);
948 buf
[i
++] = (unsigned char)(chip
->capacity
[lun
]);
951 /* Byte[8]: Descriptor Type: Formatted medium */
954 buf
[i
++] = 0; /* Byte[16] */
962 /* Byte[8]: Descriptor Type: No medium */
965 buf
[i
++] = 0; /*Byte[16] */
975 buf_len
= min(scsi_bufflen(srb
), buf_len
);
976 rts51x_set_xfer_buf(buf
, buf_len
, srb
);
979 scsi_set_resid(srb
, scsi_bufflen(srb
) - buf_len
);
981 return TRANSPORT_GOOD
;
984 static int read_capacity(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
987 unsigned int lun
= SCSI_LUN(srb
);
989 if (!check_card_ready(chip
, lun
)) {
990 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
991 TRACE_RET(chip
, TRANSPORT_FAILED
);
994 if (!check_lun_mc(chip
, lun
)) {
995 set_lun_mc(chip
, lun
);
996 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_CHANGE
);
997 return TRANSPORT_FAILED
;
1000 buf
= kmalloc(8, GFP_KERNEL
);
1002 TRACE_RET(chip
, TRANSPORT_ERROR
);
1004 buf
[0] = (unsigned char)((chip
->capacity
[lun
] - 1) >> 24);
1005 buf
[1] = (unsigned char)((chip
->capacity
[lun
] - 1) >> 16);
1006 buf
[2] = (unsigned char)((chip
->capacity
[lun
] - 1) >> 8);
1007 buf
[3] = (unsigned char)(chip
->capacity
[lun
] - 1);
1014 rts51x_set_xfer_buf(buf
, scsi_bufflen(srb
), srb
);
1017 scsi_set_resid(srb
, 0);
1019 return TRANSPORT_GOOD
;
1022 static int get_dev_status(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1024 unsigned int lun
= SCSI_LUN(srb
);
1025 unsigned int buf_len
;
1026 u8 status
[32] = { 0 };
1028 rts51x_pp_status(chip
, lun
, status
, 32);
1030 buf_len
= min(scsi_bufflen(srb
), (unsigned int)sizeof(status
));
1031 rts51x_set_xfer_buf(status
, buf_len
, srb
);
1032 scsi_set_resid(srb
, scsi_bufflen(srb
) - buf_len
);
1034 return TRANSPORT_GOOD
;
1037 static int read_status(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1039 u8 rts51x_status
[16];
1040 unsigned int buf_len
;
1041 unsigned int lun
= SCSI_LUN(srb
);
1043 rts51x_read_status(chip
, lun
, rts51x_status
, 16);
1045 buf_len
= min(scsi_bufflen(srb
), (unsigned int)sizeof(rts51x_status
));
1046 rts51x_set_xfer_buf(rts51x_status
, buf_len
, srb
);
1047 scsi_set_resid(srb
, scsi_bufflen(srb
) - buf_len
);
1049 return TRANSPORT_GOOD
;
1052 static int read_mem(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1054 unsigned int lun
= SCSI_LUN(srb
);
1055 unsigned short addr
, len
, i
;
1059 rts51x_prepare_run(chip
);
1060 RTS51X_SET_STAT(chip
, STAT_RUN
);
1062 addr
= ((u16
) srb
->cmnd
[2] << 8) | srb
->cmnd
[3];
1063 len
= ((u16
) srb
->cmnd
[4] << 8) | srb
->cmnd
[5];
1065 if (addr
< 0xe000) {
1066 RTS51X_DEBUGP("filter!addr=0x%x\n", addr
);
1067 return TRANSPORT_GOOD
;
1072 TRACE_RET(chip
, TRANSPORT_ERROR
);
1074 for (i
= 0; i
< len
; i
++) {
1075 retval
= rts51x_ep0_read_register(chip
, addr
+ i
, buf
+ i
);
1076 if (retval
!= STATUS_SUCCESS
) {
1078 set_sense_type(chip
, lun
,
1079 SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR
);
1080 TRACE_RET(chip
, TRANSPORT_FAILED
);
1084 len
= (unsigned short)min(scsi_bufflen(srb
), (unsigned int)len
);
1085 rts51x_set_xfer_buf(buf
, len
, srb
);
1086 scsi_set_resid(srb
, scsi_bufflen(srb
) - len
);
1090 return TRANSPORT_GOOD
;
1093 static int write_mem(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1095 unsigned int lun
= SCSI_LUN(srb
);
1096 unsigned short addr
, len
, i
;
1100 rts51x_prepare_run(chip
);
1101 RTS51X_SET_STAT(chip
, STAT_RUN
);
1103 addr
= ((u16
) srb
->cmnd
[2] << 8) | srb
->cmnd
[3];
1104 len
= ((u16
) srb
->cmnd
[4] << 8) | srb
->cmnd
[5];
1106 if (addr
< 0xe000) {
1107 RTS51X_DEBUGP("filter!addr=0x%x\n", addr
);
1108 return TRANSPORT_GOOD
;
1111 len
= (unsigned short)min(scsi_bufflen(srb
), (unsigned int)len
);
1114 TRACE_RET(chip
, TRANSPORT_ERROR
);
1116 rts51x_get_xfer_buf(buf
, len
, srb
);
1118 for (i
= 0; i
< len
; i
++) {
1120 rts51x_ep0_write_register(chip
, addr
+ i
, 0xFF, buf
[i
]);
1121 if (retval
!= STATUS_SUCCESS
) {
1123 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_WRITE_ERR
);
1124 TRACE_RET(chip
, TRANSPORT_FAILED
);
1129 scsi_set_resid(srb
, scsi_bufflen(srb
) - len
);
1131 return TRANSPORT_GOOD
;
1134 static int get_sd_csd(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1136 struct sd_info
*sd_card
= &(chip
->sd_card
);
1137 unsigned int lun
= SCSI_LUN(srb
);
1139 if (!check_card_ready(chip
, lun
)) {
1140 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
1141 TRACE_RET(chip
, TRANSPORT_FAILED
);
1144 if (get_lun_card(chip
, lun
) != SD_CARD
) {
1145 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR
);
1146 TRACE_RET(chip
, TRANSPORT_FAILED
);
1149 scsi_set_resid(srb
, 0);
1150 rts51x_set_xfer_buf(sd_card
->raw_csd
, scsi_bufflen(srb
), srb
);
1152 return TRANSPORT_GOOD
;
1155 static int read_phy_register(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1161 rts51x_prepare_run(chip
);
1162 RTS51X_SET_STAT(chip
, STAT_RUN
);
1164 addr
= srb
->cmnd
[5];
1170 TRACE_RET(chip
, TRANSPORT_ERROR
);
1172 for (i
= 0; i
< len
; i
++) {
1174 rts51x_read_phy_register(chip
, addr
+ i
, buf
+ i
);
1175 if (retval
!= STATUS_SUCCESS
) {
1177 set_sense_type(chip
, SCSI_LUN(srb
),
1178 SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR
);
1179 TRACE_RET(chip
, TRANSPORT_FAILED
);
1183 len
= min(scsi_bufflen(srb
), (unsigned int)len
);
1184 rts51x_set_xfer_buf(buf
, len
, srb
);
1185 scsi_set_resid(srb
, scsi_bufflen(srb
) - len
);
1190 return TRANSPORT_GOOD
;
1193 static int write_phy_register(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1199 rts51x_prepare_run(chip
);
1200 RTS51X_SET_STAT(chip
, STAT_RUN
);
1202 addr
= srb
->cmnd
[5];
1206 len
= min(scsi_bufflen(srb
), (unsigned int)len
);
1210 TRACE_RET(chip
, TRANSPORT_ERROR
);
1212 rts51x_get_xfer_buf(buf
, len
, srb
);
1213 scsi_set_resid(srb
, scsi_bufflen(srb
) - len
);
1215 for (i
= 0; i
< len
; i
++) {
1217 rts51x_write_phy_register(chip
, addr
+ i
, buf
[i
]);
1218 if (retval
!= STATUS_SUCCESS
) {
1220 set_sense_type(chip
, SCSI_LUN(srb
),
1221 SENSE_TYPE_MEDIA_WRITE_ERR
);
1222 TRACE_RET(chip
, TRANSPORT_FAILED
);
1229 return TRANSPORT_GOOD
;
1232 static int get_card_bus_width(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1234 unsigned int lun
= SCSI_LUN(srb
);
1237 if (!check_card_ready(chip
, lun
)) {
1238 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
1239 TRACE_RET(chip
, TRANSPORT_FAILED
);
1242 card
= get_lun_card(chip
, lun
);
1243 if ((card
== SD_CARD
) || (card
== MS_CARD
)) {
1244 bus_width
= chip
->card_bus_width
[lun
];
1246 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR
);
1247 TRACE_RET(chip
, TRANSPORT_FAILED
);
1250 scsi_set_resid(srb
, 0);
1251 rts51x_set_xfer_buf(&bus_width
, scsi_bufflen(srb
), srb
);
1253 return TRANSPORT_GOOD
;
1257 static int trace_msg_cmd(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1259 unsigned char *buf
= NULL
;
1261 unsigned int buf_len
;
1265 ((2 + MSG_FUNC_LEN
+ MSG_FILE_LEN
+ TIME_VAL_LEN
) * TRACE_ITEM_CNT
);
1267 if ((scsi_bufflen(srb
) < buf_len
) || (scsi_sglist(srb
) == NULL
)) {
1268 set_sense_type(chip
, SCSI_LUN(srb
),
1269 SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR
);
1270 TRACE_RET(chip
, TRANSPORT_FAILED
);
1273 clear
= srb
->cmnd
[2];
1275 buf
= vmalloc(scsi_bufflen(srb
));
1277 TRACE_RET(chip
, TRANSPORT_ERROR
);
1279 rts51x_trace_msg(chip
, buf
, clear
);
1281 rts51x_set_xfer_buf(buf
, scsi_bufflen(srb
), srb
);
1284 scsi_set_resid(srb
, 0);
1285 return TRANSPORT_GOOD
;
1289 static int rw_mem_cmd_buf(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1291 int retval
= STATUS_SUCCESS
;
1292 unsigned int lun
= SCSI_LUN(srb
);
1293 u8 cmd_type
, mask
, value
, idx
, mode
, len
;
1297 rts51x_prepare_run(chip
);
1298 RTS51X_SET_STAT(chip
, STAT_RUN
);
1300 switch (srb
->cmnd
[3]) {
1302 rts51x_init_cmd(chip
);
1306 cmd_type
= srb
->cmnd
[4];
1308 set_sense_type(chip
, lun
,
1309 SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1310 TRACE_RET(chip
, TRANSPORT_FAILED
);
1312 addr
= (srb
->cmnd
[5] << 8) | srb
->cmnd
[6];
1313 mask
= srb
->cmnd
[7];
1314 value
= srb
->cmnd
[8];
1315 rts51x_add_cmd(chip
, cmd_type
, addr
, mask
, value
);
1319 mode
= srb
->cmnd
[4];
1322 ((u32
) srb
->cmnd
[6] << 24) | ((u32
) srb
->
1323 cmnd
[7] << 16) | ((u32
) srb
->
1329 retval
= rts51x_send_cmd(chip
, mode
, 1000);
1330 if (retval
!= STATUS_SUCCESS
) {
1331 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_WRITE_ERR
);
1332 TRACE_RET(chip
, TRANSPORT_FAILED
);
1334 if (mode
& STAGE_R
) {
1335 retval
= rts51x_get_rsp(chip
, len
, timeout
);
1336 if (retval
!= STATUS_SUCCESS
) {
1337 set_sense_type(chip
, lun
,
1338 SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR
);
1339 TRACE_RET(chip
, TRANSPORT_FAILED
);
1346 value
= chip
->rsp_buf
[idx
];
1347 if (scsi_bufflen(srb
) < 1) {
1348 set_sense_type(chip
, lun
,
1349 SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1350 TRACE_RET(chip
, TRANSPORT_FAILED
);
1352 rts51x_set_xfer_buf(&value
, 1, srb
);
1353 scsi_set_resid(srb
, 0);
1357 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1358 TRACE_RET(chip
, TRANSPORT_FAILED
);
1361 if (retval
!= STATUS_SUCCESS
) {
1362 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_WRITE_ERR
);
1363 TRACE_RET(chip
, TRANSPORT_FAILED
);
1366 return TRANSPORT_GOOD
;
1369 static int suit_cmd(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1373 switch (srb
->cmnd
[3]) {
1378 result
= rw_mem_cmd_buf(srb
, chip
);
1381 result
= TRANSPORT_ERROR
;
1387 static int app_cmd(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1391 switch (srb
->cmnd
[2]) {
1394 result
= read_write(srb
, chip
);
1398 result
= suit_cmd(srb
, chip
);
1402 result
= read_phy_register(srb
, chip
);
1406 result
= write_phy_register(srb
, chip
);
1409 case GET_DEV_STATUS
:
1410 result
= get_dev_status(srb
, chip
);
1414 set_sense_type(chip
, SCSI_LUN(srb
),
1415 SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1416 TRACE_RET(chip
, TRANSPORT_FAILED
);
1422 static int vendor_cmnd(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1424 int result
= TRANSPORT_GOOD
;
1426 switch (srb
->cmnd
[1]) {
1428 result
= read_status(srb
, chip
);
1432 result
= read_mem(srb
, chip
);
1436 result
= write_mem(srb
, chip
);
1440 result
= get_card_bus_width(srb
, chip
);
1444 result
= get_sd_csd(srb
, chip
);
1449 result
= trace_msg_cmd(srb
, chip
);
1454 result
= app_cmd(srb
, chip
);
1458 set_sense_type(chip
, SCSI_LUN(srb
),
1459 SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1460 TRACE_RET(chip
, TRANSPORT_FAILED
);
1466 static int ms_format_cmnd(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1468 struct ms_info
*ms_card
= &(chip
->ms_card
);
1469 unsigned int lun
= SCSI_LUN(srb
);
1470 int retval
, quick_format
;
1472 if (get_lun_card(chip
, lun
) != MS_CARD
) {
1473 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT
);
1474 TRACE_RET(chip
, TRANSPORT_FAILED
);
1477 if ((srb
->cmnd
[3] != 0x4D) || (srb
->cmnd
[4] != 0x47)
1478 || (srb
->cmnd
[5] != 0x66) || (srb
->cmnd
[6] != 0x6D)
1479 || (srb
->cmnd
[7] != 0x74)) {
1480 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1481 TRACE_RET(chip
, TRANSPORT_FAILED
);
1484 if (srb
->cmnd
[8] & 0x01)
1489 if (!(chip
->card_ready
& MS_CARD
)) {
1490 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
1491 TRACE_RET(chip
, TRANSPORT_FAILED
);
1494 if (chip
->card_wp
& MS_CARD
) {
1495 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_WRITE_PROTECT
);
1496 TRACE_RET(chip
, TRANSPORT_FAILED
);
1499 if (!CHK_MSPRO(ms_card
)) {
1500 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT
);
1501 TRACE_RET(chip
, TRANSPORT_FAILED
);
1504 rts51x_prepare_run(chip
);
1505 RTS51X_SET_STAT(chip
, STAT_RUN
);
1507 retval
= mspro_format(srb
, chip
, MS_SHORT_DATA_LEN
, quick_format
);
1508 if (retval
!= STATUS_SUCCESS
) {
1509 set_sense_type(chip
, lun
, SENSE_TYPE_FORMAT_CMD_FAILED
);
1510 TRACE_RET(chip
, TRANSPORT_FAILED
);
1513 scsi_set_resid(srb
, 0);
1514 return TRANSPORT_GOOD
;
1517 #ifdef SUPPORT_PCGL_1P18
1518 int get_ms_information(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1520 struct ms_info
*ms_card
= &(chip
->ms_card
);
1521 unsigned int lun
= SCSI_LUN(srb
);
1522 u8 dev_info_id
, data_len
;
1524 unsigned int buf_len
;
1527 if (!check_card_ready(chip
, lun
)) {
1528 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
1529 TRACE_RET(chip
, TRANSPORT_FAILED
);
1531 if ((get_lun_card(chip
, lun
) != MS_CARD
)) {
1532 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT
);
1533 TRACE_RET(chip
, TRANSPORT_FAILED
);
1536 if ((srb
->cmnd
[2] != 0xB0) || (srb
->cmnd
[4] != 0x4D) ||
1537 (srb
->cmnd
[5] != 0x53) || (srb
->cmnd
[6] != 0x49) ||
1538 (srb
->cmnd
[7] != 0x44)) {
1539 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1540 TRACE_RET(chip
, TRANSPORT_FAILED
);
1543 dev_info_id
= srb
->cmnd
[3];
1544 if ((CHK_MSXC(ms_card
) && (dev_info_id
== 0x10)) ||
1545 (!CHK_MSXC(ms_card
) && (dev_info_id
== 0x13)) ||
1546 !CHK_MSPRO(ms_card
)) {
1547 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1548 TRACE_RET(chip
, TRANSPORT_FAILED
);
1551 if (dev_info_id
== 0x15)
1552 buf_len
= data_len
= 0x3A;
1554 buf_len
= data_len
= 0x6A;
1556 buf
= kmalloc(buf_len
, GFP_KERNEL
);
1558 TRACE_RET(chip
, TRANSPORT_ERROR
);
1561 /* GET Memory Stick Media Information Response Header */
1562 buf
[i
++] = 0x00; /* Data length MSB */
1563 buf
[i
++] = data_len
; /* Data length LSB */
1564 /* Device Information Type Code */
1565 if (CHK_MSXC(ms_card
))
1575 /* Number of Device Information */
1578 /* Device Information Body
1579 * Device Information ID Number */
1580 buf
[i
++] = dev_info_id
;
1581 /* Device Information Length */
1582 if (dev_info_id
== 0x15)
1586 buf
[i
++] = 0x00; /* Data length MSB */
1587 buf
[i
++] = data_len
; /* Data length LSB */
1590 if ((dev_info_id
== 0x10) || (dev_info_id
== 0x13)) {
1591 /* System Information */
1592 memcpy(buf
+ i
, ms_card
->raw_sys_info
, 96);
1595 memcpy(buf
+ i
, ms_card
->raw_model_name
, 48);
1598 rts51x_set_xfer_buf(buf
, buf_len
, srb
);
1600 if (dev_info_id
== 0x15)
1601 scsi_set_resid(srb
, scsi_bufflen(srb
) - 0x3C);
1603 scsi_set_resid(srb
, scsi_bufflen(srb
) - 0x6C);
1606 return STATUS_SUCCESS
;
1610 static int ms_sp_cmnd(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1612 int retval
= TRANSPORT_ERROR
;
1614 if (srb
->cmnd
[2] == MS_FORMAT
)
1615 retval
= ms_format_cmnd(srb
, chip
);
1616 #ifdef SUPPORT_PCGL_1P18
1617 else if (srb
->cmnd
[2] == GET_MS_INFORMATION
)
1618 retval
= get_ms_information(srb
, chip
);
1625 static int sd_extention_cmnd(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1627 unsigned int lun
= SCSI_LUN(srb
);
1630 rts51x_prepare_run(chip
);
1631 RTS51X_SET_STAT(chip
, STAT_RUN
);
1633 sd_cleanup_work(chip
);
1635 if (!check_card_ready(chip
, lun
)) {
1636 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
1637 TRACE_RET(chip
, TRANSPORT_FAILED
);
1639 if ((get_lun_card(chip
, lun
) != SD_CARD
)) {
1640 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT
);
1641 TRACE_RET(chip
, TRANSPORT_FAILED
);
1644 switch (srb
->cmnd
[0]) {
1645 case SD_PASS_THRU_MODE
:
1646 result
= sd_pass_thru_mode(srb
, chip
);
1649 case SD_EXECUTE_NO_DATA
:
1650 result
= sd_execute_no_data(srb
, chip
);
1653 case SD_EXECUTE_READ
:
1654 result
= sd_execute_read_data(srb
, chip
);
1657 case SD_EXECUTE_WRITE
:
1658 result
= sd_execute_write_data(srb
, chip
);
1662 result
= sd_get_cmd_rsp(srb
, chip
);
1666 result
= sd_hw_rst(srb
, chip
);
1670 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1671 TRACE_RET(chip
, TRANSPORT_FAILED
);
1678 #ifdef SUPPORT_MAGIC_GATE
1679 int mg_report_key(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1681 struct ms_info
*ms_card
= &(chip
->ms_card
);
1682 unsigned int lun
= SCSI_LUN(srb
);
1686 rts51x_prepare_run(chip
);
1687 RTS51X_SET_STAT(chip
, STAT_RUN
);
1689 ms_cleanup_work(chip
);
1691 if (!check_card_ready(chip
, lun
)) {
1692 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
1693 TRACE_RET(chip
, TRANSPORT_FAILED
);
1695 if ((get_lun_card(chip
, lun
) != MS_CARD
)) {
1696 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT
);
1697 TRACE_RET(chip
, TRANSPORT_FAILED
);
1700 if (srb
->cmnd
[7] != KC_MG_R_PRO
) {
1701 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1702 TRACE_RET(chip
, TRANSPORT_FAILED
);
1705 if (!CHK_MSPRO(ms_card
)) {
1706 set_sense_type(chip
, lun
, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM
);
1707 TRACE_RET(chip
, TRANSPORT_FAILED
);
1710 key_format
= srb
->cmnd
[10] & 0x3F;
1712 switch (key_format
) {
1713 case KF_GET_LOC_EKB
:
1714 if ((scsi_bufflen(srb
) == 0x41C) &&
1715 (srb
->cmnd
[8] == 0x04) && (srb
->cmnd
[9] == 0x1C)) {
1716 retval
= mg_get_local_EKB(srb
, chip
);
1717 if (retval
!= STATUS_SUCCESS
)
1718 TRACE_RET(chip
, TRANSPORT_FAILED
);
1720 set_sense_type(chip
, lun
,
1721 SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1722 TRACE_RET(chip
, TRANSPORT_FAILED
);
1727 if ((scsi_bufflen(srb
) == 0x24) &&
1728 (srb
->cmnd
[8] == 0x00) && (srb
->cmnd
[9] == 0x24)) {
1729 retval
= mg_get_rsp_chg(srb
, chip
);
1730 if (retval
!= STATUS_SUCCESS
)
1731 TRACE_RET(chip
, TRANSPORT_FAILED
);
1733 set_sense_type(chip
, lun
,
1734 SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1735 TRACE_RET(chip
, TRANSPORT_FAILED
);
1740 ms_card
->mg_entry_num
= srb
->cmnd
[5];
1741 if ((scsi_bufflen(srb
) == 0x404) &&
1742 (srb
->cmnd
[8] == 0x04) &&
1743 (srb
->cmnd
[9] == 0x04) &&
1744 (srb
->cmnd
[2] == 0x00) &&
1745 (srb
->cmnd
[3] == 0x00) &&
1746 (srb
->cmnd
[4] == 0x00) && (srb
->cmnd
[5] < 32)) {
1747 retval
= mg_get_ICV(srb
, chip
);
1748 if (retval
!= STATUS_SUCCESS
)
1749 TRACE_RET(chip
, TRANSPORT_FAILED
);
1751 set_sense_type(chip
, lun
,
1752 SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1753 TRACE_RET(chip
, TRANSPORT_FAILED
);
1758 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1759 TRACE_RET(chip
, TRANSPORT_FAILED
);
1762 scsi_set_resid(srb
, 0);
1763 return TRANSPORT_GOOD
;
1766 int mg_send_key(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1768 struct ms_info
*ms_card
= &(chip
->ms_card
);
1769 unsigned int lun
= SCSI_LUN(srb
);
1773 rts51x_prepare_run(chip
);
1774 RTS51X_SET_STAT(chip
, STAT_RUN
);
1776 ms_cleanup_work(chip
);
1778 if (!check_card_ready(chip
, lun
)) {
1779 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
1780 TRACE_RET(chip
, TRANSPORT_FAILED
);
1782 if (check_card_wp(chip
, lun
)) {
1783 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_WRITE_PROTECT
);
1784 TRACE_RET(chip
, TRANSPORT_FAILED
);
1786 if ((get_lun_card(chip
, lun
) != MS_CARD
)) {
1787 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT
);
1788 TRACE_RET(chip
, TRANSPORT_FAILED
);
1791 if (srb
->cmnd
[7] != KC_MG_R_PRO
) {
1792 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1793 TRACE_RET(chip
, TRANSPORT_FAILED
);
1796 if (!CHK_MSPRO(ms_card
)) {
1797 set_sense_type(chip
, lun
, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM
);
1798 TRACE_RET(chip
, TRANSPORT_FAILED
);
1801 key_format
= srb
->cmnd
[10] & 0x3F;
1803 switch (key_format
) {
1804 case KF_SET_LEAF_ID
:
1805 if ((scsi_bufflen(srb
) == 0x0C) &&
1806 (srb
->cmnd
[8] == 0x00) && (srb
->cmnd
[9] == 0x0C)) {
1807 retval
= mg_set_leaf_id(srb
, chip
);
1808 if (retval
!= STATUS_SUCCESS
)
1809 TRACE_RET(chip
, TRANSPORT_FAILED
);
1811 set_sense_type(chip
, lun
,
1812 SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1813 TRACE_RET(chip
, TRANSPORT_FAILED
);
1818 if ((scsi_bufflen(srb
) == 0x0C) &&
1819 (srb
->cmnd
[8] == 0x00) && (srb
->cmnd
[9] == 0x0C)) {
1820 retval
= mg_chg(srb
, chip
);
1821 if (retval
!= STATUS_SUCCESS
)
1822 TRACE_RET(chip
, TRANSPORT_FAILED
);
1824 set_sense_type(chip
, lun
,
1825 SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1826 TRACE_RET(chip
, TRANSPORT_FAILED
);
1831 if ((scsi_bufflen(srb
) == 0x0C) &&
1832 (srb
->cmnd
[8] == 0x00) && (srb
->cmnd
[9] == 0x0C)) {
1833 retval
= mg_rsp(srb
, chip
);
1834 if (retval
!= STATUS_SUCCESS
)
1835 TRACE_RET(chip
, TRANSPORT_FAILED
);
1837 set_sense_type(chip
, lun
,
1838 SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1839 TRACE_RET(chip
, TRANSPORT_FAILED
);
1844 ms_card
->mg_entry_num
= srb
->cmnd
[5];
1845 if ((scsi_bufflen(srb
) == 0x404) &&
1846 (srb
->cmnd
[8] == 0x04) &&
1847 (srb
->cmnd
[9] == 0x04) &&
1848 (srb
->cmnd
[2] == 0x00) &&
1849 (srb
->cmnd
[3] == 0x00) &&
1850 (srb
->cmnd
[4] == 0x00) && (srb
->cmnd
[5] < 32)) {
1851 retval
= mg_set_ICV(srb
, chip
);
1852 if (retval
!= STATUS_SUCCESS
)
1853 TRACE_RET(chip
, TRANSPORT_FAILED
);
1855 set_sense_type(chip
, lun
,
1856 SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1857 TRACE_RET(chip
, TRANSPORT_FAILED
);
1862 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1863 TRACE_RET(chip
, TRANSPORT_FAILED
);
1866 scsi_set_resid(srb
, 0);
1867 return TRANSPORT_GOOD
;
1871 int rts51x_scsi_handler(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1873 #ifdef SUPPORT_SD_LOCK
1874 struct sd_info
*sd_card
= &(chip
->sd_card
);
1876 struct ms_info
*ms_card
= &(chip
->ms_card
);
1877 unsigned int lun
= SCSI_LUN(srb
);
1878 int result
= TRANSPORT_GOOD
;
1880 #ifdef SUPPORT_SD_LOCK
1881 if (sd_card
->sd_erase_status
) {
1882 /* Block all SCSI command except for REQUEST_SENSE
1883 * and rs_ppstatus */
1885 ((srb
->cmnd
[0] == VENDOR_CMND
)
1886 && (srb
->cmnd
[1] == SCSI_APP_CMD
)
1887 && (srb
->cmnd
[2] == GET_DEV_STATUS
))
1888 && (srb
->cmnd
[0] != REQUEST_SENSE
)) {
1889 /* Logical Unit Not Ready Format in Progress */
1890 set_sense_data(chip
, lun
, CUR_ERR
, 0x02, 0, 0x04, 0x04,
1892 TRACE_RET(chip
, TRANSPORT_FAILED
);
1897 if ((get_lun_card(chip
, lun
) == MS_CARD
) &&
1898 (ms_card
->format_status
== FORMAT_IN_PROGRESS
)) {
1899 if ((srb
->cmnd
[0] != REQUEST_SENSE
)
1900 && (srb
->cmnd
[0] != INQUIRY
)) {
1901 /* Logical Unit Not Ready Format in Progress */
1902 set_sense_data(chip
, lun
, CUR_ERR
, 0x02, 0, 0x04, 0x04,
1903 0, (u16
) (ms_card
->progress
));
1904 TRACE_RET(chip
, TRANSPORT_FAILED
);
1908 switch (srb
->cmnd
[0]) {
1913 result
= read_write(srb
, chip
);
1916 case TEST_UNIT_READY
:
1917 result
= test_unit_ready(srb
, chip
);
1921 result
= inquiry(srb
, chip
);
1925 result
= read_capacity(srb
, chip
);
1929 result
= start_stop_unit(srb
, chip
);
1932 case ALLOW_MEDIUM_REMOVAL
:
1933 result
= allow_medium_removal(srb
, chip
);
1937 result
= request_sense(srb
, chip
);
1942 result
= mode_sense(srb
, chip
);
1946 result
= read_format_capacity(srb
, chip
);
1950 result
= vendor_cmnd(srb
, chip
);
1954 result
= ms_sp_cmnd(srb
, chip
);
1958 case SD_PASS_THRU_MODE
:
1959 case SD_EXECUTE_NO_DATA
:
1960 case SD_EXECUTE_READ
:
1961 case SD_EXECUTE_WRITE
:
1964 result
= sd_extention_cmnd(srb
, chip
);
1968 #ifdef SUPPORT_MAGIC_GATE
1969 case CMD_MSPRO_MG_RKEY
:
1970 result
= mg_report_key(srb
, chip
);
1973 case CMD_MSPRO_MG_SKEY
:
1974 result
= mg_send_key(srb
, chip
);
1981 result
= TRANSPORT_GOOD
;
1985 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1986 result
= TRANSPORT_FAILED
;
1992 /***********************************************************************
1994 ***********************************************************************/
1996 const char *host_info(struct Scsi_Host
*host
)
1998 return "SCSI emulation for RTS51xx USB driver-based card reader";
2001 int slave_alloc(struct scsi_device
*sdev
)
2004 * Set the INQUIRY transfer length to 36. We don't use any of
2005 * the extra data and many devices choke if asked for more or
2006 * less than 36 bytes.
2008 sdev
->inquiry_len
= 36;
2012 int slave_configure(struct scsi_device
*sdev
)
2014 /* Scatter-gather buffers (all but the last) must have a length
2015 * divisible by the bulk maxpacket size. Otherwise a data packet
2016 * would end up being short, causing a premature end to the data
2017 * transfer. Since high-speed bulk pipes have a maxpacket size
2018 * of 512, we'll use that as the scsi device queue's DMA alignment
2019 * mask. Guaranteeing proper alignment of the first buffer will
2020 * have the desired effect because, except at the beginning and
2021 * the end, scatter-gather buffers follow page boundaries. */
2022 blk_queue_dma_alignment(sdev
->request_queue
, (512 - 1));
2024 /* Set the SCSI level to at least 2. We'll leave it at 3 if that's
2025 * what is originally reported. We need this to avoid confusing
2026 * the SCSI layer with devices that report 0 or 1, but need 10-byte
2027 * commands (ala ATAPI devices behind certain bridges, or devices
2028 * which simply have broken INQUIRY data).
2030 * NOTE: This means /dev/sg programs (ala cdrecord) will get the
2031 * actual information. This seems to be the preference for
2032 * programs like that.
2034 * NOTE: This also means that /proc/scsi/scsi and sysfs may report
2035 * the actual value or the modified one, depending on where the
2038 if (sdev
->scsi_level
< SCSI_2
)
2039 sdev
->scsi_level
= sdev
->sdev_target
->scsi_level
= SCSI_2
;
2044 /***********************************************************************
2045 * /proc/scsi/ functions
2046 ***********************************************************************/
2048 /* we use this macro to help us write into the buffer */
2050 #define SPRINTF(args...) \
2051 do { if (pos < buffer+length) pos += sprintf(pos, ## args); } while (0)
2053 int proc_info(struct Scsi_Host
*host
, char *buffer
,
2054 char **start
, off_t offset
, int length
, int inout
)
2058 /* if someone is sending us data, just throw it away */
2062 /* print the controller name */
2063 SPRINTF(" Host scsi%d: %s\n", host
->host_no
, RTS51X_NAME
);
2065 /* print product, vendor, and driver version strings */
2066 SPRINTF(" Vendor: Realtek Corp.\n");
2067 SPRINTF(" Product: RTS51xx USB Card Reader\n");
2068 SPRINTF(" Version: %s\n", DRIVER_VERSION
);
2069 SPRINTF(" Build: %s\n", __TIME__
);
2072 * Calculate start of next buffer, and return value.
2074 *start
= buffer
+ offset
;
2076 if ((pos
- buffer
) < offset
)
2078 else if ((pos
- buffer
- offset
) < length
)
2079 return pos
- buffer
- offset
;
2084 /* queue a command */
2085 /* This is always called with scsi_lock(host) held */
2086 int queuecommand_lck(struct scsi_cmnd
*srb
, void (*done
) (struct scsi_cmnd
*))
2088 struct rts51x_chip
*chip
= host_to_rts51x(srb
->device
->host
);
2090 /* check for state-transition errors */
2091 if (chip
->srb
!= NULL
) {
2092 RTS51X_DEBUGP("Error in %s: chip->srb = %p\n",
2093 __func__
, chip
->srb
);
2094 return SCSI_MLQUEUE_HOST_BUSY
;
2097 /* fail the command if we are disconnecting */
2098 if (test_bit(FLIDX_DISCONNECTING
, &chip
->usb
->dflags
)) {
2099 RTS51X_DEBUGP("Fail command during disconnect\n");
2100 srb
->result
= DID_NO_CONNECT
<< 16;
2105 /* enqueue the command and wake up the control thread */
2106 srb
->scsi_done
= done
;
2108 complete(&chip
->usb
->cmnd_ready
);
2113 #if 0 /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37) */
2114 int queuecommand(struct scsi_cmnd
*srb
, void (*done
) (struct scsi_cmnd
*))
2116 return queuecommand_lck(srb
, done
);
2119 DEF_SCSI_QCMD(queuecommand
)
2121 /***********************************************************************
2122 * Error handling functions
2123 ***********************************************************************/
2124 /* Command timeout and abort */
2125 int command_abort(struct scsi_cmnd
*srb
)
2127 struct rts51x_chip
*chip
= host_to_rts51x(srb
->device
->host
);
2129 RTS51X_DEBUGP("%s called\n", __func__
);
2131 /* us->srb together with the TIMED_OUT, RESETTING, and ABORTING
2132 * bits are protected by the host lock. */
2133 scsi_lock(rts51x_to_host(chip
));
2135 /* Is this command still active? */
2136 if (chip
->srb
!= srb
) {
2137 scsi_unlock(rts51x_to_host(chip
));
2138 RTS51X_DEBUGP("-- nothing to abort\n");
2142 /* Set the TIMED_OUT bit. Also set the ABORTING bit, but only if
2143 * a device reset isn't already in progress (to avoid interfering
2144 * with the reset). Note that we must retain the host lock while
2145 * calling usb_stor_stop_transport(); otherwise it might interfere
2146 * with an auto-reset that begins as soon as we release the lock. */
2147 set_bit(FLIDX_TIMED_OUT
, &chip
->usb
->dflags
);
2148 if (!test_bit(FLIDX_RESETTING
, &chip
->usb
->dflags
)) {
2149 set_bit(FLIDX_ABORTING
, &chip
->usb
->dflags
);
2150 /* rts51x_stop_transport(us); */
2152 scsi_unlock(rts51x_to_host(chip
));
2154 /* Wait for the aborted command to finish */
2155 wait_for_completion(&chip
->usb
->notify
);
2159 /* This invokes the transport reset mechanism to reset the state of the
2161 int device_reset(struct scsi_cmnd
*srb
)
2165 RTS51X_DEBUGP("%s called\n", __func__
);
2167 return result
< 0 ? FAILED
: SUCCESS
;
2170 /* Simulate a SCSI bus reset by resetting the device's USB port. */
2171 int bus_reset(struct scsi_cmnd
*srb
)
2175 RTS51X_DEBUGP("%s called\n", __func__
);
2177 return result
< 0 ? FAILED
: SUCCESS
;
2180 static const char *rts5139_info(struct Scsi_Host
*host
)
2182 return "SCSI emulation for RTS5139 USB card reader";
2185 struct scsi_host_template rts51x_host_template
= {
2186 /* basic userland interface stuff */
2187 .name
= RTS51X_NAME
,
2188 .proc_name
= RTS51X_NAME
,
2189 .proc_info
= proc_info
,
2190 .info
= rts5139_info
,
2192 /* command interface -- queued only */
2193 .queuecommand
= queuecommand
,
2195 /* error and abort handlers */
2196 .eh_abort_handler
= command_abort
,
2197 .eh_device_reset_handler
= device_reset
,
2198 .eh_bus_reset_handler
= bus_reset
,
2200 /* queue commands only, only one command per LUN */
2204 /* unknown initiator id */
2207 .slave_alloc
= slave_alloc
,
2208 .slave_configure
= slave_configure
,
2210 /* lots of sg segments can be handled */
2211 .sg_tablesize
= SG_ALL
,
2213 /* limit the total size of a transfer to 120 KB */
2216 /* merge commands... this seems to help performance, but
2217 * periodically someone should test to see which setting is more
2220 .use_clustering
= 1,
2225 /* we do our own delay after a device or bus reset */
2226 .skip_settle_delay
= 1,
2228 /* sysfs device attributes */
2229 /* .sdev_attrs = sysfs_device_attr_list, */
2231 /* module management */
2232 .module
= THIS_MODULE