3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2, or (at your option) any
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
17 #include <linux/jiffies.h>
18 #include <linux/errno.h>
19 #include <linux/module.h>
20 #include <linux/slab.h>
22 #include <scsi/scsi.h>
23 #include <scsi/scsi_cmnd.h>
25 #include <linux/firmware.h>
28 #include "transport.h"
33 #define SD_INIT1_FIRMWARE "ene-ub6250/sd_init1.bin"
34 #define SD_INIT2_FIRMWARE "ene-ub6250/sd_init2.bin"
35 #define SD_RW_FIRMWARE "ene-ub6250/sd_rdwr.bin"
36 #define MS_INIT_FIRMWARE "ene-ub6250/ms_init.bin"
37 #define MSP_RW_FIRMWARE "ene-ub6250/msp_rdwr.bin"
38 #define MS_RW_FIRMWARE "ene-ub6250/ms_rdwr.bin"
40 #define DRV_NAME "ums_eneub6250"
42 MODULE_DESCRIPTION("Driver for ENE UB6250 reader");
43 MODULE_LICENSE("GPL");
44 MODULE_FIRMWARE(SD_INIT1_FIRMWARE
);
45 MODULE_FIRMWARE(SD_INIT2_FIRMWARE
);
46 MODULE_FIRMWARE(SD_RW_FIRMWARE
);
47 MODULE_FIRMWARE(MS_INIT_FIRMWARE
);
48 MODULE_FIRMWARE(MSP_RW_FIRMWARE
);
49 MODULE_FIRMWARE(MS_RW_FIRMWARE
);
52 * The table of devices
54 #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
55 vendorName, productName, useProtocol, useTransport, \
56 initFunction, flags) \
57 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
58 .driver_info = (flags)}
60 static struct usb_device_id ene_ub6250_usb_ids
[] = {
61 # include "unusual_ene_ub6250.h"
62 { } /* Terminating entry */
64 MODULE_DEVICE_TABLE(usb
, ene_ub6250_usb_ids
);
71 #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
72 vendor_name, product_name, use_protocol, use_transport, \
73 init_function, Flags) \
75 .vendorName = vendor_name, \
76 .productName = product_name, \
77 .useProtocol = use_protocol, \
78 .useTransport = use_transport, \
79 .initFunction = init_function, \
82 static struct us_unusual_dev ene_ub6250_unusual_dev_list
[] = {
83 # include "unusual_ene_ub6250.h"
84 { } /* Terminating entry */
91 /* ENE bin code len */
92 #define ENE_BIN_CODE_LEN 0x800
94 #define REG_CARD_STATUS 0xFF83
95 #define REG_HW_TRAP1 0xFF89
98 #define SS_SUCCESS 0x00 /* No Sense */
99 #define SS_NOT_READY 0x02
100 #define SS_MEDIUM_ERR 0x03
101 #define SS_HW_ERR 0x04
102 #define SS_ILLEGAL_REQUEST 0x05
103 #define SS_UNIT_ATTENTION 0x06
105 /* ENE Load FW Pattern */
106 #define SD_INIT1_PATTERN 1
107 #define SD_INIT2_PATTERN 2
108 #define SD_RW_PATTERN 3
109 #define MS_INIT_PATTERN 4
110 #define MSP_RW_PATTERN 5
111 #define MS_RW_PATTERN 6
112 #define SM_INIT_PATTERN 7
113 #define SM_RW_PATTERN 8
120 /* Status Register 1 */
121 #define MS_REG_ST1_MB 0x80 /* media busy */
122 #define MS_REG_ST1_FB1 0x40 /* flush busy 1 */
123 #define MS_REG_ST1_DTER 0x20 /* error on data(corrected) */
124 #define MS_REG_ST1_UCDT 0x10 /* unable to correct data */
125 #define MS_REG_ST1_EXER 0x08 /* error on extra(corrected) */
126 #define MS_REG_ST1_UCEX 0x04 /* unable to correct extra */
127 #define MS_REG_ST1_FGER 0x02 /* error on overwrite flag(corrected) */
128 #define MS_REG_ST1_UCFG 0x01 /* unable to correct overwrite flag */
129 #define MS_REG_ST1_DEFAULT (MS_REG_ST1_MB | MS_REG_ST1_FB1 | MS_REG_ST1_DTER | MS_REG_ST1_UCDT | MS_REG_ST1_EXER | MS_REG_ST1_UCEX | MS_REG_ST1_FGER | MS_REG_ST1_UCFG)
132 #define MS_REG_OVR_BKST 0x80 /* block status */
133 #define MS_REG_OVR_BKST_OK MS_REG_OVR_BKST /* OK */
134 #define MS_REG_OVR_BKST_NG 0x00 /* NG */
135 #define MS_REG_OVR_PGST0 0x40 /* page status */
136 #define MS_REG_OVR_PGST1 0x20
137 #define MS_REG_OVR_PGST_MASK (MS_REG_OVR_PGST0 | MS_REG_OVR_PGST1)
138 #define MS_REG_OVR_PGST_OK (MS_REG_OVR_PGST0 | MS_REG_OVR_PGST1) /* OK */
139 #define MS_REG_OVR_PGST_NG MS_REG_OVR_PGST1 /* NG */
140 #define MS_REG_OVR_PGST_DATA_ERROR 0x00 /* data error */
141 #define MS_REG_OVR_UDST 0x10 /* update status */
142 #define MS_REG_OVR_UDST_UPDATING 0x00 /* updating */
143 #define MS_REG_OVR_UDST_NO_UPDATE MS_REG_OVR_UDST
144 #define MS_REG_OVR_RESERVED 0x08
145 #define MS_REG_OVR_DEFAULT (MS_REG_OVR_BKST_OK | MS_REG_OVR_PGST_OK | MS_REG_OVR_UDST_NO_UPDATE | MS_REG_OVR_RESERVED)
147 /* Management Flag */
148 #define MS_REG_MNG_SCMS0 0x20 /* serial copy management system */
149 #define MS_REG_MNG_SCMS1 0x10
150 #define MS_REG_MNG_SCMS_MASK (MS_REG_MNG_SCMS0 | MS_REG_MNG_SCMS1)
151 #define MS_REG_MNG_SCMS_COPY_OK (MS_REG_MNG_SCMS0 | MS_REG_MNG_SCMS1)
152 #define MS_REG_MNG_SCMS_ONE_COPY MS_REG_MNG_SCMS1
153 #define MS_REG_MNG_SCMS_NO_COPY 0x00
154 #define MS_REG_MNG_ATFLG 0x08 /* address transfer table flag */
155 #define MS_REG_MNG_ATFLG_OTHER MS_REG_MNG_ATFLG /* other */
156 #define MS_REG_MNG_ATFLG_ATTBL 0x00 /* address transfer table */
157 #define MS_REG_MNG_SYSFLG 0x04 /* system flag */
158 #define MS_REG_MNG_SYSFLG_USER MS_REG_MNG_SYSFLG /* user block */
159 #define MS_REG_MNG_SYSFLG_BOOT 0x00 /* system block */
160 #define MS_REG_MNG_RESERVED 0xc3
161 #define MS_REG_MNG_DEFAULT (MS_REG_MNG_SCMS_COPY_OK | MS_REG_MNG_ATFLG_OTHER | MS_REG_MNG_SYSFLG_USER | MS_REG_MNG_RESERVED)
164 #define MS_MAX_PAGES_PER_BLOCK 32
165 #define MS_MAX_INITIAL_ERROR_BLOCKS 10
166 #define MS_LIB_BITS_PER_BYTE 8
168 #define MS_SYSINF_FORMAT_FAT 1
169 #define MS_SYSINF_USAGE_GENERAL 0
171 #define MS_SYSINF_MSCLASS_TYPE_1 1
172 #define MS_SYSINF_PAGE_SIZE MS_BYTES_PER_PAGE /* fixed */
174 #define MS_SYSINF_CARDTYPE_RDONLY 1
175 #define MS_SYSINF_CARDTYPE_RDWR 2
176 #define MS_SYSINF_CARDTYPE_HYBRID 3
177 #define MS_SYSINF_SECURITY 0x01
178 #define MS_SYSINF_SECURITY_NO_SUPPORT MS_SYSINF_SECURITY
179 #define MS_SYSINF_SECURITY_SUPPORT 0
181 #define MS_SYSINF_RESERVED1 1
182 #define MS_SYSINF_RESERVED2 1
184 #define MS_SYSENT_TYPE_INVALID_BLOCK 0x01
185 #define MS_SYSENT_TYPE_CIS_IDI 0x0a /* CIS/IDI */
187 #define SIZE_OF_KIRO 1024
188 #define BYTE_MASK 0xff
191 #define MS_STATUS_WRITE_PROTECT 0x0106
192 #define MS_STATUS_SUCCESS 0x0000
193 #define MS_ERROR_FLASH_READ 0x8003
194 #define MS_ERROR_FLASH_ERASE 0x8005
195 #define MS_LB_ERROR 0xfff0
196 #define MS_LB_BOOT_BLOCK 0xfff1
197 #define MS_LB_INITIAL_ERROR 0xfff2
198 #define MS_STATUS_SUCCESS_WITH_ECC 0xfff3
199 #define MS_LB_ACQUIRED_ERROR 0xfff4
200 #define MS_LB_NOT_USED_ERASED 0xfff5
201 #define MS_NOCARD_ERROR 0xfff8
202 #define MS_NO_MEMORY_ERROR 0xfff9
203 #define MS_STATUS_INT_ERROR 0xfffa
204 #define MS_STATUS_ERROR 0xfffe
205 #define MS_LB_NOT_USED 0xffff
207 #define MS_REG_MNG_SYSFLG 0x04 /* system flag */
208 #define MS_REG_MNG_SYSFLG_USER MS_REG_MNG_SYSFLG /* user block */
210 #define MS_BOOT_BLOCK_ID 0x0001
211 #define MS_BOOT_BLOCK_FORMAT_VERSION 0x0100
212 #define MS_BOOT_BLOCK_DATA_ENTRIES 2
214 #define MS_NUMBER_OF_SYSTEM_ENTRY 4
215 #define MS_NUMBER_OF_BOOT_BLOCK 2
216 #define MS_BYTES_PER_PAGE 512
217 #define MS_LOGICAL_BLOCKS_PER_SEGMENT 496
218 #define MS_LOGICAL_BLOCKS_IN_1ST_SEGMENT 494
220 #define MS_PHYSICAL_BLOCKS_PER_SEGMENT 0x200 /* 512 */
221 #define MS_PHYSICAL_BLOCKS_PER_SEGMENT_MASK 0x1ff
224 #define MS_REG_OVR_BKST 0x80 /* block status */
225 #define MS_REG_OVR_BKST_OK MS_REG_OVR_BKST /* OK */
226 #define MS_REG_OVR_BKST_NG 0x00 /* NG */
228 /* Status Register 1 */
229 #define MS_REG_ST1_DTER 0x20 /* error on data(corrected) */
230 #define MS_REG_ST1_EXER 0x08 /* error on extra(corrected) */
231 #define MS_REG_ST1_FGER 0x02 /* error on overwrite flag(corrected) */
233 /* MemoryStick Register */
234 /* Status Register 0 */
235 #define MS_REG_ST0_WP 0x01 /* write protected */
236 #define MS_REG_ST0_WP_ON MS_REG_ST0_WP
238 #define MS_LIB_CTRL_RDONLY 0
239 #define MS_LIB_CTRL_WRPROTECT 1
242 #define ms_libconv_to_logical(pdx, PhyBlock) (((PhyBlock) >= (pdx)->MS_Lib.NumberOfPhyBlock) ? MS_STATUS_ERROR : (pdx)->MS_Lib.Phy2LogMap[PhyBlock])
243 #define ms_libconv_to_physical(pdx, LogBlock) (((LogBlock) >= (pdx)->MS_Lib.NumberOfLogBlock) ? MS_STATUS_ERROR : (pdx)->MS_Lib.Log2PhyMap[LogBlock])
245 #define ms_lib_ctrl_set(pdx, Flag) ((pdx)->MS_Lib.flags |= (1 << (Flag)))
246 #define ms_lib_ctrl_reset(pdx, Flag) ((pdx)->MS_Lib.flags &= ~(1 << (Flag)))
247 #define ms_lib_ctrl_check(pdx, Flag) ((pdx)->MS_Lib.flags & (1 << (Flag)))
249 #define ms_lib_iswritable(pdx) ((ms_lib_ctrl_check((pdx), MS_LIB_CTRL_RDONLY) == 0) && (ms_lib_ctrl_check(pdx, MS_LIB_CTRL_WRPROTECT) == 0))
250 #define ms_lib_clear_pagemap(pdx) memset((pdx)->MS_Lib.pagemap, 0, sizeof((pdx)->MS_Lib.pagemap))
251 #define memstick_logaddr(logadr1, logadr0) ((((u16)(logadr1)) << 8) | (logadr0))
285 struct ms_bootblock_cis
{
286 u8 bCistplDEVICE
[6]; /* 0 */
287 u8 bCistplDEVICE0C
[6]; /* 6 */
288 u8 bCistplJEDECC
[4]; /* 12 */
289 u8 bCistplMANFID
[6]; /* 16 */
290 u8 bCistplVER1
[32]; /* 22 */
291 u8 bCistplFUNCID
[4]; /* 54 */
292 u8 bCistplFUNCE0
[4]; /* 58 */
293 u8 bCistplFUNCE1
[5]; /* 62 */
294 u8 bCistplCONF
[7]; /* 67 */
295 u8 bCistplCFTBLENT0
[10];/* 74 */
296 u8 bCistplCFTBLENT1
[8]; /* 84 */
297 u8 bCistplCFTBLENT2
[12];/* 92 */
298 u8 bCistplCFTBLENT3
[8]; /* 104 */
299 u8 bCistplCFTBLENT4
[17];/* 112 */
300 u8 bCistplCFTBLENT5
[8]; /* 129 */
301 u8 bCistplCFTBLENT6
[17];/* 137 */
302 u8 bCistplCFTBLENT7
[8]; /* 154 */
303 u8 bCistplNOLINK
[3]; /* 162 */
306 struct ms_bootblock_idi
{
307 #define MS_IDI_GENERAL_CONF 0x848A
308 u16 wIDIgeneralConfiguration
; /* 0 */
309 u16 wIDInumberOfCylinder
; /* 1 */
310 u16 wIDIreserved0
; /* 2 */
311 u16 wIDInumberOfHead
; /* 3 */
312 u16 wIDIbytesPerTrack
; /* 4 */
313 u16 wIDIbytesPerSector
; /* 5 */
314 u16 wIDIsectorsPerTrack
; /* 6 */
315 u16 wIDItotalSectors
[2]; /* 7-8 high,low */
316 u16 wIDIreserved1
[11]; /* 9-19 */
317 u16 wIDIbufferType
; /* 20 */
318 u16 wIDIbufferSize
; /* 21 */
319 u16 wIDIlongCmdECC
; /* 22 */
320 u16 wIDIfirmVersion
[4]; /* 23-26 */
321 u16 wIDImodelName
[20]; /* 27-46 */
322 u16 wIDIreserved2
; /* 47 */
323 u16 wIDIlongWordSupported
; /* 48 */
324 u16 wIDIdmaSupported
; /* 49 */
325 u16 wIDIreserved3
; /* 50 */
326 u16 wIDIpioTiming
; /* 51 */
327 u16 wIDIdmaTiming
; /* 52 */
328 u16 wIDItransferParameter
; /* 53 */
329 u16 wIDIformattedCylinder
; /* 54 */
330 u16 wIDIformattedHead
; /* 55 */
331 u16 wIDIformattedSectorsPerTrack
;/* 56 */
332 u16 wIDIformattedTotalSectors
[2];/* 57-58 */
333 u16 wIDImultiSector
; /* 59 */
334 u16 wIDIlbaSectors
[2]; /* 60-61 */
335 u16 wIDIsingleWordDMA
; /* 62 */
336 u16 wIDImultiWordDMA
; /* 63 */
337 u16 wIDIreserved4
[192]; /* 64-255 */
340 struct ms_bootblock_sysent_rec
{
347 struct ms_bootblock_sysent
{
348 struct ms_bootblock_sysent_rec entry
[MS_NUMBER_OF_SYSTEM_ENTRY
];
351 struct ms_bootblock_sysinf
{
352 u8 bMsClass
; /* must be 1 */
353 u8 bCardType
; /* see below */
354 u16 wBlockSize
; /* n KB */
355 u16 wBlockNumber
; /* number of physical block */
356 u16 wTotalBlockNumber
; /* number of logical block */
357 u16 wPageSize
; /* must be 0x200 */
358 u8 bExtraSize
; /* 0x10 */
362 u8 bAssemblyMakerCode
;
363 u8 bAssemblyMachineCode
[3];
364 u16 wMemoryMakerCode
;
365 u16 wMemoryDeviceCode
;
371 u16 wControllerChipNumber
;
372 u16 wControllerFunction
; /* New MS */
373 u8 bReserved3
[9]; /* New MS */
374 u8 bParallelSupport
; /* New MS */
375 u16 wFormatValue
; /* New MS */
385 struct ms_bootblock_header
{
389 u8 bNumberOfDataEntry
;
393 struct ms_bootblock_page0
{
394 struct ms_bootblock_header header
;
395 struct ms_bootblock_sysent sysent
;
396 struct ms_bootblock_sysinf sysinf
;
399 struct ms_bootblock_cis_idi
{
401 struct ms_bootblock_cis cis
;
406 struct ms_bootblock_idi idi
;
412 /* ENE MS Lib struct */
413 struct ms_lib_type_extdat
{
426 u32 NumberOfCylinder
;
427 u32 SectorsPerCylinder
;
428 u16 cardType
; /* R/W, RO, Hybrid */
431 u16 NumberOfPhyBlock
;
432 u16 NumberOfLogBlock
;
434 u16
*Phy2LogMap
; /* phy2log table */
435 u16
*Log2PhyMap
; /* log2phy table */
437 unsigned char *pagemap
[(MS_MAX_PAGES_PER_BLOCK
+ (MS_LIB_BITS_PER_BYTE
-1)) / MS_LIB_BITS_PER_BYTE
];
438 unsigned char *blkpag
;
439 struct ms_lib_type_extdat
*blkext
;
440 unsigned char copybuf
[512];
444 /* SD Block Length */
445 /* 2^9 = 512 Bytes, The HW maximum read/write data length */
446 #define SD_BLOCK_LEN 9
448 struct ene_ub6250_info
{
450 /* I/O bounce buffer */
454 struct SD_STATUS SD_Status
;
455 struct MS_STATUS MS_Status
;
456 struct SM_STATUS SM_Status
;
458 /* ----- SD Control Data ---------------- */
459 /*SD_REGISTER SD_Regs; */
465 /* SD/MMC New spec. */
468 u8 SD20_HIGH_CAPACITY
;
472 u8 MMC_HIGH_CAPACITY
;
474 /*----- MS Control Data ---------------- */
477 struct ms_lib_ctrl MS_Lib
;
481 /*----- SM Control Data ---------------- */
485 unsigned char *testbuf
;
490 /*------Power Managerment ---------------*/
494 static int ene_sd_init(struct us_data
*us
);
495 static int ene_ms_init(struct us_data
*us
);
496 static int ene_load_bincode(struct us_data
*us
, unsigned char flag
);
498 static void ene_ub6250_info_destructor(void *extra
)
500 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) extra
;
507 static int ene_send_scsi_cmd(struct us_data
*us
, u8 fDir
, void *buf
, int use_sg
)
509 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
510 struct bulk_cs_wrap
*bcs
= (struct bulk_cs_wrap
*) us
->iobuf
;
513 unsigned int residue
;
514 unsigned int cswlen
= 0, partial
= 0;
515 unsigned int transfer_length
= bcb
->DataTransferLength
;
517 /* usb_stor_dbg(us, "transport --- ene_send_scsi_cmd\n"); */
518 /* send cmd to out endpoint */
519 result
= usb_stor_bulk_transfer_buf(us
, us
->send_bulk_pipe
,
520 bcb
, US_BULK_CB_WRAP_LEN
, NULL
);
521 if (result
!= USB_STOR_XFER_GOOD
) {
522 usb_stor_dbg(us
, "send cmd to out endpoint fail ---\n");
523 return USB_STOR_TRANSPORT_ERROR
;
527 unsigned int pipe
= fDir
;
529 if (fDir
== FDIR_READ
)
530 pipe
= us
->recv_bulk_pipe
;
532 pipe
= us
->send_bulk_pipe
;
536 result
= usb_stor_bulk_srb(us
, pipe
, us
->srb
);
538 result
= usb_stor_bulk_transfer_sg(us
, pipe
, buf
,
539 transfer_length
, 0, &partial
);
541 if (result
!= USB_STOR_XFER_GOOD
) {
542 usb_stor_dbg(us
, "data transfer fail ---\n");
543 return USB_STOR_TRANSPORT_ERROR
;
547 /* Get CSW for device status */
548 result
= usb_stor_bulk_transfer_buf(us
, us
->recv_bulk_pipe
, bcs
,
549 US_BULK_CS_WRAP_LEN
, &cswlen
);
551 if (result
== USB_STOR_XFER_SHORT
&& cswlen
== 0) {
552 usb_stor_dbg(us
, "Received 0-length CSW; retrying...\n");
553 result
= usb_stor_bulk_transfer_buf(us
, us
->recv_bulk_pipe
,
554 bcs
, US_BULK_CS_WRAP_LEN
, &cswlen
);
557 if (result
== USB_STOR_XFER_STALLED
) {
558 /* get the status again */
559 usb_stor_dbg(us
, "Attempting to get CSW (2nd try)...\n");
560 result
= usb_stor_bulk_transfer_buf(us
, us
->recv_bulk_pipe
,
561 bcs
, US_BULK_CS_WRAP_LEN
, NULL
);
564 if (result
!= USB_STOR_XFER_GOOD
)
565 return USB_STOR_TRANSPORT_ERROR
;
567 /* check bulk status */
568 residue
= le32_to_cpu(bcs
->Residue
);
570 /* try to compute the actual residue, based on how much data
571 * was really transferred and what the device tells us */
572 if (residue
&& !(us
->fflags
& US_FL_IGNORE_RESIDUE
)) {
573 residue
= min(residue
, transfer_length
);
575 scsi_set_resid(us
->srb
, max(scsi_get_resid(us
->srb
),
579 if (bcs
->Status
!= US_BULK_STAT_OK
)
580 return USB_STOR_TRANSPORT_ERROR
;
582 return USB_STOR_TRANSPORT_GOOD
;
585 static int sd_scsi_test_unit_ready(struct us_data
*us
, struct scsi_cmnd
*srb
)
587 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
589 if (info
->SD_Status
.Insert
&& info
->SD_Status
.Ready
)
590 return USB_STOR_TRANSPORT_GOOD
;
593 return USB_STOR_TRANSPORT_GOOD
;
596 return USB_STOR_TRANSPORT_GOOD
;
599 static int sd_scsi_inquiry(struct us_data
*us
, struct scsi_cmnd
*srb
)
601 unsigned char data_ptr
[36] = {
602 0x00, 0x80, 0x02, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x55,
603 0x53, 0x42, 0x32, 0x2E, 0x30, 0x20, 0x20, 0x43, 0x61,
604 0x72, 0x64, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20,
605 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x30, 0x30 };
607 usb_stor_set_xfer_buf(data_ptr
, 36, srb
);
608 return USB_STOR_TRANSPORT_GOOD
;
611 static int sd_scsi_mode_sense(struct us_data
*us
, struct scsi_cmnd
*srb
)
613 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
614 unsigned char mediaNoWP
[12] = {
615 0x0b, 0x00, 0x00, 0x08, 0x00, 0x00,
616 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
617 unsigned char mediaWP
[12] = {
618 0x0b, 0x00, 0x80, 0x08, 0x00, 0x00,
619 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
621 if (info
->SD_Status
.WtP
)
622 usb_stor_set_xfer_buf(mediaWP
, 12, srb
);
624 usb_stor_set_xfer_buf(mediaNoWP
, 12, srb
);
627 return USB_STOR_TRANSPORT_GOOD
;
630 static int sd_scsi_read_capacity(struct us_data
*us
, struct scsi_cmnd
*srb
)
634 unsigned int offset
= 0;
635 unsigned char buf
[8];
636 struct scatterlist
*sg
= NULL
;
637 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
639 usb_stor_dbg(us
, "sd_scsi_read_capacity\n");
640 if (info
->SD_Status
.HiCapacity
) {
642 if (info
->SD_Status
.IsMMC
)
643 bl_num
= info
->HC_C_SIZE
-1;
645 bl_num
= (info
->HC_C_SIZE
+ 1) * 1024 - 1;
647 bl_len
= 1 << (info
->SD_READ_BL_LEN
);
648 bl_num
= info
->SD_Block_Mult
* (info
->SD_C_SIZE
+ 1)
649 * (1 << (info
->SD_C_SIZE_MULT
+ 2)) - 1;
651 info
->bl_num
= bl_num
;
652 usb_stor_dbg(us
, "bl_len = %x\n", bl_len
);
653 usb_stor_dbg(us
, "bl_num = %x\n", bl_num
);
655 /*srb->request_bufflen = 8; */
656 buf
[0] = (bl_num
>> 24) & 0xff;
657 buf
[1] = (bl_num
>> 16) & 0xff;
658 buf
[2] = (bl_num
>> 8) & 0xff;
659 buf
[3] = (bl_num
>> 0) & 0xff;
660 buf
[4] = (bl_len
>> 24) & 0xff;
661 buf
[5] = (bl_len
>> 16) & 0xff;
662 buf
[6] = (bl_len
>> 8) & 0xff;
663 buf
[7] = (bl_len
>> 0) & 0xff;
665 usb_stor_access_xfer_buf(buf
, 8, srb
, &sg
, &offset
, TO_XFER_BUF
);
667 return USB_STOR_TRANSPORT_GOOD
;
670 static int sd_scsi_read(struct us_data
*us
, struct scsi_cmnd
*srb
)
673 unsigned char *cdb
= srb
->cmnd
;
674 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
675 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
677 u32 bn
= ((cdb
[2] << 24) & 0xff000000) | ((cdb
[3] << 16) & 0x00ff0000) |
678 ((cdb
[4] << 8) & 0x0000ff00) | ((cdb
[5] << 0) & 0x000000ff);
679 u16 blen
= ((cdb
[7] << 8) & 0xff00) | ((cdb
[8] << 0) & 0x00ff);
680 u32 bnByte
= bn
* 0x200;
681 u32 blenByte
= blen
* 0x200;
683 if (bn
> info
->bl_num
)
684 return USB_STOR_TRANSPORT_ERROR
;
686 result
= ene_load_bincode(us
, SD_RW_PATTERN
);
687 if (result
!= USB_STOR_XFER_GOOD
) {
688 usb_stor_dbg(us
, "Load SD RW pattern Fail !!\n");
689 return USB_STOR_TRANSPORT_ERROR
;
692 if (info
->SD_Status
.HiCapacity
)
695 /* set up the command wrapper */
696 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
697 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
698 bcb
->DataTransferLength
= blenByte
;
699 bcb
->Flags
= US_BULK_FLAG_IN
;
701 bcb
->CDB
[5] = (unsigned char)(bnByte
);
702 bcb
->CDB
[4] = (unsigned char)(bnByte
>>8);
703 bcb
->CDB
[3] = (unsigned char)(bnByte
>>16);
704 bcb
->CDB
[2] = (unsigned char)(bnByte
>>24);
706 result
= ene_send_scsi_cmd(us
, FDIR_READ
, scsi_sglist(srb
), 1);
710 static int sd_scsi_write(struct us_data
*us
, struct scsi_cmnd
*srb
)
713 unsigned char *cdb
= srb
->cmnd
;
714 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
715 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
717 u32 bn
= ((cdb
[2] << 24) & 0xff000000) | ((cdb
[3] << 16) & 0x00ff0000) |
718 ((cdb
[4] << 8) & 0x0000ff00) | ((cdb
[5] << 0) & 0x000000ff);
719 u16 blen
= ((cdb
[7] << 8) & 0xff00) | ((cdb
[8] << 0) & 0x00ff);
720 u32 bnByte
= bn
* 0x200;
721 u32 blenByte
= blen
* 0x200;
723 if (bn
> info
->bl_num
)
724 return USB_STOR_TRANSPORT_ERROR
;
726 result
= ene_load_bincode(us
, SD_RW_PATTERN
);
727 if (result
!= USB_STOR_XFER_GOOD
) {
728 usb_stor_dbg(us
, "Load SD RW pattern Fail !!\n");
729 return USB_STOR_TRANSPORT_ERROR
;
732 if (info
->SD_Status
.HiCapacity
)
735 /* set up the command wrapper */
736 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
737 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
738 bcb
->DataTransferLength
= blenByte
;
741 bcb
->CDB
[5] = (unsigned char)(bnByte
);
742 bcb
->CDB
[4] = (unsigned char)(bnByte
>>8);
743 bcb
->CDB
[3] = (unsigned char)(bnByte
>>16);
744 bcb
->CDB
[2] = (unsigned char)(bnByte
>>24);
746 result
= ene_send_scsi_cmd(us
, FDIR_WRITE
, scsi_sglist(srb
), 1);
754 static int ms_lib_set_logicalpair(struct us_data
*us
, u16 logblk
, u16 phyblk
)
756 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
758 if ((logblk
>= info
->MS_Lib
.NumberOfLogBlock
) || (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
))
761 info
->MS_Lib
.Phy2LogMap
[phyblk
] = logblk
;
762 info
->MS_Lib
.Log2PhyMap
[logblk
] = phyblk
;
767 static int ms_lib_set_logicalblockmark(struct us_data
*us
, u16 phyblk
, u16 mark
)
769 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
771 if (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
)
774 info
->MS_Lib
.Phy2LogMap
[phyblk
] = mark
;
779 static int ms_lib_set_initialerrorblock(struct us_data
*us
, u16 phyblk
)
781 return ms_lib_set_logicalblockmark(us
, phyblk
, MS_LB_INITIAL_ERROR
);
784 static int ms_lib_set_bootblockmark(struct us_data
*us
, u16 phyblk
)
786 return ms_lib_set_logicalblockmark(us
, phyblk
, MS_LB_BOOT_BLOCK
);
789 static int ms_lib_free_logicalmap(struct us_data
*us
)
791 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
793 kfree(info
->MS_Lib
.Phy2LogMap
);
794 info
->MS_Lib
.Phy2LogMap
= NULL
;
796 kfree(info
->MS_Lib
.Log2PhyMap
);
797 info
->MS_Lib
.Log2PhyMap
= NULL
;
802 static int ms_lib_alloc_logicalmap(struct us_data
*us
)
805 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
807 info
->MS_Lib
.Phy2LogMap
= kmalloc(info
->MS_Lib
.NumberOfPhyBlock
* sizeof(u16
), GFP_KERNEL
);
808 info
->MS_Lib
.Log2PhyMap
= kmalloc(info
->MS_Lib
.NumberOfLogBlock
* sizeof(u16
), GFP_KERNEL
);
810 if ((info
->MS_Lib
.Phy2LogMap
== NULL
) || (info
->MS_Lib
.Log2PhyMap
== NULL
)) {
811 ms_lib_free_logicalmap(us
);
815 for (i
= 0; i
< info
->MS_Lib
.NumberOfPhyBlock
; i
++)
816 info
->MS_Lib
.Phy2LogMap
[i
] = MS_LB_NOT_USED
;
818 for (i
= 0; i
< info
->MS_Lib
.NumberOfLogBlock
; i
++)
819 info
->MS_Lib
.Log2PhyMap
[i
] = MS_LB_NOT_USED
;
824 static void ms_lib_clear_writebuf(struct us_data
*us
)
827 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
829 info
->MS_Lib
.wrtblk
= (u16
)-1;
830 ms_lib_clear_pagemap(info
);
832 if (info
->MS_Lib
.blkpag
)
833 memset(info
->MS_Lib
.blkpag
, 0xff, info
->MS_Lib
.PagesPerBlock
* info
->MS_Lib
.BytesPerSector
);
835 if (info
->MS_Lib
.blkext
) {
836 for (i
= 0; i
< info
->MS_Lib
.PagesPerBlock
; i
++) {
837 info
->MS_Lib
.blkext
[i
].status1
= MS_REG_ST1_DEFAULT
;
838 info
->MS_Lib
.blkext
[i
].ovrflg
= MS_REG_OVR_DEFAULT
;
839 info
->MS_Lib
.blkext
[i
].mngflg
= MS_REG_MNG_DEFAULT
;
840 info
->MS_Lib
.blkext
[i
].logadr
= MS_LB_NOT_USED
;
845 static int ms_count_freeblock(struct us_data
*us
, u16 PhyBlock
)
848 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
850 Ende
= PhyBlock
+ MS_PHYSICAL_BLOCKS_PER_SEGMENT
;
851 for (Count
= 0; PhyBlock
< Ende
; PhyBlock
++) {
852 switch (info
->MS_Lib
.Phy2LogMap
[PhyBlock
]) {
854 case MS_LB_NOT_USED_ERASED
:
864 static int ms_read_readpage(struct us_data
*us
, u32 PhyBlockAddr
,
865 u8 PageNum
, u32
*PageBuf
, struct ms_lib_type_extdat
*ExtraDat
)
867 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
868 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
869 u8
*bbuf
= info
->bbuf
;
871 u32 bn
= PhyBlockAddr
* 0x20 + PageNum
;
873 /* printk(KERN_INFO "MS --- MS_ReaderReadPage,
874 PhyBlockAddr = %x, PageNum = %x\n", PhyBlockAddr, PageNum); */
876 result
= ene_load_bincode(us
, MS_RW_PATTERN
);
877 if (result
!= USB_STOR_XFER_GOOD
)
878 return USB_STOR_TRANSPORT_ERROR
;
881 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
882 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
883 bcb
->DataTransferLength
= 0x200;
884 bcb
->Flags
= US_BULK_FLAG_IN
;
887 bcb
->CDB
[1] = 0x02; /* in init.c ENE_MSInit() is 0x01 */
889 bcb
->CDB
[5] = (unsigned char)(bn
);
890 bcb
->CDB
[4] = (unsigned char)(bn
>>8);
891 bcb
->CDB
[3] = (unsigned char)(bn
>>16);
892 bcb
->CDB
[2] = (unsigned char)(bn
>>24);
894 result
= ene_send_scsi_cmd(us
, FDIR_READ
, PageBuf
, 0);
895 if (result
!= USB_STOR_XFER_GOOD
)
896 return USB_STOR_TRANSPORT_ERROR
;
899 /* Read Extra Data */
900 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
901 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
902 bcb
->DataTransferLength
= 0x4;
903 bcb
->Flags
= US_BULK_FLAG_IN
;
907 bcb
->CDB
[5] = (unsigned char)(PageNum
);
908 bcb
->CDB
[4] = (unsigned char)(PhyBlockAddr
);
909 bcb
->CDB
[3] = (unsigned char)(PhyBlockAddr
>>8);
910 bcb
->CDB
[2] = (unsigned char)(PhyBlockAddr
>>16);
913 result
= ene_send_scsi_cmd(us
, FDIR_READ
, bbuf
, 0);
914 if (result
!= USB_STOR_XFER_GOOD
)
915 return USB_STOR_TRANSPORT_ERROR
;
917 ExtraDat
->reserved
= 0;
918 ExtraDat
->intr
= 0x80; /* Not yet,fireware support */
919 ExtraDat
->status0
= 0x10; /* Not yet,fireware support */
921 ExtraDat
->status1
= 0x00; /* Not yet,fireware support */
922 ExtraDat
->ovrflg
= bbuf
[0];
923 ExtraDat
->mngflg
= bbuf
[1];
924 ExtraDat
->logadr
= memstick_logaddr(bbuf
[2], bbuf
[3]);
926 return USB_STOR_TRANSPORT_GOOD
;
929 static int ms_lib_process_bootblock(struct us_data
*us
, u16 PhyBlock
, u8
*PageData
)
931 struct ms_bootblock_sysent
*SysEntry
;
932 struct ms_bootblock_sysinf
*SysInfo
;
936 struct ms_lib_type_extdat ExtraData
;
937 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
939 PageBuffer
= kmalloc(MS_BYTES_PER_PAGE
, GFP_KERNEL
);
940 if (PageBuffer
== NULL
)
945 SysInfo
= &(((struct ms_bootblock_page0
*)PageData
)->sysinf
);
947 if ((SysInfo
->bMsClass
!= MS_SYSINF_MSCLASS_TYPE_1
) ||
948 (be16_to_cpu(SysInfo
->wPageSize
) != MS_SYSINF_PAGE_SIZE
) ||
949 ((SysInfo
->bSecuritySupport
& MS_SYSINF_SECURITY
) == MS_SYSINF_SECURITY_SUPPORT
) ||
950 (SysInfo
->bReserved1
!= MS_SYSINF_RESERVED1
) ||
951 (SysInfo
->bReserved2
!= MS_SYSINF_RESERVED2
) ||
952 (SysInfo
->bFormatType
!= MS_SYSINF_FORMAT_FAT
) ||
953 (SysInfo
->bUsage
!= MS_SYSINF_USAGE_GENERAL
))
956 switch (info
->MS_Lib
.cardType
= SysInfo
->bCardType
) {
957 case MS_SYSINF_CARDTYPE_RDONLY
:
958 ms_lib_ctrl_set(info
, MS_LIB_CTRL_RDONLY
);
960 case MS_SYSINF_CARDTYPE_RDWR
:
961 ms_lib_ctrl_reset(info
, MS_LIB_CTRL_RDONLY
);
963 case MS_SYSINF_CARDTYPE_HYBRID
:
968 info
->MS_Lib
.blockSize
= be16_to_cpu(SysInfo
->wBlockSize
);
969 info
->MS_Lib
.NumberOfPhyBlock
= be16_to_cpu(SysInfo
->wBlockNumber
);
970 info
->MS_Lib
.NumberOfLogBlock
= be16_to_cpu(SysInfo
->wTotalBlockNumber
)-2;
971 info
->MS_Lib
.PagesPerBlock
= info
->MS_Lib
.blockSize
* SIZE_OF_KIRO
/ MS_BYTES_PER_PAGE
;
972 info
->MS_Lib
.NumberOfSegment
= info
->MS_Lib
.NumberOfPhyBlock
/ MS_PHYSICAL_BLOCKS_PER_SEGMENT
;
973 info
->MS_Model
= be16_to_cpu(SysInfo
->wMemorySize
);
975 /*Allocate to all number of logicalblock and physicalblock */
976 if (ms_lib_alloc_logicalmap(us
))
979 /* Mark the book block */
980 ms_lib_set_bootblockmark(us
, PhyBlock
);
982 SysEntry
= &(((struct ms_bootblock_page0
*)PageData
)->sysent
);
984 for (i
= 0; i
< MS_NUMBER_OF_SYSTEM_ENTRY
; i
++) {
985 u32 EntryOffset
, EntrySize
;
987 EntryOffset
= be32_to_cpu(SysEntry
->entry
[i
].dwStart
);
989 if (EntryOffset
== 0xffffff)
991 EntrySize
= be32_to_cpu(SysEntry
->entry
[i
].dwSize
);
996 if (EntryOffset
+ MS_BYTES_PER_PAGE
+ EntrySize
> info
->MS_Lib
.blockSize
* (u32
)SIZE_OF_KIRO
)
1000 u8 PrevPageNumber
= 0;
1003 if (SysEntry
->entry
[i
].bType
!= MS_SYSENT_TYPE_INVALID_BLOCK
)
1006 while (EntrySize
> 0) {
1008 PageNumber
= (u8
)(EntryOffset
/ MS_BYTES_PER_PAGE
+ 1);
1009 if (PageNumber
!= PrevPageNumber
) {
1010 switch (ms_read_readpage(us
, PhyBlock
, PageNumber
, (u32
*)PageBuffer
, &ExtraData
)) {
1011 case MS_STATUS_SUCCESS
:
1013 case MS_STATUS_WRITE_PROTECT
:
1014 case MS_ERROR_FLASH_READ
:
1015 case MS_STATUS_ERROR
:
1020 PrevPageNumber
= PageNumber
;
1023 phyblk
= be16_to_cpu(*(u16
*)(PageBuffer
+ (EntryOffset
% MS_BYTES_PER_PAGE
)));
1024 if (phyblk
< 0x0fff)
1025 ms_lib_set_initialerrorblock(us
, phyblk
);
1030 } else if (i
== 1) { /* CIS/IDI */
1031 struct ms_bootblock_idi
*idi
;
1033 if (SysEntry
->entry
[i
].bType
!= MS_SYSENT_TYPE_CIS_IDI
)
1036 switch (ms_read_readpage(us
, PhyBlock
, (u8
)(EntryOffset
/ MS_BYTES_PER_PAGE
+ 1), (u32
*)PageBuffer
, &ExtraData
)) {
1037 case MS_STATUS_SUCCESS
:
1039 case MS_STATUS_WRITE_PROTECT
:
1040 case MS_ERROR_FLASH_READ
:
1041 case MS_STATUS_ERROR
:
1046 idi
= &((struct ms_bootblock_cis_idi
*)(PageBuffer
+ (EntryOffset
% MS_BYTES_PER_PAGE
)))->idi
.idi
;
1047 if (le16_to_cpu(idi
->wIDIgeneralConfiguration
) != MS_IDI_GENERAL_CONF
)
1050 info
->MS_Lib
.BytesPerSector
= le16_to_cpu(idi
->wIDIbytesPerSector
);
1051 if (info
->MS_Lib
.BytesPerSector
!= MS_BYTES_PER_PAGE
)
1060 ms_lib_free_logicalmap(us
);
1068 static void ms_lib_free_writebuf(struct us_data
*us
)
1070 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1071 info
->MS_Lib
.wrtblk
= (u16
)-1; /* set to -1 */
1073 /* memset((fdoExt)->MS_Lib.pagemap, 0, sizeof((fdoExt)->MS_Lib.pagemap)) */
1075 ms_lib_clear_pagemap(info
); /* (pdx)->MS_Lib.pagemap memset 0 in ms.h */
1077 if (info
->MS_Lib
.blkpag
) {
1078 kfree((u8
*)(info
->MS_Lib
.blkpag
)); /* Arnold test ... */
1079 info
->MS_Lib
.blkpag
= NULL
;
1082 if (info
->MS_Lib
.blkext
) {
1083 kfree((u8
*)(info
->MS_Lib
.blkext
)); /* Arnold test ... */
1084 info
->MS_Lib
.blkext
= NULL
;
1089 static void ms_lib_free_allocatedarea(struct us_data
*us
)
1091 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1093 ms_lib_free_writebuf(us
); /* Free MS_Lib.pagemap */
1094 ms_lib_free_logicalmap(us
); /* kfree MS_Lib.Phy2LogMap and MS_Lib.Log2PhyMap */
1096 /* set struct us point flag to 0 */
1097 info
->MS_Lib
.flags
= 0;
1098 info
->MS_Lib
.BytesPerSector
= 0;
1099 info
->MS_Lib
.SectorsPerCylinder
= 0;
1101 info
->MS_Lib
.cardType
= 0;
1102 info
->MS_Lib
.blockSize
= 0;
1103 info
->MS_Lib
.PagesPerBlock
= 0;
1105 info
->MS_Lib
.NumberOfPhyBlock
= 0;
1106 info
->MS_Lib
.NumberOfLogBlock
= 0;
1110 static int ms_lib_alloc_writebuf(struct us_data
*us
)
1112 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1114 info
->MS_Lib
.wrtblk
= (u16
)-1;
1116 info
->MS_Lib
.blkpag
= kmalloc(info
->MS_Lib
.PagesPerBlock
* info
->MS_Lib
.BytesPerSector
, GFP_KERNEL
);
1117 info
->MS_Lib
.blkext
= kmalloc(info
->MS_Lib
.PagesPerBlock
* sizeof(struct ms_lib_type_extdat
), GFP_KERNEL
);
1119 if ((info
->MS_Lib
.blkpag
== NULL
) || (info
->MS_Lib
.blkext
== NULL
)) {
1120 ms_lib_free_writebuf(us
);
1124 ms_lib_clear_writebuf(us
);
1129 static int ms_lib_force_setlogical_pair(struct us_data
*us
, u16 logblk
, u16 phyblk
)
1131 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1133 if (logblk
== MS_LB_NOT_USED
)
1136 if ((logblk
>= info
->MS_Lib
.NumberOfLogBlock
) ||
1137 (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
))
1140 info
->MS_Lib
.Phy2LogMap
[phyblk
] = logblk
;
1141 info
->MS_Lib
.Log2PhyMap
[logblk
] = phyblk
;
1146 static int ms_read_copyblock(struct us_data
*us
, u16 oldphy
, u16 newphy
,
1147 u16 PhyBlockAddr
, u8 PageNum
, unsigned char *buf
, u16 len
)
1149 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1152 /* printk(KERN_INFO "MS_ReaderCopyBlock --- PhyBlockAddr = %x,
1153 PageNum = %x\n", PhyBlockAddr, PageNum); */
1154 result
= ene_load_bincode(us
, MS_RW_PATTERN
);
1155 if (result
!= USB_STOR_XFER_GOOD
)
1156 return USB_STOR_TRANSPORT_ERROR
;
1158 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1159 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1160 bcb
->DataTransferLength
= 0x200*len
;
1164 bcb
->CDB
[4] = (unsigned char)(oldphy
);
1165 bcb
->CDB
[3] = (unsigned char)(oldphy
>>8);
1166 bcb
->CDB
[2] = 0; /* (BYTE)(oldphy>>16) */
1167 bcb
->CDB
[7] = (unsigned char)(newphy
);
1168 bcb
->CDB
[6] = (unsigned char)(newphy
>>8);
1169 bcb
->CDB
[5] = 0; /* (BYTE)(newphy>>16) */
1170 bcb
->CDB
[9] = (unsigned char)(PhyBlockAddr
);
1171 bcb
->CDB
[8] = (unsigned char)(PhyBlockAddr
>>8);
1172 bcb
->CDB
[10] = PageNum
;
1174 result
= ene_send_scsi_cmd(us
, FDIR_WRITE
, buf
, 0);
1175 if (result
!= USB_STOR_XFER_GOOD
)
1176 return USB_STOR_TRANSPORT_ERROR
;
1178 return USB_STOR_TRANSPORT_GOOD
;
1181 static int ms_read_eraseblock(struct us_data
*us
, u32 PhyBlockAddr
)
1183 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1185 u32 bn
= PhyBlockAddr
;
1187 /* printk(KERN_INFO "MS --- ms_read_eraseblock,
1188 PhyBlockAddr = %x\n", PhyBlockAddr); */
1189 result
= ene_load_bincode(us
, MS_RW_PATTERN
);
1190 if (result
!= USB_STOR_XFER_GOOD
)
1191 return USB_STOR_TRANSPORT_ERROR
;
1193 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1194 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1195 bcb
->DataTransferLength
= 0x200;
1196 bcb
->Flags
= US_BULK_FLAG_IN
;
1199 bcb
->CDB
[4] = (unsigned char)(bn
);
1200 bcb
->CDB
[3] = (unsigned char)(bn
>>8);
1201 bcb
->CDB
[2] = (unsigned char)(bn
>>16);
1203 result
= ene_send_scsi_cmd(us
, FDIR_READ
, NULL
, 0);
1204 if (result
!= USB_STOR_XFER_GOOD
)
1205 return USB_STOR_TRANSPORT_ERROR
;
1207 return USB_STOR_TRANSPORT_GOOD
;
1210 static int ms_lib_check_disableblock(struct us_data
*us
, u16 PhyBlock
)
1212 unsigned char *PageBuf
= NULL
;
1213 u16 result
= MS_STATUS_SUCCESS
;
1215 struct ms_lib_type_extdat extdat
;
1216 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1218 PageBuf
= kmalloc(MS_BYTES_PER_PAGE
, GFP_KERNEL
);
1219 if (PageBuf
== NULL
) {
1220 result
= MS_NO_MEMORY_ERROR
;
1224 ms_read_readpage(us
, PhyBlock
, 1, (u32
*)PageBuf
, &extdat
);
1226 blk
= be16_to_cpu(PageBuf
[index
]);
1227 if (blk
== MS_LB_NOT_USED
)
1229 if (blk
== info
->MS_Lib
.Log2PhyMap
[0]) {
1230 result
= MS_ERROR_FLASH_READ
;
1241 static int ms_lib_setacquired_errorblock(struct us_data
*us
, u16 phyblk
)
1244 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1246 if (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
)
1249 log
= info
->MS_Lib
.Phy2LogMap
[phyblk
];
1251 if (log
< info
->MS_Lib
.NumberOfLogBlock
)
1252 info
->MS_Lib
.Log2PhyMap
[log
] = MS_LB_NOT_USED
;
1254 if (info
->MS_Lib
.Phy2LogMap
[phyblk
] != MS_LB_INITIAL_ERROR
)
1255 info
->MS_Lib
.Phy2LogMap
[phyblk
] = MS_LB_ACQUIRED_ERROR
;
1260 static int ms_lib_overwrite_extra(struct us_data
*us
, u32 PhyBlockAddr
,
1261 u8 PageNum
, u8 OverwriteFlag
)
1263 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1266 /* printk("MS --- MS_LibOverwriteExtra,
1267 PhyBlockAddr = %x, PageNum = %x\n", PhyBlockAddr, PageNum); */
1268 result
= ene_load_bincode(us
, MS_RW_PATTERN
);
1269 if (result
!= USB_STOR_XFER_GOOD
)
1270 return USB_STOR_TRANSPORT_ERROR
;
1272 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1273 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1274 bcb
->DataTransferLength
= 0x4;
1275 bcb
->Flags
= US_BULK_FLAG_IN
;
1278 bcb
->CDB
[5] = (unsigned char)(PageNum
);
1279 bcb
->CDB
[4] = (unsigned char)(PhyBlockAddr
);
1280 bcb
->CDB
[3] = (unsigned char)(PhyBlockAddr
>>8);
1281 bcb
->CDB
[2] = (unsigned char)(PhyBlockAddr
>>16);
1282 bcb
->CDB
[6] = OverwriteFlag
;
1287 result
= ene_send_scsi_cmd(us
, FDIR_READ
, NULL
, 0);
1288 if (result
!= USB_STOR_XFER_GOOD
)
1289 return USB_STOR_TRANSPORT_ERROR
;
1291 return USB_STOR_TRANSPORT_GOOD
;
1294 static int ms_lib_error_phyblock(struct us_data
*us
, u16 phyblk
)
1296 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1298 if (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
)
1299 return MS_STATUS_ERROR
;
1301 ms_lib_setacquired_errorblock(us
, phyblk
);
1303 if (ms_lib_iswritable(info
))
1304 return ms_lib_overwrite_extra(us
, phyblk
, 0, (u8
)(~MS_REG_OVR_BKST
& BYTE_MASK
));
1306 return MS_STATUS_SUCCESS
;
1309 static int ms_lib_erase_phyblock(struct us_data
*us
, u16 phyblk
)
1312 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1314 if (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
)
1315 return MS_STATUS_ERROR
;
1317 log
= info
->MS_Lib
.Phy2LogMap
[phyblk
];
1319 if (log
< info
->MS_Lib
.NumberOfLogBlock
)
1320 info
->MS_Lib
.Log2PhyMap
[log
] = MS_LB_NOT_USED
;
1322 info
->MS_Lib
.Phy2LogMap
[phyblk
] = MS_LB_NOT_USED
;
1324 if (ms_lib_iswritable(info
)) {
1325 switch (ms_read_eraseblock(us
, phyblk
)) {
1326 case MS_STATUS_SUCCESS
:
1327 info
->MS_Lib
.Phy2LogMap
[phyblk
] = MS_LB_NOT_USED_ERASED
;
1328 return MS_STATUS_SUCCESS
;
1329 case MS_ERROR_FLASH_ERASE
:
1330 case MS_STATUS_INT_ERROR
:
1331 ms_lib_error_phyblock(us
, phyblk
);
1332 return MS_ERROR_FLASH_ERASE
;
1333 case MS_STATUS_ERROR
:
1335 ms_lib_ctrl_set(info
, MS_LIB_CTRL_RDONLY
); /* MS_LibCtrlSet will used by ENE_MSInit ,need check, and why us to info*/
1336 ms_lib_setacquired_errorblock(us
, phyblk
);
1337 return MS_STATUS_ERROR
;
1341 ms_lib_setacquired_errorblock(us
, phyblk
);
1343 return MS_STATUS_SUCCESS
;
1346 static int ms_lib_read_extra(struct us_data
*us
, u32 PhyBlock
,
1347 u8 PageNum
, struct ms_lib_type_extdat
*ExtraDat
)
1349 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1350 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1351 u8
*bbuf
= info
->bbuf
;
1354 /* printk("MS_LibReadExtra --- PhyBlock = %x, PageNum = %x\n", PhyBlock, PageNum); */
1355 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1356 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1357 bcb
->DataTransferLength
= 0x4;
1358 bcb
->Flags
= US_BULK_FLAG_IN
;
1361 bcb
->CDB
[5] = (unsigned char)(PageNum
);
1362 bcb
->CDB
[4] = (unsigned char)(PhyBlock
);
1363 bcb
->CDB
[3] = (unsigned char)(PhyBlock
>>8);
1364 bcb
->CDB
[2] = (unsigned char)(PhyBlock
>>16);
1367 result
= ene_send_scsi_cmd(us
, FDIR_READ
, bbuf
, 0);
1368 if (result
!= USB_STOR_XFER_GOOD
)
1369 return USB_STOR_TRANSPORT_ERROR
;
1371 ExtraDat
->reserved
= 0;
1372 ExtraDat
->intr
= 0x80; /* Not yet, waiting for fireware support */
1373 ExtraDat
->status0
= 0x10; /* Not yet, waiting for fireware support */
1374 ExtraDat
->status1
= 0x00; /* Not yet, waiting for fireware support */
1375 ExtraDat
->ovrflg
= bbuf
[0];
1376 ExtraDat
->mngflg
= bbuf
[1];
1377 ExtraDat
->logadr
= memstick_logaddr(bbuf
[2], bbuf
[3]);
1379 return USB_STOR_TRANSPORT_GOOD
;
1382 static int ms_libsearch_block_from_physical(struct us_data
*us
, u16 phyblk
)
1386 struct ms_lib_type_extdat extdat
; /* need check */
1387 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1390 if (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
)
1393 for (blk
= phyblk
+ 1; blk
!= phyblk
; blk
++) {
1394 if ((blk
& MS_PHYSICAL_BLOCKS_PER_SEGMENT_MASK
) == 0)
1395 blk
-= MS_PHYSICAL_BLOCKS_PER_SEGMENT
;
1397 Newblk
= info
->MS_Lib
.Phy2LogMap
[blk
];
1398 if (info
->MS_Lib
.Phy2LogMap
[blk
] == MS_LB_NOT_USED_ERASED
) {
1400 } else if (info
->MS_Lib
.Phy2LogMap
[blk
] == MS_LB_NOT_USED
) {
1401 switch (ms_lib_read_extra(us
, blk
, 0, &extdat
)) {
1402 case MS_STATUS_SUCCESS
:
1403 case MS_STATUS_SUCCESS_WITH_ECC
:
1405 case MS_NOCARD_ERROR
:
1406 return MS_NOCARD_ERROR
;
1407 case MS_STATUS_INT_ERROR
:
1409 case MS_ERROR_FLASH_READ
:
1411 ms_lib_setacquired_errorblock(us
, blk
);
1415 if ((extdat
.ovrflg
& MS_REG_OVR_BKST
) != MS_REG_OVR_BKST_OK
) {
1416 ms_lib_setacquired_errorblock(us
, blk
);
1420 switch (ms_lib_erase_phyblock(us
, blk
)) {
1421 case MS_STATUS_SUCCESS
:
1423 case MS_STATUS_ERROR
:
1425 case MS_ERROR_FLASH_ERASE
:
1427 ms_lib_error_phyblock(us
, blk
);
1435 static int ms_libsearch_block_from_logical(struct us_data
*us
, u16 logblk
)
1438 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1440 phyblk
= ms_libconv_to_physical(info
, logblk
);
1441 if (phyblk
>= MS_LB_ERROR
) {
1442 if (logblk
>= info
->MS_Lib
.NumberOfLogBlock
)
1445 phyblk
= (logblk
+ MS_NUMBER_OF_BOOT_BLOCK
) / MS_LOGICAL_BLOCKS_PER_SEGMENT
;
1446 phyblk
*= MS_PHYSICAL_BLOCKS_PER_SEGMENT
;
1447 phyblk
+= MS_PHYSICAL_BLOCKS_PER_SEGMENT
- 1;
1450 return ms_libsearch_block_from_physical(us
, phyblk
);
1453 static int ms_scsi_test_unit_ready(struct us_data
*us
, struct scsi_cmnd
*srb
)
1455 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)(us
->extra
);
1457 /* pr_info("MS_SCSI_Test_Unit_Ready\n"); */
1458 if (info
->MS_Status
.Insert
&& info
->MS_Status
.Ready
) {
1459 return USB_STOR_TRANSPORT_GOOD
;
1462 return USB_STOR_TRANSPORT_GOOD
;
1465 return USB_STOR_TRANSPORT_GOOD
;
1468 static int ms_scsi_inquiry(struct us_data
*us
, struct scsi_cmnd
*srb
)
1470 /* pr_info("MS_SCSI_Inquiry\n"); */
1471 unsigned char data_ptr
[36] = {
1472 0x00, 0x80, 0x02, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x55,
1473 0x53, 0x42, 0x32, 0x2E, 0x30, 0x20, 0x20, 0x43, 0x61,
1474 0x72, 0x64, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20,
1475 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x30, 0x30};
1477 usb_stor_set_xfer_buf(data_ptr
, 36, srb
);
1478 return USB_STOR_TRANSPORT_GOOD
;
1481 static int ms_scsi_mode_sense(struct us_data
*us
, struct scsi_cmnd
*srb
)
1483 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1484 unsigned char mediaNoWP
[12] = {
1485 0x0b, 0x00, 0x00, 0x08, 0x00, 0x00,
1486 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
1487 unsigned char mediaWP
[12] = {
1488 0x0b, 0x00, 0x80, 0x08, 0x00, 0x00,
1489 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
1491 if (info
->MS_Status
.WtP
)
1492 usb_stor_set_xfer_buf(mediaWP
, 12, srb
);
1494 usb_stor_set_xfer_buf(mediaNoWP
, 12, srb
);
1496 return USB_STOR_TRANSPORT_GOOD
;
1499 static int ms_scsi_read_capacity(struct us_data
*us
, struct scsi_cmnd
*srb
)
1503 unsigned int offset
= 0;
1504 unsigned char buf
[8];
1505 struct scatterlist
*sg
= NULL
;
1506 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1508 usb_stor_dbg(us
, "ms_scsi_read_capacity\n");
1510 if (info
->MS_Status
.IsMSPro
)
1511 bl_num
= info
->MSP_TotalBlock
- 1;
1513 bl_num
= info
->MS_Lib
.NumberOfLogBlock
* info
->MS_Lib
.blockSize
* 2 - 1;
1515 info
->bl_num
= bl_num
;
1516 usb_stor_dbg(us
, "bl_len = %x\n", bl_len
);
1517 usb_stor_dbg(us
, "bl_num = %x\n", bl_num
);
1519 /*srb->request_bufflen = 8; */
1520 buf
[0] = (bl_num
>> 24) & 0xff;
1521 buf
[1] = (bl_num
>> 16) & 0xff;
1522 buf
[2] = (bl_num
>> 8) & 0xff;
1523 buf
[3] = (bl_num
>> 0) & 0xff;
1524 buf
[4] = (bl_len
>> 24) & 0xff;
1525 buf
[5] = (bl_len
>> 16) & 0xff;
1526 buf
[6] = (bl_len
>> 8) & 0xff;
1527 buf
[7] = (bl_len
>> 0) & 0xff;
1529 usb_stor_access_xfer_buf(buf
, 8, srb
, &sg
, &offset
, TO_XFER_BUF
);
1531 return USB_STOR_TRANSPORT_GOOD
;
1534 static void ms_lib_phy_to_log_range(u16 PhyBlock
, u16
*LogStart
, u16
*LogEnde
)
1536 PhyBlock
/= MS_PHYSICAL_BLOCKS_PER_SEGMENT
;
1539 *LogStart
= MS_LOGICAL_BLOCKS_IN_1ST_SEGMENT
+ (PhyBlock
- 1) * MS_LOGICAL_BLOCKS_PER_SEGMENT
;/*496*/
1540 *LogEnde
= *LogStart
+ MS_LOGICAL_BLOCKS_PER_SEGMENT
;/*496*/
1543 *LogEnde
= MS_LOGICAL_BLOCKS_IN_1ST_SEGMENT
;/*494*/
1547 static int ms_lib_read_extrablock(struct us_data
*us
, u32 PhyBlock
,
1548 u8 PageNum
, u8 blen
, void *buf
)
1550 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1553 /* printk("MS_LibReadExtraBlock --- PhyBlock = %x,
1554 PageNum = %x, blen = %x\n", PhyBlock, PageNum, blen); */
1556 /* Read Extra Data */
1557 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1558 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1559 bcb
->DataTransferLength
= 0x4 * blen
;
1560 bcb
->Flags
= US_BULK_FLAG_IN
;
1563 bcb
->CDB
[5] = (unsigned char)(PageNum
);
1564 bcb
->CDB
[4] = (unsigned char)(PhyBlock
);
1565 bcb
->CDB
[3] = (unsigned char)(PhyBlock
>>8);
1566 bcb
->CDB
[2] = (unsigned char)(PhyBlock
>>16);
1569 result
= ene_send_scsi_cmd(us
, FDIR_READ
, buf
, 0);
1570 if (result
!= USB_STOR_XFER_GOOD
)
1571 return USB_STOR_TRANSPORT_ERROR
;
1573 return USB_STOR_TRANSPORT_GOOD
;
1576 static int ms_lib_scan_logicalblocknumber(struct us_data
*us
, u16 btBlk1st
)
1578 u16 PhyBlock
, newblk
, i
;
1579 u16 LogStart
, LogEnde
;
1580 struct ms_lib_type_extdat extdat
;
1581 u32 count
= 0, index
= 0;
1582 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1583 u8
*bbuf
= info
->bbuf
;
1585 for (PhyBlock
= 0; PhyBlock
< info
->MS_Lib
.NumberOfPhyBlock
;) {
1586 ms_lib_phy_to_log_range(PhyBlock
, &LogStart
, &LogEnde
);
1588 for (i
= 0; i
< MS_PHYSICAL_BLOCKS_PER_SEGMENT
; i
++, PhyBlock
++) {
1589 switch (ms_libconv_to_logical(info
, PhyBlock
)) {
1590 case MS_STATUS_ERROR
:
1596 if (count
== PhyBlock
) {
1597 ms_lib_read_extrablock(us
, PhyBlock
, 0, 0x80,
1601 index
= (PhyBlock
% 0x80) * 4;
1603 extdat
.ovrflg
= bbuf
[index
];
1604 extdat
.mngflg
= bbuf
[index
+1];
1605 extdat
.logadr
= memstick_logaddr(bbuf
[index
+2],
1608 if ((extdat
.ovrflg
& MS_REG_OVR_BKST
) != MS_REG_OVR_BKST_OK
) {
1609 ms_lib_setacquired_errorblock(us
, PhyBlock
);
1613 if ((extdat
.mngflg
& MS_REG_MNG_ATFLG
) == MS_REG_MNG_ATFLG_ATTBL
) {
1614 ms_lib_erase_phyblock(us
, PhyBlock
);
1618 if (extdat
.logadr
!= MS_LB_NOT_USED
) {
1619 if ((extdat
.logadr
< LogStart
) || (LogEnde
<= extdat
.logadr
)) {
1620 ms_lib_erase_phyblock(us
, PhyBlock
);
1624 newblk
= ms_libconv_to_physical(info
, extdat
.logadr
);
1626 if (newblk
!= MS_LB_NOT_USED
) {
1627 if (extdat
.logadr
== 0) {
1628 ms_lib_set_logicalpair(us
, extdat
.logadr
, PhyBlock
);
1629 if (ms_lib_check_disableblock(us
, btBlk1st
)) {
1630 ms_lib_set_logicalpair(us
, extdat
.logadr
, newblk
);
1635 ms_lib_read_extra(us
, newblk
, 0, &extdat
);
1636 if ((extdat
.ovrflg
& MS_REG_OVR_UDST
) == MS_REG_OVR_UDST_UPDATING
) {
1637 ms_lib_erase_phyblock(us
, PhyBlock
);
1640 ms_lib_erase_phyblock(us
, newblk
);
1644 ms_lib_set_logicalpair(us
, extdat
.logadr
, PhyBlock
);
1649 return MS_STATUS_SUCCESS
;
1653 static int ms_scsi_read(struct us_data
*us
, struct scsi_cmnd
*srb
)
1656 unsigned char *cdb
= srb
->cmnd
;
1657 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1658 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1660 u32 bn
= ((cdb
[2] << 24) & 0xff000000) | ((cdb
[3] << 16) & 0x00ff0000) |
1661 ((cdb
[4] << 8) & 0x0000ff00) | ((cdb
[5] << 0) & 0x000000ff);
1662 u16 blen
= ((cdb
[7] << 8) & 0xff00) | ((cdb
[8] << 0) & 0x00ff);
1663 u32 blenByte
= blen
* 0x200;
1665 if (bn
> info
->bl_num
)
1666 return USB_STOR_TRANSPORT_ERROR
;
1668 if (info
->MS_Status
.IsMSPro
) {
1669 result
= ene_load_bincode(us
, MSP_RW_PATTERN
);
1670 if (result
!= USB_STOR_XFER_GOOD
) {
1671 usb_stor_dbg(us
, "Load MPS RW pattern Fail !!\n");
1672 return USB_STOR_TRANSPORT_ERROR
;
1675 /* set up the command wrapper */
1676 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1677 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1678 bcb
->DataTransferLength
= blenByte
;
1679 bcb
->Flags
= US_BULK_FLAG_IN
;
1682 bcb
->CDB
[5] = (unsigned char)(bn
);
1683 bcb
->CDB
[4] = (unsigned char)(bn
>>8);
1684 bcb
->CDB
[3] = (unsigned char)(bn
>>16);
1685 bcb
->CDB
[2] = (unsigned char)(bn
>>24);
1687 result
= ene_send_scsi_cmd(us
, FDIR_READ
, scsi_sglist(srb
), 1);
1696 buf
= kmalloc(blenByte
, GFP_KERNEL
);
1698 return USB_STOR_TRANSPORT_ERROR
;
1700 result
= ene_load_bincode(us
, MS_RW_PATTERN
);
1701 if (result
!= USB_STOR_XFER_GOOD
) {
1702 pr_info("Load MS RW pattern Fail !!\n");
1703 result
= USB_STOR_TRANSPORT_ERROR
;
1707 logblk
= (u16
)(bn
/ info
->MS_Lib
.PagesPerBlock
);
1708 PageNum
= (u8
)(bn
% info
->MS_Lib
.PagesPerBlock
);
1711 if (blen
> (info
->MS_Lib
.PagesPerBlock
-PageNum
))
1712 len
= info
->MS_Lib
.PagesPerBlock
-PageNum
;
1716 phyblk
= ms_libconv_to_physical(info
, logblk
);
1717 blkno
= phyblk
* 0x20 + PageNum
;
1719 /* set up the command wrapper */
1720 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1721 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1722 bcb
->DataTransferLength
= 0x200 * len
;
1723 bcb
->Flags
= US_BULK_FLAG_IN
;
1726 bcb
->CDB
[5] = (unsigned char)(blkno
);
1727 bcb
->CDB
[4] = (unsigned char)(blkno
>>8);
1728 bcb
->CDB
[3] = (unsigned char)(blkno
>>16);
1729 bcb
->CDB
[2] = (unsigned char)(blkno
>>24);
1731 result
= ene_send_scsi_cmd(us
, FDIR_READ
, buf
+offset
, 0);
1732 if (result
!= USB_STOR_XFER_GOOD
) {
1733 pr_info("MS_SCSI_Read --- result = %x\n", result
);
1734 result
= USB_STOR_TRANSPORT_ERROR
;
1743 offset
+= MS_BYTES_PER_PAGE
*len
;
1745 usb_stor_set_xfer_buf(buf
, blenByte
, srb
);
1752 static int ms_scsi_write(struct us_data
*us
, struct scsi_cmnd
*srb
)
1755 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1756 unsigned char *cdb
= srb
->cmnd
;
1757 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1759 u32 bn
= ((cdb
[2] << 24) & 0xff000000) |
1760 ((cdb
[3] << 16) & 0x00ff0000) |
1761 ((cdb
[4] << 8) & 0x0000ff00) |
1762 ((cdb
[5] << 0) & 0x000000ff);
1763 u16 blen
= ((cdb
[7] << 8) & 0xff00) | ((cdb
[8] << 0) & 0x00ff);
1764 u32 blenByte
= blen
* 0x200;
1766 if (bn
> info
->bl_num
)
1767 return USB_STOR_TRANSPORT_ERROR
;
1769 if (info
->MS_Status
.IsMSPro
) {
1770 result
= ene_load_bincode(us
, MSP_RW_PATTERN
);
1771 if (result
!= USB_STOR_XFER_GOOD
) {
1772 pr_info("Load MSP RW pattern Fail !!\n");
1773 return USB_STOR_TRANSPORT_ERROR
;
1776 /* set up the command wrapper */
1777 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1778 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1779 bcb
->DataTransferLength
= blenByte
;
1783 bcb
->CDB
[5] = (unsigned char)(bn
);
1784 bcb
->CDB
[4] = (unsigned char)(bn
>>8);
1785 bcb
->CDB
[3] = (unsigned char)(bn
>>16);
1786 bcb
->CDB
[2] = (unsigned char)(bn
>>24);
1788 result
= ene_send_scsi_cmd(us
, FDIR_WRITE
, scsi_sglist(srb
), 1);
1794 u16 len
, oldphy
, newphy
;
1796 buf
= kmalloc(blenByte
, GFP_KERNEL
);
1798 return USB_STOR_TRANSPORT_ERROR
;
1799 usb_stor_set_xfer_buf(buf
, blenByte
, srb
);
1801 result
= ene_load_bincode(us
, MS_RW_PATTERN
);
1802 if (result
!= USB_STOR_XFER_GOOD
) {
1803 pr_info("Load MS RW pattern Fail !!\n");
1804 result
= USB_STOR_TRANSPORT_ERROR
;
1808 PhyBlockAddr
= (u16
)(bn
/ info
->MS_Lib
.PagesPerBlock
);
1809 PageNum
= (u8
)(bn
% info
->MS_Lib
.PagesPerBlock
);
1812 if (blen
> (info
->MS_Lib
.PagesPerBlock
-PageNum
))
1813 len
= info
->MS_Lib
.PagesPerBlock
-PageNum
;
1817 oldphy
= ms_libconv_to_physical(info
, PhyBlockAddr
); /* need check us <-> info */
1818 newphy
= ms_libsearch_block_from_logical(us
, PhyBlockAddr
);
1820 result
= ms_read_copyblock(us
, oldphy
, newphy
, PhyBlockAddr
, PageNum
, buf
+offset
, len
);
1822 if (result
!= USB_STOR_XFER_GOOD
) {
1823 pr_info("MS_SCSI_Write --- result = %x\n", result
);
1824 result
= USB_STOR_TRANSPORT_ERROR
;
1828 info
->MS_Lib
.Phy2LogMap
[oldphy
] = MS_LB_NOT_USED_ERASED
;
1829 ms_lib_force_setlogical_pair(us
, PhyBlockAddr
, newphy
);
1836 offset
+= MS_BYTES_PER_PAGE
*len
;
1848 static int ene_get_card_type(struct us_data
*us
, u16 index
, void *buf
)
1850 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1853 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1854 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1855 bcb
->DataTransferLength
= 0x01;
1856 bcb
->Flags
= US_BULK_FLAG_IN
;
1858 bcb
->CDB
[2] = (unsigned char)(index
>>8);
1859 bcb
->CDB
[3] = (unsigned char)index
;
1861 result
= ene_send_scsi_cmd(us
, FDIR_READ
, buf
, 0);
1865 static int ene_get_card_status(struct us_data
*us
, u8
*buf
)
1869 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1871 /*usb_stor_dbg(us, "transport --- ENE_ReadSDReg\n");*/
1872 reg4b
= *(u32
*)&buf
[0x18];
1873 info
->SD_READ_BL_LEN
= (u8
)((reg4b
>> 8) & 0x0f);
1875 tmpreg
= (u16
) reg4b
;
1876 reg4b
= *(u32
*)(&buf
[0x14]);
1877 if (info
->SD_Status
.HiCapacity
&& !info
->SD_Status
.IsMMC
)
1878 info
->HC_C_SIZE
= (reg4b
>> 8) & 0x3fffff;
1880 info
->SD_C_SIZE
= ((tmpreg
& 0x03) << 10) | (u16
)(reg4b
>> 22);
1881 info
->SD_C_SIZE_MULT
= (u8
)(reg4b
>> 7) & 0x07;
1882 if (info
->SD_Status
.HiCapacity
&& info
->SD_Status
.IsMMC
)
1883 info
->HC_C_SIZE
= *(u32
*)(&buf
[0x100]);
1885 if (info
->SD_READ_BL_LEN
> SD_BLOCK_LEN
) {
1886 info
->SD_Block_Mult
= 1 << (info
->SD_READ_BL_LEN
-SD_BLOCK_LEN
);
1887 info
->SD_READ_BL_LEN
= SD_BLOCK_LEN
;
1889 info
->SD_Block_Mult
= 1;
1892 return USB_STOR_TRANSPORT_GOOD
;
1895 static int ene_load_bincode(struct us_data
*us
, unsigned char flag
)
1898 char *fw_name
= NULL
;
1899 unsigned char *buf
= NULL
;
1900 const struct firmware
*sd_fw
= NULL
;
1901 int result
= USB_STOR_TRANSPORT_ERROR
;
1902 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1903 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1905 if (info
->BIN_FLAG
== flag
)
1906 return USB_STOR_TRANSPORT_GOOD
;
1910 case SD_INIT1_PATTERN
:
1911 usb_stor_dbg(us
, "SD_INIT1_PATTERN\n");
1912 fw_name
= SD_INIT1_FIRMWARE
;
1914 case SD_INIT2_PATTERN
:
1915 usb_stor_dbg(us
, "SD_INIT2_PATTERN\n");
1916 fw_name
= SD_INIT2_FIRMWARE
;
1919 usb_stor_dbg(us
, "SD_RW_PATTERN\n");
1920 fw_name
= SD_RW_FIRMWARE
;
1923 case MS_INIT_PATTERN
:
1924 usb_stor_dbg(us
, "MS_INIT_PATTERN\n");
1925 fw_name
= MS_INIT_FIRMWARE
;
1927 case MSP_RW_PATTERN
:
1928 usb_stor_dbg(us
, "MSP_RW_PATTERN\n");
1929 fw_name
= MSP_RW_FIRMWARE
;
1932 usb_stor_dbg(us
, "MS_RW_PATTERN\n");
1933 fw_name
= MS_RW_FIRMWARE
;
1936 usb_stor_dbg(us
, "----------- Unknown PATTERN ----------\n");
1940 err
= request_firmware(&sd_fw
, fw_name
, &us
->pusb_dev
->dev
);
1942 usb_stor_dbg(us
, "load firmware %s failed\n", fw_name
);
1945 buf
= kmemdup(sd_fw
->data
, sd_fw
->size
, GFP_KERNEL
);
1949 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1950 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1951 bcb
->DataTransferLength
= sd_fw
->size
;
1955 result
= ene_send_scsi_cmd(us
, FDIR_WRITE
, buf
, 0);
1956 if (us
->srb
!= NULL
)
1957 scsi_set_resid(us
->srb
, 0);
1958 info
->BIN_FLAG
= flag
;
1962 release_firmware(sd_fw
);
1966 static int ms_card_init(struct us_data
*us
)
1970 unsigned char *PageBuffer0
= NULL
, *PageBuffer1
= NULL
;
1971 struct ms_lib_type_extdat extdat
;
1972 u16 btBlk1st
, btBlk2nd
;
1974 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1976 printk(KERN_INFO
"MS_CardInit start\n");
1978 ms_lib_free_allocatedarea(us
); /* Clean buffer and set struct us_data flag to 0 */
1980 /* get two PageBuffer */
1981 PageBuffer0
= kmalloc(MS_BYTES_PER_PAGE
, GFP_KERNEL
);
1982 PageBuffer1
= kmalloc(MS_BYTES_PER_PAGE
, GFP_KERNEL
);
1983 if ((PageBuffer0
== NULL
) || (PageBuffer1
== NULL
)) {
1984 result
= MS_NO_MEMORY_ERROR
;
1988 btBlk1st
= btBlk2nd
= MS_LB_NOT_USED
;
1991 for (TmpBlock
= 0; TmpBlock
< MS_MAX_INITIAL_ERROR_BLOCKS
+2; TmpBlock
++) {
1993 switch (ms_read_readpage(us
, TmpBlock
, 0, (u32
*)PageBuffer0
, &extdat
)) {
1994 case MS_STATUS_SUCCESS
:
1996 case MS_STATUS_INT_ERROR
:
1998 case MS_STATUS_ERROR
:
2003 if ((extdat
.ovrflg
& MS_REG_OVR_BKST
) == MS_REG_OVR_BKST_NG
)
2006 if (((extdat
.mngflg
& MS_REG_MNG_SYSFLG
) == MS_REG_MNG_SYSFLG_USER
) ||
2007 (be16_to_cpu(((struct ms_bootblock_page0
*)PageBuffer0
)->header
.wBlockID
) != MS_BOOT_BLOCK_ID
) ||
2008 (be16_to_cpu(((struct ms_bootblock_page0
*)PageBuffer0
)->header
.wFormatVersion
) != MS_BOOT_BLOCK_FORMAT_VERSION
) ||
2009 (((struct ms_bootblock_page0
*)PageBuffer0
)->header
.bNumberOfDataEntry
!= MS_BOOT_BLOCK_DATA_ENTRIES
))
2012 if (btBlk1st
!= MS_LB_NOT_USED
) {
2013 btBlk2nd
= TmpBlock
;
2017 btBlk1st
= TmpBlock
;
2018 memcpy(PageBuffer1
, PageBuffer0
, MS_BYTES_PER_PAGE
);
2019 if (extdat
.status1
& (MS_REG_ST1_DTER
| MS_REG_ST1_EXER
| MS_REG_ST1_FGER
))
2023 if (btBlk1st
== MS_LB_NOT_USED
) {
2024 result
= MS_STATUS_ERROR
;
2029 if ((extdat
.status0
& MS_REG_ST0_WP
) == MS_REG_ST0_WP_ON
)
2030 ms_lib_ctrl_set(info
, MS_LIB_CTRL_WRPROTECT
);
2032 result
= MS_STATUS_ERROR
;
2033 /* 1st Boot Block */
2034 if (btBlk1stErred
== 0)
2035 result
= ms_lib_process_bootblock(us
, btBlk1st
, PageBuffer1
);
2037 /* 2nd Boot Block */
2038 if (result
&& (btBlk2nd
!= MS_LB_NOT_USED
))
2039 result
= ms_lib_process_bootblock(us
, btBlk2nd
, PageBuffer0
);
2042 result
= MS_STATUS_ERROR
;
2046 for (TmpBlock
= 0; TmpBlock
< btBlk1st
; TmpBlock
++)
2047 info
->MS_Lib
.Phy2LogMap
[TmpBlock
] = MS_LB_INITIAL_ERROR
;
2049 info
->MS_Lib
.Phy2LogMap
[btBlk1st
] = MS_LB_BOOT_BLOCK
;
2051 if (btBlk2nd
!= MS_LB_NOT_USED
) {
2052 for (TmpBlock
= btBlk1st
+ 1; TmpBlock
< btBlk2nd
; TmpBlock
++)
2053 info
->MS_Lib
.Phy2LogMap
[TmpBlock
] = MS_LB_INITIAL_ERROR
;
2055 info
->MS_Lib
.Phy2LogMap
[btBlk2nd
] = MS_LB_BOOT_BLOCK
;
2058 result
= ms_lib_scan_logicalblocknumber(us
, btBlk1st
);
2062 for (TmpBlock
= MS_PHYSICAL_BLOCKS_PER_SEGMENT
;
2063 TmpBlock
< info
->MS_Lib
.NumberOfPhyBlock
;
2064 TmpBlock
+= MS_PHYSICAL_BLOCKS_PER_SEGMENT
) {
2065 if (ms_count_freeblock(us
, TmpBlock
) == 0) {
2066 ms_lib_ctrl_set(info
, MS_LIB_CTRL_WRPROTECT
);
2072 if (ms_lib_alloc_writebuf(us
)) {
2073 result
= MS_NO_MEMORY_ERROR
;
2077 result
= MS_STATUS_SUCCESS
;
2083 printk(KERN_INFO
"MS_CardInit end\n");
2087 static int ene_ms_init(struct us_data
*us
)
2089 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
2091 u16 MSP_BlockSize
, MSP_UserAreaBlocks
;
2092 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
2093 u8
*bbuf
= info
->bbuf
;
2095 printk(KERN_INFO
"transport --- ENE_MSInit\n");
2097 /* the same part to test ENE */
2099 result
= ene_load_bincode(us
, MS_INIT_PATTERN
);
2100 if (result
!= USB_STOR_XFER_GOOD
) {
2101 printk(KERN_ERR
"Load MS Init Code Fail !!\n");
2102 return USB_STOR_TRANSPORT_ERROR
;
2105 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
2106 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
2107 bcb
->DataTransferLength
= 0x200;
2108 bcb
->Flags
= US_BULK_FLAG_IN
;
2112 result
= ene_send_scsi_cmd(us
, FDIR_READ
, bbuf
, 0);
2113 if (result
!= USB_STOR_XFER_GOOD
) {
2114 printk(KERN_ERR
"Execution MS Init Code Fail !!\n");
2115 return USB_STOR_TRANSPORT_ERROR
;
2117 /* the same part to test ENE */
2118 info
->MS_Status
= *(struct MS_STATUS
*) bbuf
;
2120 if (info
->MS_Status
.Insert
&& info
->MS_Status
.Ready
) {
2121 printk(KERN_INFO
"Insert = %x\n", info
->MS_Status
.Insert
);
2122 printk(KERN_INFO
"Ready = %x\n", info
->MS_Status
.Ready
);
2123 printk(KERN_INFO
"IsMSPro = %x\n", info
->MS_Status
.IsMSPro
);
2124 printk(KERN_INFO
"IsMSPHG = %x\n", info
->MS_Status
.IsMSPHG
);
2125 printk(KERN_INFO
"WtP= %x\n", info
->MS_Status
.WtP
);
2126 if (info
->MS_Status
.IsMSPro
) {
2127 MSP_BlockSize
= (bbuf
[6] << 8) | bbuf
[7];
2128 MSP_UserAreaBlocks
= (bbuf
[10] << 8) | bbuf
[11];
2129 info
->MSP_TotalBlock
= MSP_BlockSize
* MSP_UserAreaBlocks
;
2131 ms_card_init(us
); /* Card is MS (to ms.c)*/
2133 usb_stor_dbg(us
, "MS Init Code OK !!\n");
2135 usb_stor_dbg(us
, "MS Card Not Ready --- %x\n", bbuf
[0]);
2136 return USB_STOR_TRANSPORT_ERROR
;
2139 return USB_STOR_TRANSPORT_GOOD
;
2142 static int ene_sd_init(struct us_data
*us
)
2145 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
2146 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
2147 u8
*bbuf
= info
->bbuf
;
2149 usb_stor_dbg(us
, "transport --- ENE_SDInit\n");
2150 /* SD Init Part-1 */
2151 result
= ene_load_bincode(us
, SD_INIT1_PATTERN
);
2152 if (result
!= USB_STOR_XFER_GOOD
) {
2153 usb_stor_dbg(us
, "Load SD Init Code Part-1 Fail !!\n");
2154 return USB_STOR_TRANSPORT_ERROR
;
2157 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
2158 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
2159 bcb
->Flags
= US_BULK_FLAG_IN
;
2162 result
= ene_send_scsi_cmd(us
, FDIR_READ
, NULL
, 0);
2163 if (result
!= USB_STOR_XFER_GOOD
) {
2164 usb_stor_dbg(us
, "Execution SD Init Code Fail !!\n");
2165 return USB_STOR_TRANSPORT_ERROR
;
2168 /* SD Init Part-2 */
2169 result
= ene_load_bincode(us
, SD_INIT2_PATTERN
);
2170 if (result
!= USB_STOR_XFER_GOOD
) {
2171 usb_stor_dbg(us
, "Load SD Init Code Part-2 Fail !!\n");
2172 return USB_STOR_TRANSPORT_ERROR
;
2175 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
2176 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
2177 bcb
->DataTransferLength
= 0x200;
2178 bcb
->Flags
= US_BULK_FLAG_IN
;
2181 result
= ene_send_scsi_cmd(us
, FDIR_READ
, bbuf
, 0);
2182 if (result
!= USB_STOR_XFER_GOOD
) {
2183 usb_stor_dbg(us
, "Execution SD Init Code Fail !!\n");
2184 return USB_STOR_TRANSPORT_ERROR
;
2187 info
->SD_Status
= *(struct SD_STATUS
*) bbuf
;
2188 if (info
->SD_Status
.Insert
&& info
->SD_Status
.Ready
) {
2189 struct SD_STATUS
*s
= &info
->SD_Status
;
2191 ene_get_card_status(us
, bbuf
);
2192 usb_stor_dbg(us
, "Insert = %x\n", s
->Insert
);
2193 usb_stor_dbg(us
, "Ready = %x\n", s
->Ready
);
2194 usb_stor_dbg(us
, "IsMMC = %x\n", s
->IsMMC
);
2195 usb_stor_dbg(us
, "HiCapacity = %x\n", s
->HiCapacity
);
2196 usb_stor_dbg(us
, "HiSpeed = %x\n", s
->HiSpeed
);
2197 usb_stor_dbg(us
, "WtP = %x\n", s
->WtP
);
2199 usb_stor_dbg(us
, "SD Card Not Ready --- %x\n", bbuf
[0]);
2200 return USB_STOR_TRANSPORT_ERROR
;
2202 return USB_STOR_TRANSPORT_GOOD
;
2206 static int ene_init(struct us_data
*us
)
2210 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)(us
->extra
);
2211 u8
*bbuf
= info
->bbuf
;
2213 result
= ene_get_card_type(us
, REG_CARD_STATUS
, bbuf
);
2214 if (result
!= USB_STOR_XFER_GOOD
)
2215 return USB_STOR_TRANSPORT_ERROR
;
2217 misc_reg03
= bbuf
[0];
2218 if (misc_reg03
& 0x01) {
2219 if (!info
->SD_Status
.Ready
) {
2220 result
= ene_sd_init(us
);
2221 if (result
!= USB_STOR_XFER_GOOD
)
2222 return USB_STOR_TRANSPORT_ERROR
;
2225 if (misc_reg03
& 0x02) {
2226 if (!info
->MS_Status
.Ready
) {
2227 result
= ene_ms_init(us
);
2228 if (result
!= USB_STOR_XFER_GOOD
)
2229 return USB_STOR_TRANSPORT_ERROR
;
2235 /*----- sd_scsi_irp() ---------*/
2236 static int sd_scsi_irp(struct us_data
*us
, struct scsi_cmnd
*srb
)
2239 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)us
->extra
;
2241 info
->SrbStatus
= SS_SUCCESS
;
2242 switch (srb
->cmnd
[0]) {
2243 case TEST_UNIT_READY
:
2244 result
= sd_scsi_test_unit_ready(us
, srb
);
2247 result
= sd_scsi_inquiry(us
, srb
);
2250 result
= sd_scsi_mode_sense(us
, srb
);
2254 result = SD_SCSI_Start_Stop(us, srb);
2258 result
= sd_scsi_read_capacity(us
, srb
);
2261 result
= sd_scsi_read(us
, srb
);
2264 result
= sd_scsi_write(us
, srb
);
2267 info
->SrbStatus
= SS_ILLEGAL_REQUEST
;
2268 result
= USB_STOR_TRANSPORT_FAILED
;
2277 static int ms_scsi_irp(struct us_data
*us
, struct scsi_cmnd
*srb
)
2280 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)us
->extra
;
2281 info
->SrbStatus
= SS_SUCCESS
;
2282 switch (srb
->cmnd
[0]) {
2283 case TEST_UNIT_READY
:
2284 result
= ms_scsi_test_unit_ready(us
, srb
);
2287 result
= ms_scsi_inquiry(us
, srb
);
2290 result
= ms_scsi_mode_sense(us
, srb
);
2293 result
= ms_scsi_read_capacity(us
, srb
);
2296 result
= ms_scsi_read(us
, srb
);
2299 result
= ms_scsi_write(us
, srb
);
2302 info
->SrbStatus
= SS_ILLEGAL_REQUEST
;
2303 result
= USB_STOR_TRANSPORT_FAILED
;
2309 static int ene_transport(struct scsi_cmnd
*srb
, struct us_data
*us
)
2311 int result
= USB_STOR_XFER_GOOD
;
2312 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)(us
->extra
);
2314 /*US_DEBUG(usb_stor_show_command(us, srb)); */
2315 scsi_set_resid(srb
, 0);
2316 if (unlikely(!(info
->SD_Status
.Ready
|| info
->MS_Status
.Ready
)))
2317 result
= ene_init(us
);
2318 if (result
== USB_STOR_XFER_GOOD
) {
2319 result
= USB_STOR_TRANSPORT_ERROR
;
2320 if (info
->SD_Status
.Ready
)
2321 result
= sd_scsi_irp(us
, srb
);
2323 if (info
->MS_Status
.Ready
)
2324 result
= ms_scsi_irp(us
, srb
);
2329 static struct scsi_host_template ene_ub6250_host_template
;
2331 static int ene_ub6250_probe(struct usb_interface
*intf
,
2332 const struct usb_device_id
*id
)
2337 struct ene_ub6250_info
*info
;
2339 result
= usb_stor_probe1(&us
, intf
, id
,
2340 (id
- ene_ub6250_usb_ids
) + ene_ub6250_unusual_dev_list
,
2341 &ene_ub6250_host_template
);
2345 /* FIXME: where should the code alloc extra buf ? */
2346 us
->extra
= kzalloc(sizeof(struct ene_ub6250_info
), GFP_KERNEL
);
2349 us
->extra_destructor
= ene_ub6250_info_destructor
;
2351 info
= (struct ene_ub6250_info
*)(us
->extra
);
2352 info
->bbuf
= kmalloc(512, GFP_KERNEL
);
2358 us
->transport_name
= "ene_ub6250";
2359 us
->transport
= ene_transport
;
2362 result
= usb_stor_probe2(us
);
2366 /* probe card type */
2367 result
= ene_get_card_type(us
, REG_CARD_STATUS
, info
->bbuf
);
2368 if (result
!= USB_STOR_XFER_GOOD
) {
2369 usb_stor_disconnect(intf
);
2370 return USB_STOR_TRANSPORT_ERROR
;
2373 misc_reg03
= info
->bbuf
[0];
2374 if (!(misc_reg03
& 0x01)) {
2375 pr_info("ums_eneub6250: This driver only supports SD/MS cards. "
2376 "It does not support SM cards.\n");
2385 static int ene_ub6250_resume(struct usb_interface
*iface
)
2388 struct us_data
*us
= usb_get_intfdata(iface
);
2389 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)(us
->extra
);
2391 mutex_lock(&us
->dev_mutex
);
2393 if (us
->suspend_resume_hook
)
2394 (us
->suspend_resume_hook
)(us
, US_RESUME
);
2396 mutex_unlock(&us
->dev_mutex
);
2398 info
->Power_IsResum
= true;
2399 /*info->SD_Status.Ready = 0; */
2400 info
->SD_Status
= *(struct SD_STATUS
*)&tmp
;
2401 info
->MS_Status
= *(struct MS_STATUS
*)&tmp
;
2402 info
->SM_Status
= *(struct SM_STATUS
*)&tmp
;
2407 static int ene_ub6250_reset_resume(struct usb_interface
*iface
)
2410 struct us_data
*us
= usb_get_intfdata(iface
);
2411 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)(us
->extra
);
2413 /* Report the reset to the SCSI core */
2414 usb_stor_reset_resume(iface
);
2416 /* FIXME: Notify the subdrivers that they need to reinitialize
2418 info
->Power_IsResum
= true;
2419 /*info->SD_Status.Ready = 0; */
2420 info
->SD_Status
= *(struct SD_STATUS
*)&tmp
;
2421 info
->MS_Status
= *(struct MS_STATUS
*)&tmp
;
2422 info
->SM_Status
= *(struct SM_STATUS
*)&tmp
;
2429 #define ene_ub6250_resume NULL
2430 #define ene_ub6250_reset_resume NULL
2434 static struct usb_driver ene_ub6250_driver
= {
2436 .probe
= ene_ub6250_probe
,
2437 .disconnect
= usb_stor_disconnect
,
2438 .suspend
= usb_stor_suspend
,
2439 .resume
= ene_ub6250_resume
,
2440 .reset_resume
= ene_ub6250_reset_resume
,
2441 .pre_reset
= usb_stor_pre_reset
,
2442 .post_reset
= usb_stor_post_reset
,
2443 .id_table
= ene_ub6250_usb_ids
,
2448 module_usb_stor_driver(ene_ub6250_driver
, ene_ub6250_host_template
, DRV_NAME
);