1 // SPDX-License-Identifier: GPL-2.0+
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2, or (at your option) any
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 675 Mass Ave, Cambridge, MA 02139, USA.
18 #include <linux/jiffies.h>
19 #include <linux/errno.h>
20 #include <linux/module.h>
21 #include <linux/slab.h>
23 #include <scsi/scsi.h>
24 #include <scsi/scsi_cmnd.h>
26 #include <linux/firmware.h>
29 #include "transport.h"
34 #define SD_INIT1_FIRMWARE "ene-ub6250/sd_init1.bin"
35 #define SD_INIT2_FIRMWARE "ene-ub6250/sd_init2.bin"
36 #define SD_RW_FIRMWARE "ene-ub6250/sd_rdwr.bin"
37 #define MS_INIT_FIRMWARE "ene-ub6250/ms_init.bin"
38 #define MSP_RW_FIRMWARE "ene-ub6250/msp_rdwr.bin"
39 #define MS_RW_FIRMWARE "ene-ub6250/ms_rdwr.bin"
41 #define DRV_NAME "ums_eneub6250"
43 MODULE_DESCRIPTION("Driver for ENE UB6250 reader");
44 MODULE_LICENSE("GPL");
45 MODULE_FIRMWARE(SD_INIT1_FIRMWARE
);
46 MODULE_FIRMWARE(SD_INIT2_FIRMWARE
);
47 MODULE_FIRMWARE(SD_RW_FIRMWARE
);
48 MODULE_FIRMWARE(MS_INIT_FIRMWARE
);
49 MODULE_FIRMWARE(MSP_RW_FIRMWARE
);
50 MODULE_FIRMWARE(MS_RW_FIRMWARE
);
53 * The table of devices
55 #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
56 vendorName, productName, useProtocol, useTransport, \
57 initFunction, flags) \
58 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
59 .driver_info = (flags)}
61 static struct usb_device_id ene_ub6250_usb_ids
[] = {
62 # include "unusual_ene_ub6250.h"
63 { } /* Terminating entry */
65 MODULE_DEVICE_TABLE(usb
, ene_ub6250_usb_ids
);
72 #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
73 vendor_name, product_name, use_protocol, use_transport, \
74 init_function, Flags) \
76 .vendorName = vendor_name, \
77 .productName = product_name, \
78 .useProtocol = use_protocol, \
79 .useTransport = use_transport, \
80 .initFunction = init_function, \
83 static struct us_unusual_dev ene_ub6250_unusual_dev_list
[] = {
84 # include "unusual_ene_ub6250.h"
85 { } /* Terminating entry */
92 /* ENE bin code len */
93 #define ENE_BIN_CODE_LEN 0x800
95 #define REG_CARD_STATUS 0xFF83
96 #define REG_HW_TRAP1 0xFF89
99 #define SS_SUCCESS 0x000000 /* No Sense */
100 #define SS_NOT_READY 0x023A00 /* Medium not present */
101 #define SS_MEDIUM_ERR 0x031100 /* Unrecovered read error */
102 #define SS_HW_ERR 0x040800 /* Communication failure */
103 #define SS_ILLEGAL_REQUEST 0x052000 /* Invalid command */
104 #define SS_UNIT_ATTENTION 0x062900 /* Reset occurred */
106 /* ENE Load FW Pattern */
107 #define SD_INIT1_PATTERN 1
108 #define SD_INIT2_PATTERN 2
109 #define SD_RW_PATTERN 3
110 #define MS_INIT_PATTERN 4
111 #define MSP_RW_PATTERN 5
112 #define MS_RW_PATTERN 6
113 #define SM_INIT_PATTERN 7
114 #define SM_RW_PATTERN 8
121 /* Status Register 1 */
122 #define MS_REG_ST1_MB 0x80 /* media busy */
123 #define MS_REG_ST1_FB1 0x40 /* flush busy 1 */
124 #define MS_REG_ST1_DTER 0x20 /* error on data(corrected) */
125 #define MS_REG_ST1_UCDT 0x10 /* unable to correct data */
126 #define MS_REG_ST1_EXER 0x08 /* error on extra(corrected) */
127 #define MS_REG_ST1_UCEX 0x04 /* unable to correct extra */
128 #define MS_REG_ST1_FGER 0x02 /* error on overwrite flag(corrected) */
129 #define MS_REG_ST1_UCFG 0x01 /* unable to correct overwrite flag */
130 #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)
133 #define MS_REG_OVR_BKST 0x80 /* block status */
134 #define MS_REG_OVR_BKST_OK MS_REG_OVR_BKST /* OK */
135 #define MS_REG_OVR_BKST_NG 0x00 /* NG */
136 #define MS_REG_OVR_PGST0 0x40 /* page status */
137 #define MS_REG_OVR_PGST1 0x20
138 #define MS_REG_OVR_PGST_MASK (MS_REG_OVR_PGST0 | MS_REG_OVR_PGST1)
139 #define MS_REG_OVR_PGST_OK (MS_REG_OVR_PGST0 | MS_REG_OVR_PGST1) /* OK */
140 #define MS_REG_OVR_PGST_NG MS_REG_OVR_PGST1 /* NG */
141 #define MS_REG_OVR_PGST_DATA_ERROR 0x00 /* data error */
142 #define MS_REG_OVR_UDST 0x10 /* update status */
143 #define MS_REG_OVR_UDST_UPDATING 0x00 /* updating */
144 #define MS_REG_OVR_UDST_NO_UPDATE MS_REG_OVR_UDST
145 #define MS_REG_OVR_RESERVED 0x08
146 #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)
148 /* Management Flag */
149 #define MS_REG_MNG_SCMS0 0x20 /* serial copy management system */
150 #define MS_REG_MNG_SCMS1 0x10
151 #define MS_REG_MNG_SCMS_MASK (MS_REG_MNG_SCMS0 | MS_REG_MNG_SCMS1)
152 #define MS_REG_MNG_SCMS_COPY_OK (MS_REG_MNG_SCMS0 | MS_REG_MNG_SCMS1)
153 #define MS_REG_MNG_SCMS_ONE_COPY MS_REG_MNG_SCMS1
154 #define MS_REG_MNG_SCMS_NO_COPY 0x00
155 #define MS_REG_MNG_ATFLG 0x08 /* address transfer table flag */
156 #define MS_REG_MNG_ATFLG_OTHER MS_REG_MNG_ATFLG /* other */
157 #define MS_REG_MNG_ATFLG_ATTBL 0x00 /* address transfer table */
158 #define MS_REG_MNG_SYSFLG 0x04 /* system flag */
159 #define MS_REG_MNG_SYSFLG_USER MS_REG_MNG_SYSFLG /* user block */
160 #define MS_REG_MNG_SYSFLG_BOOT 0x00 /* system block */
161 #define MS_REG_MNG_RESERVED 0xc3
162 #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)
165 #define MS_MAX_PAGES_PER_BLOCK 32
166 #define MS_MAX_INITIAL_ERROR_BLOCKS 10
167 #define MS_LIB_BITS_PER_BYTE 8
169 #define MS_SYSINF_FORMAT_FAT 1
170 #define MS_SYSINF_USAGE_GENERAL 0
172 #define MS_SYSINF_MSCLASS_TYPE_1 1
173 #define MS_SYSINF_PAGE_SIZE MS_BYTES_PER_PAGE /* fixed */
175 #define MS_SYSINF_CARDTYPE_RDONLY 1
176 #define MS_SYSINF_CARDTYPE_RDWR 2
177 #define MS_SYSINF_CARDTYPE_HYBRID 3
178 #define MS_SYSINF_SECURITY 0x01
179 #define MS_SYSINF_SECURITY_NO_SUPPORT MS_SYSINF_SECURITY
180 #define MS_SYSINF_SECURITY_SUPPORT 0
182 #define MS_SYSINF_RESERVED1 1
183 #define MS_SYSINF_RESERVED2 1
185 #define MS_SYSENT_TYPE_INVALID_BLOCK 0x01
186 #define MS_SYSENT_TYPE_CIS_IDI 0x0a /* CIS/IDI */
188 #define SIZE_OF_KIRO 1024
189 #define BYTE_MASK 0xff
192 #define MS_STATUS_WRITE_PROTECT 0x0106
193 #define MS_STATUS_SUCCESS 0x0000
194 #define MS_ERROR_FLASH_READ 0x8003
195 #define MS_ERROR_FLASH_ERASE 0x8005
196 #define MS_LB_ERROR 0xfff0
197 #define MS_LB_BOOT_BLOCK 0xfff1
198 #define MS_LB_INITIAL_ERROR 0xfff2
199 #define MS_STATUS_SUCCESS_WITH_ECC 0xfff3
200 #define MS_LB_ACQUIRED_ERROR 0xfff4
201 #define MS_LB_NOT_USED_ERASED 0xfff5
202 #define MS_NOCARD_ERROR 0xfff8
203 #define MS_NO_MEMORY_ERROR 0xfff9
204 #define MS_STATUS_INT_ERROR 0xfffa
205 #define MS_STATUS_ERROR 0xfffe
206 #define MS_LB_NOT_USED 0xffff
208 #define MS_REG_MNG_SYSFLG 0x04 /* system flag */
209 #define MS_REG_MNG_SYSFLG_USER MS_REG_MNG_SYSFLG /* user block */
211 #define MS_BOOT_BLOCK_ID 0x0001
212 #define MS_BOOT_BLOCK_FORMAT_VERSION 0x0100
213 #define MS_BOOT_BLOCK_DATA_ENTRIES 2
215 #define MS_NUMBER_OF_SYSTEM_ENTRY 4
216 #define MS_NUMBER_OF_BOOT_BLOCK 2
217 #define MS_BYTES_PER_PAGE 512
218 #define MS_LOGICAL_BLOCKS_PER_SEGMENT 496
219 #define MS_LOGICAL_BLOCKS_IN_1ST_SEGMENT 494
221 #define MS_PHYSICAL_BLOCKS_PER_SEGMENT 0x200 /* 512 */
222 #define MS_PHYSICAL_BLOCKS_PER_SEGMENT_MASK 0x1ff
225 #define MS_REG_OVR_BKST 0x80 /* block status */
226 #define MS_REG_OVR_BKST_OK MS_REG_OVR_BKST /* OK */
227 #define MS_REG_OVR_BKST_NG 0x00 /* NG */
229 /* Status Register 1 */
230 #define MS_REG_ST1_DTER 0x20 /* error on data(corrected) */
231 #define MS_REG_ST1_EXER 0x08 /* error on extra(corrected) */
232 #define MS_REG_ST1_FGER 0x02 /* error on overwrite flag(corrected) */
234 /* MemoryStick Register */
235 /* Status Register 0 */
236 #define MS_REG_ST0_WP 0x01 /* write protected */
237 #define MS_REG_ST0_WP_ON MS_REG_ST0_WP
239 #define MS_LIB_CTRL_RDONLY 0
240 #define MS_LIB_CTRL_WRPROTECT 1
243 #define ms_libconv_to_logical(pdx, PhyBlock) (((PhyBlock) >= (pdx)->MS_Lib.NumberOfPhyBlock) ? MS_STATUS_ERROR : (pdx)->MS_Lib.Phy2LogMap[PhyBlock])
244 #define ms_libconv_to_physical(pdx, LogBlock) (((LogBlock) >= (pdx)->MS_Lib.NumberOfLogBlock) ? MS_STATUS_ERROR : (pdx)->MS_Lib.Log2PhyMap[LogBlock])
246 #define ms_lib_ctrl_set(pdx, Flag) ((pdx)->MS_Lib.flags |= (1 << (Flag)))
247 #define ms_lib_ctrl_reset(pdx, Flag) ((pdx)->MS_Lib.flags &= ~(1 << (Flag)))
248 #define ms_lib_ctrl_check(pdx, Flag) ((pdx)->MS_Lib.flags & (1 << (Flag)))
250 #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))
251 #define ms_lib_clear_pagemap(pdx) memset((pdx)->MS_Lib.pagemap, 0, sizeof((pdx)->MS_Lib.pagemap))
252 #define memstick_logaddr(logadr1, logadr0) ((((u16)(logadr1)) << 8) | (logadr0))
286 struct ms_bootblock_cis
{
287 u8 bCistplDEVICE
[6]; /* 0 */
288 u8 bCistplDEVICE0C
[6]; /* 6 */
289 u8 bCistplJEDECC
[4]; /* 12 */
290 u8 bCistplMANFID
[6]; /* 16 */
291 u8 bCistplVER1
[32]; /* 22 */
292 u8 bCistplFUNCID
[4]; /* 54 */
293 u8 bCistplFUNCE0
[4]; /* 58 */
294 u8 bCistplFUNCE1
[5]; /* 62 */
295 u8 bCistplCONF
[7]; /* 67 */
296 u8 bCistplCFTBLENT0
[10];/* 74 */
297 u8 bCistplCFTBLENT1
[8]; /* 84 */
298 u8 bCistplCFTBLENT2
[12];/* 92 */
299 u8 bCistplCFTBLENT3
[8]; /* 104 */
300 u8 bCistplCFTBLENT4
[17];/* 112 */
301 u8 bCistplCFTBLENT5
[8]; /* 129 */
302 u8 bCistplCFTBLENT6
[17];/* 137 */
303 u8 bCistplCFTBLENT7
[8]; /* 154 */
304 u8 bCistplNOLINK
[3]; /* 162 */
307 struct ms_bootblock_idi
{
308 #define MS_IDI_GENERAL_CONF 0x848A
309 u16 wIDIgeneralConfiguration
; /* 0 */
310 u16 wIDInumberOfCylinder
; /* 1 */
311 u16 wIDIreserved0
; /* 2 */
312 u16 wIDInumberOfHead
; /* 3 */
313 u16 wIDIbytesPerTrack
; /* 4 */
314 u16 wIDIbytesPerSector
; /* 5 */
315 u16 wIDIsectorsPerTrack
; /* 6 */
316 u16 wIDItotalSectors
[2]; /* 7-8 high,low */
317 u16 wIDIreserved1
[11]; /* 9-19 */
318 u16 wIDIbufferType
; /* 20 */
319 u16 wIDIbufferSize
; /* 21 */
320 u16 wIDIlongCmdECC
; /* 22 */
321 u16 wIDIfirmVersion
[4]; /* 23-26 */
322 u16 wIDImodelName
[20]; /* 27-46 */
323 u16 wIDIreserved2
; /* 47 */
324 u16 wIDIlongWordSupported
; /* 48 */
325 u16 wIDIdmaSupported
; /* 49 */
326 u16 wIDIreserved3
; /* 50 */
327 u16 wIDIpioTiming
; /* 51 */
328 u16 wIDIdmaTiming
; /* 52 */
329 u16 wIDItransferParameter
; /* 53 */
330 u16 wIDIformattedCylinder
; /* 54 */
331 u16 wIDIformattedHead
; /* 55 */
332 u16 wIDIformattedSectorsPerTrack
;/* 56 */
333 u16 wIDIformattedTotalSectors
[2];/* 57-58 */
334 u16 wIDImultiSector
; /* 59 */
335 u16 wIDIlbaSectors
[2]; /* 60-61 */
336 u16 wIDIsingleWordDMA
; /* 62 */
337 u16 wIDImultiWordDMA
; /* 63 */
338 u16 wIDIreserved4
[192]; /* 64-255 */
341 struct ms_bootblock_sysent_rec
{
348 struct ms_bootblock_sysent
{
349 struct ms_bootblock_sysent_rec entry
[MS_NUMBER_OF_SYSTEM_ENTRY
];
352 struct ms_bootblock_sysinf
{
353 u8 bMsClass
; /* must be 1 */
354 u8 bCardType
; /* see below */
355 u16 wBlockSize
; /* n KB */
356 u16 wBlockNumber
; /* number of physical block */
357 u16 wTotalBlockNumber
; /* number of logical block */
358 u16 wPageSize
; /* must be 0x200 */
359 u8 bExtraSize
; /* 0x10 */
363 u8 bAssemblyMakerCode
;
364 u8 bAssemblyMachineCode
[3];
365 u16 wMemoryMakerCode
;
366 u16 wMemoryDeviceCode
;
372 u16 wControllerChipNumber
;
373 u16 wControllerFunction
; /* New MS */
374 u8 bReserved3
[9]; /* New MS */
375 u8 bParallelSupport
; /* New MS */
376 u16 wFormatValue
; /* New MS */
386 struct ms_bootblock_header
{
390 u8 bNumberOfDataEntry
;
394 struct ms_bootblock_page0
{
395 struct ms_bootblock_header header
;
396 struct ms_bootblock_sysent sysent
;
397 struct ms_bootblock_sysinf sysinf
;
400 struct ms_bootblock_cis_idi
{
402 struct ms_bootblock_cis cis
;
407 struct ms_bootblock_idi idi
;
413 /* ENE MS Lib struct */
414 struct ms_lib_type_extdat
{
427 u32 NumberOfCylinder
;
428 u32 SectorsPerCylinder
;
429 u16 cardType
; /* R/W, RO, Hybrid */
432 u16 NumberOfPhyBlock
;
433 u16 NumberOfLogBlock
;
435 u16
*Phy2LogMap
; /* phy2log table */
436 u16
*Log2PhyMap
; /* log2phy table */
438 unsigned char *pagemap
[(MS_MAX_PAGES_PER_BLOCK
+ (MS_LIB_BITS_PER_BYTE
-1)) / MS_LIB_BITS_PER_BYTE
];
439 unsigned char *blkpag
;
440 struct ms_lib_type_extdat
*blkext
;
441 unsigned char copybuf
[512];
445 /* SD Block Length */
446 /* 2^9 = 512 Bytes, The HW maximum read/write data length */
447 #define SD_BLOCK_LEN 9
449 struct ene_ub6250_info
{
451 /* I/O bounce buffer */
455 struct SD_STATUS SD_Status
;
456 struct MS_STATUS MS_Status
;
457 struct SM_STATUS SM_Status
;
459 /* ----- SD Control Data ---------------- */
460 /*SD_REGISTER SD_Regs; */
466 /* SD/MMC New spec. */
469 u8 SD20_HIGH_CAPACITY
;
473 u8 MMC_HIGH_CAPACITY
;
475 /*----- MS Control Data ---------------- */
478 struct ms_lib_ctrl MS_Lib
;
482 /*----- SM Control Data ---------------- */
486 unsigned char *testbuf
;
491 /*------Power Managerment ---------------*/
495 static int ene_sd_init(struct us_data
*us
);
496 static int ene_ms_init(struct us_data
*us
);
497 static int ene_load_bincode(struct us_data
*us
, unsigned char flag
);
499 static void ene_ub6250_info_destructor(void *extra
)
501 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) extra
;
508 static int ene_send_scsi_cmd(struct us_data
*us
, u8 fDir
, void *buf
, int use_sg
)
510 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
511 struct bulk_cs_wrap
*bcs
= (struct bulk_cs_wrap
*) us
->iobuf
;
514 unsigned int residue
;
515 unsigned int cswlen
= 0, partial
= 0;
516 unsigned int transfer_length
= bcb
->DataTransferLength
;
518 /* usb_stor_dbg(us, "transport --- ene_send_scsi_cmd\n"); */
519 /* send cmd to out endpoint */
520 result
= usb_stor_bulk_transfer_buf(us
, us
->send_bulk_pipe
,
521 bcb
, US_BULK_CB_WRAP_LEN
, NULL
);
522 if (result
!= USB_STOR_XFER_GOOD
) {
523 usb_stor_dbg(us
, "send cmd to out endpoint fail ---\n");
524 return USB_STOR_TRANSPORT_ERROR
;
528 unsigned int pipe
= fDir
;
530 if (fDir
== FDIR_READ
)
531 pipe
= us
->recv_bulk_pipe
;
533 pipe
= us
->send_bulk_pipe
;
537 result
= usb_stor_bulk_srb(us
, pipe
, us
->srb
);
539 result
= usb_stor_bulk_transfer_sg(us
, pipe
, buf
,
540 transfer_length
, 0, &partial
);
542 if (result
!= USB_STOR_XFER_GOOD
) {
543 usb_stor_dbg(us
, "data transfer fail ---\n");
544 return USB_STOR_TRANSPORT_ERROR
;
548 /* Get CSW for device status */
549 result
= usb_stor_bulk_transfer_buf(us
, us
->recv_bulk_pipe
, bcs
,
550 US_BULK_CS_WRAP_LEN
, &cswlen
);
552 if (result
== USB_STOR_XFER_SHORT
&& cswlen
== 0) {
553 usb_stor_dbg(us
, "Received 0-length CSW; retrying...\n");
554 result
= usb_stor_bulk_transfer_buf(us
, us
->recv_bulk_pipe
,
555 bcs
, US_BULK_CS_WRAP_LEN
, &cswlen
);
558 if (result
== USB_STOR_XFER_STALLED
) {
559 /* get the status again */
560 usb_stor_dbg(us
, "Attempting to get CSW (2nd try)...\n");
561 result
= usb_stor_bulk_transfer_buf(us
, us
->recv_bulk_pipe
,
562 bcs
, US_BULK_CS_WRAP_LEN
, NULL
);
565 if (result
!= USB_STOR_XFER_GOOD
)
566 return USB_STOR_TRANSPORT_ERROR
;
568 /* check bulk status */
569 residue
= le32_to_cpu(bcs
->Residue
);
572 * try to compute the actual residue, based on how much data
573 * was really transferred and what the device tells us
575 if (residue
&& !(us
->fflags
& US_FL_IGNORE_RESIDUE
)) {
576 residue
= min(residue
, transfer_length
);
578 scsi_set_resid(us
->srb
, max(scsi_get_resid(us
->srb
),
582 if (bcs
->Status
!= US_BULK_STAT_OK
)
583 return USB_STOR_TRANSPORT_ERROR
;
585 return USB_STOR_TRANSPORT_GOOD
;
588 static int do_scsi_request_sense(struct us_data
*us
, struct scsi_cmnd
*srb
)
590 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
591 unsigned char buf
[18];
594 buf
[0] = 0x70; /* Current error */
595 buf
[2] = info
->SrbStatus
>> 16; /* Sense key */
596 buf
[7] = 10; /* Additional length */
597 buf
[12] = info
->SrbStatus
>> 8; /* ASC */
598 buf
[13] = info
->SrbStatus
; /* ASCQ */
600 usb_stor_set_xfer_buf(buf
, sizeof(buf
), srb
);
601 return USB_STOR_TRANSPORT_GOOD
;
604 static int do_scsi_inquiry(struct us_data
*us
, struct scsi_cmnd
*srb
)
606 unsigned char data_ptr
[36] = {
607 0x00, 0x00, 0x02, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x55,
608 0x53, 0x42, 0x32, 0x2E, 0x30, 0x20, 0x20, 0x43, 0x61,
609 0x72, 0x64, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20,
610 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x30, 0x30 };
612 usb_stor_set_xfer_buf(data_ptr
, 36, srb
);
613 return USB_STOR_TRANSPORT_GOOD
;
616 static int sd_scsi_test_unit_ready(struct us_data
*us
, struct scsi_cmnd
*srb
)
618 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
620 if (info
->SD_Status
.Insert
&& info
->SD_Status
.Ready
)
621 return USB_STOR_TRANSPORT_GOOD
;
624 return USB_STOR_TRANSPORT_GOOD
;
627 return USB_STOR_TRANSPORT_GOOD
;
630 static int sd_scsi_mode_sense(struct us_data
*us
, struct scsi_cmnd
*srb
)
632 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
633 unsigned char mediaNoWP
[12] = {
634 0x0b, 0x00, 0x00, 0x08, 0x00, 0x00,
635 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
636 unsigned char mediaWP
[12] = {
637 0x0b, 0x00, 0x80, 0x08, 0x00, 0x00,
638 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
640 if (info
->SD_Status
.WtP
)
641 usb_stor_set_xfer_buf(mediaWP
, 12, srb
);
643 usb_stor_set_xfer_buf(mediaNoWP
, 12, srb
);
646 return USB_STOR_TRANSPORT_GOOD
;
649 static int sd_scsi_read_capacity(struct us_data
*us
, struct scsi_cmnd
*srb
)
653 unsigned int offset
= 0;
654 unsigned char buf
[8];
655 struct scatterlist
*sg
= NULL
;
656 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
658 usb_stor_dbg(us
, "sd_scsi_read_capacity\n");
659 if (info
->SD_Status
.HiCapacity
) {
661 if (info
->SD_Status
.IsMMC
)
662 bl_num
= info
->HC_C_SIZE
-1;
664 bl_num
= (info
->HC_C_SIZE
+ 1) * 1024 - 1;
666 bl_len
= 1 << (info
->SD_READ_BL_LEN
);
667 bl_num
= info
->SD_Block_Mult
* (info
->SD_C_SIZE
+ 1)
668 * (1 << (info
->SD_C_SIZE_MULT
+ 2)) - 1;
670 info
->bl_num
= bl_num
;
671 usb_stor_dbg(us
, "bl_len = %x\n", bl_len
);
672 usb_stor_dbg(us
, "bl_num = %x\n", bl_num
);
674 /*srb->request_bufflen = 8; */
675 buf
[0] = (bl_num
>> 24) & 0xff;
676 buf
[1] = (bl_num
>> 16) & 0xff;
677 buf
[2] = (bl_num
>> 8) & 0xff;
678 buf
[3] = (bl_num
>> 0) & 0xff;
679 buf
[4] = (bl_len
>> 24) & 0xff;
680 buf
[5] = (bl_len
>> 16) & 0xff;
681 buf
[6] = (bl_len
>> 8) & 0xff;
682 buf
[7] = (bl_len
>> 0) & 0xff;
684 usb_stor_access_xfer_buf(buf
, 8, srb
, &sg
, &offset
, TO_XFER_BUF
);
686 return USB_STOR_TRANSPORT_GOOD
;
689 static int sd_scsi_read(struct us_data
*us
, struct scsi_cmnd
*srb
)
692 unsigned char *cdb
= srb
->cmnd
;
693 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
694 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
696 u32 bn
= ((cdb
[2] << 24) & 0xff000000) | ((cdb
[3] << 16) & 0x00ff0000) |
697 ((cdb
[4] << 8) & 0x0000ff00) | ((cdb
[5] << 0) & 0x000000ff);
698 u16 blen
= ((cdb
[7] << 8) & 0xff00) | ((cdb
[8] << 0) & 0x00ff);
699 u32 bnByte
= bn
* 0x200;
700 u32 blenByte
= blen
* 0x200;
702 if (bn
> info
->bl_num
)
703 return USB_STOR_TRANSPORT_ERROR
;
705 result
= ene_load_bincode(us
, SD_RW_PATTERN
);
706 if (result
!= USB_STOR_XFER_GOOD
) {
707 usb_stor_dbg(us
, "Load SD RW pattern Fail !!\n");
708 return USB_STOR_TRANSPORT_ERROR
;
711 if (info
->SD_Status
.HiCapacity
)
714 /* set up the command wrapper */
715 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
716 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
717 bcb
->DataTransferLength
= blenByte
;
718 bcb
->Flags
= US_BULK_FLAG_IN
;
720 bcb
->CDB
[5] = (unsigned char)(bnByte
);
721 bcb
->CDB
[4] = (unsigned char)(bnByte
>>8);
722 bcb
->CDB
[3] = (unsigned char)(bnByte
>>16);
723 bcb
->CDB
[2] = (unsigned char)(bnByte
>>24);
725 result
= ene_send_scsi_cmd(us
, FDIR_READ
, scsi_sglist(srb
), 1);
729 static int sd_scsi_write(struct us_data
*us
, struct scsi_cmnd
*srb
)
732 unsigned char *cdb
= srb
->cmnd
;
733 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
734 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
736 u32 bn
= ((cdb
[2] << 24) & 0xff000000) | ((cdb
[3] << 16) & 0x00ff0000) |
737 ((cdb
[4] << 8) & 0x0000ff00) | ((cdb
[5] << 0) & 0x000000ff);
738 u16 blen
= ((cdb
[7] << 8) & 0xff00) | ((cdb
[8] << 0) & 0x00ff);
739 u32 bnByte
= bn
* 0x200;
740 u32 blenByte
= blen
* 0x200;
742 if (bn
> info
->bl_num
)
743 return USB_STOR_TRANSPORT_ERROR
;
745 result
= ene_load_bincode(us
, SD_RW_PATTERN
);
746 if (result
!= USB_STOR_XFER_GOOD
) {
747 usb_stor_dbg(us
, "Load SD RW pattern Fail !!\n");
748 return USB_STOR_TRANSPORT_ERROR
;
751 if (info
->SD_Status
.HiCapacity
)
754 /* set up the command wrapper */
755 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
756 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
757 bcb
->DataTransferLength
= blenByte
;
760 bcb
->CDB
[5] = (unsigned char)(bnByte
);
761 bcb
->CDB
[4] = (unsigned char)(bnByte
>>8);
762 bcb
->CDB
[3] = (unsigned char)(bnByte
>>16);
763 bcb
->CDB
[2] = (unsigned char)(bnByte
>>24);
765 result
= ene_send_scsi_cmd(us
, FDIR_WRITE
, scsi_sglist(srb
), 1);
773 static int ms_lib_set_logicalpair(struct us_data
*us
, u16 logblk
, u16 phyblk
)
775 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
777 if ((logblk
>= info
->MS_Lib
.NumberOfLogBlock
) || (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
))
780 info
->MS_Lib
.Phy2LogMap
[phyblk
] = logblk
;
781 info
->MS_Lib
.Log2PhyMap
[logblk
] = phyblk
;
786 static int ms_lib_set_logicalblockmark(struct us_data
*us
, u16 phyblk
, u16 mark
)
788 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
790 if (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
)
793 info
->MS_Lib
.Phy2LogMap
[phyblk
] = mark
;
798 static int ms_lib_set_initialerrorblock(struct us_data
*us
, u16 phyblk
)
800 return ms_lib_set_logicalblockmark(us
, phyblk
, MS_LB_INITIAL_ERROR
);
803 static int ms_lib_set_bootblockmark(struct us_data
*us
, u16 phyblk
)
805 return ms_lib_set_logicalblockmark(us
, phyblk
, MS_LB_BOOT_BLOCK
);
808 static int ms_lib_free_logicalmap(struct us_data
*us
)
810 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
812 kfree(info
->MS_Lib
.Phy2LogMap
);
813 info
->MS_Lib
.Phy2LogMap
= NULL
;
815 kfree(info
->MS_Lib
.Log2PhyMap
);
816 info
->MS_Lib
.Log2PhyMap
= NULL
;
821 static int ms_lib_alloc_logicalmap(struct us_data
*us
)
824 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
826 info
->MS_Lib
.Phy2LogMap
= kmalloc(info
->MS_Lib
.NumberOfPhyBlock
* sizeof(u16
), GFP_KERNEL
);
827 info
->MS_Lib
.Log2PhyMap
= kmalloc(info
->MS_Lib
.NumberOfLogBlock
* sizeof(u16
), GFP_KERNEL
);
829 if ((info
->MS_Lib
.Phy2LogMap
== NULL
) || (info
->MS_Lib
.Log2PhyMap
== NULL
)) {
830 ms_lib_free_logicalmap(us
);
834 for (i
= 0; i
< info
->MS_Lib
.NumberOfPhyBlock
; i
++)
835 info
->MS_Lib
.Phy2LogMap
[i
] = MS_LB_NOT_USED
;
837 for (i
= 0; i
< info
->MS_Lib
.NumberOfLogBlock
; i
++)
838 info
->MS_Lib
.Log2PhyMap
[i
] = MS_LB_NOT_USED
;
843 static void ms_lib_clear_writebuf(struct us_data
*us
)
846 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
848 info
->MS_Lib
.wrtblk
= (u16
)-1;
849 ms_lib_clear_pagemap(info
);
851 if (info
->MS_Lib
.blkpag
)
852 memset(info
->MS_Lib
.blkpag
, 0xff, info
->MS_Lib
.PagesPerBlock
* info
->MS_Lib
.BytesPerSector
);
854 if (info
->MS_Lib
.blkext
) {
855 for (i
= 0; i
< info
->MS_Lib
.PagesPerBlock
; i
++) {
856 info
->MS_Lib
.blkext
[i
].status1
= MS_REG_ST1_DEFAULT
;
857 info
->MS_Lib
.blkext
[i
].ovrflg
= MS_REG_OVR_DEFAULT
;
858 info
->MS_Lib
.blkext
[i
].mngflg
= MS_REG_MNG_DEFAULT
;
859 info
->MS_Lib
.blkext
[i
].logadr
= MS_LB_NOT_USED
;
864 static int ms_count_freeblock(struct us_data
*us
, u16 PhyBlock
)
867 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
869 Ende
= PhyBlock
+ MS_PHYSICAL_BLOCKS_PER_SEGMENT
;
870 for (Count
= 0; PhyBlock
< Ende
; PhyBlock
++) {
871 switch (info
->MS_Lib
.Phy2LogMap
[PhyBlock
]) {
873 case MS_LB_NOT_USED_ERASED
:
883 static int ms_read_readpage(struct us_data
*us
, u32 PhyBlockAddr
,
884 u8 PageNum
, u32
*PageBuf
, struct ms_lib_type_extdat
*ExtraDat
)
886 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
887 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
888 u8
*bbuf
= info
->bbuf
;
890 u32 bn
= PhyBlockAddr
* 0x20 + PageNum
;
892 result
= ene_load_bincode(us
, MS_RW_PATTERN
);
893 if (result
!= USB_STOR_XFER_GOOD
)
894 return USB_STOR_TRANSPORT_ERROR
;
897 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
898 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
899 bcb
->DataTransferLength
= 0x200;
900 bcb
->Flags
= US_BULK_FLAG_IN
;
903 bcb
->CDB
[1] = 0x02; /* in init.c ENE_MSInit() is 0x01 */
905 bcb
->CDB
[5] = (unsigned char)(bn
);
906 bcb
->CDB
[4] = (unsigned char)(bn
>>8);
907 bcb
->CDB
[3] = (unsigned char)(bn
>>16);
908 bcb
->CDB
[2] = (unsigned char)(bn
>>24);
910 result
= ene_send_scsi_cmd(us
, FDIR_READ
, PageBuf
, 0);
911 if (result
!= USB_STOR_XFER_GOOD
)
912 return USB_STOR_TRANSPORT_ERROR
;
915 /* Read Extra Data */
916 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
917 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
918 bcb
->DataTransferLength
= 0x4;
919 bcb
->Flags
= US_BULK_FLAG_IN
;
923 bcb
->CDB
[5] = (unsigned char)(PageNum
);
924 bcb
->CDB
[4] = (unsigned char)(PhyBlockAddr
);
925 bcb
->CDB
[3] = (unsigned char)(PhyBlockAddr
>>8);
926 bcb
->CDB
[2] = (unsigned char)(PhyBlockAddr
>>16);
929 result
= ene_send_scsi_cmd(us
, FDIR_READ
, bbuf
, 0);
930 if (result
!= USB_STOR_XFER_GOOD
)
931 return USB_STOR_TRANSPORT_ERROR
;
933 ExtraDat
->reserved
= 0;
934 ExtraDat
->intr
= 0x80; /* Not yet,fireware support */
935 ExtraDat
->status0
= 0x10; /* Not yet,fireware support */
937 ExtraDat
->status1
= 0x00; /* Not yet,fireware support */
938 ExtraDat
->ovrflg
= bbuf
[0];
939 ExtraDat
->mngflg
= bbuf
[1];
940 ExtraDat
->logadr
= memstick_logaddr(bbuf
[2], bbuf
[3]);
942 return USB_STOR_TRANSPORT_GOOD
;
945 static int ms_lib_process_bootblock(struct us_data
*us
, u16 PhyBlock
, u8
*PageData
)
947 struct ms_bootblock_sysent
*SysEntry
;
948 struct ms_bootblock_sysinf
*SysInfo
;
952 struct ms_lib_type_extdat ExtraData
;
953 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
955 PageBuffer
= kmalloc(MS_BYTES_PER_PAGE
, GFP_KERNEL
);
956 if (PageBuffer
== NULL
)
961 SysInfo
= &(((struct ms_bootblock_page0
*)PageData
)->sysinf
);
963 if ((SysInfo
->bMsClass
!= MS_SYSINF_MSCLASS_TYPE_1
) ||
964 (be16_to_cpu(SysInfo
->wPageSize
) != MS_SYSINF_PAGE_SIZE
) ||
965 ((SysInfo
->bSecuritySupport
& MS_SYSINF_SECURITY
) == MS_SYSINF_SECURITY_SUPPORT
) ||
966 (SysInfo
->bReserved1
!= MS_SYSINF_RESERVED1
) ||
967 (SysInfo
->bReserved2
!= MS_SYSINF_RESERVED2
) ||
968 (SysInfo
->bFormatType
!= MS_SYSINF_FORMAT_FAT
) ||
969 (SysInfo
->bUsage
!= MS_SYSINF_USAGE_GENERAL
))
972 switch (info
->MS_Lib
.cardType
= SysInfo
->bCardType
) {
973 case MS_SYSINF_CARDTYPE_RDONLY
:
974 ms_lib_ctrl_set(info
, MS_LIB_CTRL_RDONLY
);
976 case MS_SYSINF_CARDTYPE_RDWR
:
977 ms_lib_ctrl_reset(info
, MS_LIB_CTRL_RDONLY
);
979 case MS_SYSINF_CARDTYPE_HYBRID
:
984 info
->MS_Lib
.blockSize
= be16_to_cpu(SysInfo
->wBlockSize
);
985 info
->MS_Lib
.NumberOfPhyBlock
= be16_to_cpu(SysInfo
->wBlockNumber
);
986 info
->MS_Lib
.NumberOfLogBlock
= be16_to_cpu(SysInfo
->wTotalBlockNumber
)-2;
987 info
->MS_Lib
.PagesPerBlock
= info
->MS_Lib
.blockSize
* SIZE_OF_KIRO
/ MS_BYTES_PER_PAGE
;
988 info
->MS_Lib
.NumberOfSegment
= info
->MS_Lib
.NumberOfPhyBlock
/ MS_PHYSICAL_BLOCKS_PER_SEGMENT
;
989 info
->MS_Model
= be16_to_cpu(SysInfo
->wMemorySize
);
991 /*Allocate to all number of logicalblock and physicalblock */
992 if (ms_lib_alloc_logicalmap(us
))
995 /* Mark the book block */
996 ms_lib_set_bootblockmark(us
, PhyBlock
);
998 SysEntry
= &(((struct ms_bootblock_page0
*)PageData
)->sysent
);
1000 for (i
= 0; i
< MS_NUMBER_OF_SYSTEM_ENTRY
; i
++) {
1001 u32 EntryOffset
, EntrySize
;
1003 EntryOffset
= be32_to_cpu(SysEntry
->entry
[i
].dwStart
);
1005 if (EntryOffset
== 0xffffff)
1007 EntrySize
= be32_to_cpu(SysEntry
->entry
[i
].dwSize
);
1012 if (EntryOffset
+ MS_BYTES_PER_PAGE
+ EntrySize
> info
->MS_Lib
.blockSize
* (u32
)SIZE_OF_KIRO
)
1016 u8 PrevPageNumber
= 0;
1019 if (SysEntry
->entry
[i
].bType
!= MS_SYSENT_TYPE_INVALID_BLOCK
)
1022 while (EntrySize
> 0) {
1024 PageNumber
= (u8
)(EntryOffset
/ MS_BYTES_PER_PAGE
+ 1);
1025 if (PageNumber
!= PrevPageNumber
) {
1026 switch (ms_read_readpage(us
, PhyBlock
, PageNumber
, (u32
*)PageBuffer
, &ExtraData
)) {
1027 case MS_STATUS_SUCCESS
:
1029 case MS_STATUS_WRITE_PROTECT
:
1030 case MS_ERROR_FLASH_READ
:
1031 case MS_STATUS_ERROR
:
1036 PrevPageNumber
= PageNumber
;
1039 phyblk
= be16_to_cpu(*(u16
*)(PageBuffer
+ (EntryOffset
% MS_BYTES_PER_PAGE
)));
1040 if (phyblk
< 0x0fff)
1041 ms_lib_set_initialerrorblock(us
, phyblk
);
1046 } else if (i
== 1) { /* CIS/IDI */
1047 struct ms_bootblock_idi
*idi
;
1049 if (SysEntry
->entry
[i
].bType
!= MS_SYSENT_TYPE_CIS_IDI
)
1052 switch (ms_read_readpage(us
, PhyBlock
, (u8
)(EntryOffset
/ MS_BYTES_PER_PAGE
+ 1), (u32
*)PageBuffer
, &ExtraData
)) {
1053 case MS_STATUS_SUCCESS
:
1055 case MS_STATUS_WRITE_PROTECT
:
1056 case MS_ERROR_FLASH_READ
:
1057 case MS_STATUS_ERROR
:
1062 idi
= &((struct ms_bootblock_cis_idi
*)(PageBuffer
+ (EntryOffset
% MS_BYTES_PER_PAGE
)))->idi
.idi
;
1063 if (le16_to_cpu(idi
->wIDIgeneralConfiguration
) != MS_IDI_GENERAL_CONF
)
1066 info
->MS_Lib
.BytesPerSector
= le16_to_cpu(idi
->wIDIbytesPerSector
);
1067 if (info
->MS_Lib
.BytesPerSector
!= MS_BYTES_PER_PAGE
)
1076 ms_lib_free_logicalmap(us
);
1084 static void ms_lib_free_writebuf(struct us_data
*us
)
1086 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1087 info
->MS_Lib
.wrtblk
= (u16
)-1; /* set to -1 */
1089 /* memset((fdoExt)->MS_Lib.pagemap, 0, sizeof((fdoExt)->MS_Lib.pagemap)) */
1091 ms_lib_clear_pagemap(info
); /* (pdx)->MS_Lib.pagemap memset 0 in ms.h */
1093 if (info
->MS_Lib
.blkpag
) {
1094 kfree(info
->MS_Lib
.blkpag
); /* Arnold test ... */
1095 info
->MS_Lib
.blkpag
= NULL
;
1098 if (info
->MS_Lib
.blkext
) {
1099 kfree(info
->MS_Lib
.blkext
); /* Arnold test ... */
1100 info
->MS_Lib
.blkext
= NULL
;
1105 static void ms_lib_free_allocatedarea(struct us_data
*us
)
1107 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1109 ms_lib_free_writebuf(us
); /* Free MS_Lib.pagemap */
1110 ms_lib_free_logicalmap(us
); /* kfree MS_Lib.Phy2LogMap and MS_Lib.Log2PhyMap */
1112 /* set struct us point flag to 0 */
1113 info
->MS_Lib
.flags
= 0;
1114 info
->MS_Lib
.BytesPerSector
= 0;
1115 info
->MS_Lib
.SectorsPerCylinder
= 0;
1117 info
->MS_Lib
.cardType
= 0;
1118 info
->MS_Lib
.blockSize
= 0;
1119 info
->MS_Lib
.PagesPerBlock
= 0;
1121 info
->MS_Lib
.NumberOfPhyBlock
= 0;
1122 info
->MS_Lib
.NumberOfLogBlock
= 0;
1126 static int ms_lib_alloc_writebuf(struct us_data
*us
)
1128 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1130 info
->MS_Lib
.wrtblk
= (u16
)-1;
1132 info
->MS_Lib
.blkpag
= kmalloc(info
->MS_Lib
.PagesPerBlock
* info
->MS_Lib
.BytesPerSector
, GFP_KERNEL
);
1133 info
->MS_Lib
.blkext
= kmalloc(info
->MS_Lib
.PagesPerBlock
* sizeof(struct ms_lib_type_extdat
), GFP_KERNEL
);
1135 if ((info
->MS_Lib
.blkpag
== NULL
) || (info
->MS_Lib
.blkext
== NULL
)) {
1136 ms_lib_free_writebuf(us
);
1140 ms_lib_clear_writebuf(us
);
1145 static int ms_lib_force_setlogical_pair(struct us_data
*us
, u16 logblk
, u16 phyblk
)
1147 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1149 if (logblk
== MS_LB_NOT_USED
)
1152 if ((logblk
>= info
->MS_Lib
.NumberOfLogBlock
) ||
1153 (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
))
1156 info
->MS_Lib
.Phy2LogMap
[phyblk
] = logblk
;
1157 info
->MS_Lib
.Log2PhyMap
[logblk
] = phyblk
;
1162 static int ms_read_copyblock(struct us_data
*us
, u16 oldphy
, u16 newphy
,
1163 u16 PhyBlockAddr
, u8 PageNum
, unsigned char *buf
, u16 len
)
1165 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1168 result
= ene_load_bincode(us
, MS_RW_PATTERN
);
1169 if (result
!= USB_STOR_XFER_GOOD
)
1170 return USB_STOR_TRANSPORT_ERROR
;
1172 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1173 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1174 bcb
->DataTransferLength
= 0x200*len
;
1178 bcb
->CDB
[4] = (unsigned char)(oldphy
);
1179 bcb
->CDB
[3] = (unsigned char)(oldphy
>>8);
1180 bcb
->CDB
[2] = 0; /* (BYTE)(oldphy>>16) */
1181 bcb
->CDB
[7] = (unsigned char)(newphy
);
1182 bcb
->CDB
[6] = (unsigned char)(newphy
>>8);
1183 bcb
->CDB
[5] = 0; /* (BYTE)(newphy>>16) */
1184 bcb
->CDB
[9] = (unsigned char)(PhyBlockAddr
);
1185 bcb
->CDB
[8] = (unsigned char)(PhyBlockAddr
>>8);
1186 bcb
->CDB
[10] = PageNum
;
1188 result
= ene_send_scsi_cmd(us
, FDIR_WRITE
, buf
, 0);
1189 if (result
!= USB_STOR_XFER_GOOD
)
1190 return USB_STOR_TRANSPORT_ERROR
;
1192 return USB_STOR_TRANSPORT_GOOD
;
1195 static int ms_read_eraseblock(struct us_data
*us
, u32 PhyBlockAddr
)
1197 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1199 u32 bn
= PhyBlockAddr
;
1201 result
= ene_load_bincode(us
, MS_RW_PATTERN
);
1202 if (result
!= USB_STOR_XFER_GOOD
)
1203 return USB_STOR_TRANSPORT_ERROR
;
1205 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1206 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1207 bcb
->DataTransferLength
= 0x200;
1208 bcb
->Flags
= US_BULK_FLAG_IN
;
1211 bcb
->CDB
[4] = (unsigned char)(bn
);
1212 bcb
->CDB
[3] = (unsigned char)(bn
>>8);
1213 bcb
->CDB
[2] = (unsigned char)(bn
>>16);
1215 result
= ene_send_scsi_cmd(us
, FDIR_READ
, NULL
, 0);
1216 if (result
!= USB_STOR_XFER_GOOD
)
1217 return USB_STOR_TRANSPORT_ERROR
;
1219 return USB_STOR_TRANSPORT_GOOD
;
1222 static int ms_lib_check_disableblock(struct us_data
*us
, u16 PhyBlock
)
1224 unsigned char *PageBuf
= NULL
;
1225 u16 result
= MS_STATUS_SUCCESS
;
1227 struct ms_lib_type_extdat extdat
;
1228 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1230 PageBuf
= kmalloc(MS_BYTES_PER_PAGE
, GFP_KERNEL
);
1231 if (PageBuf
== NULL
) {
1232 result
= MS_NO_MEMORY_ERROR
;
1236 ms_read_readpage(us
, PhyBlock
, 1, (u32
*)PageBuf
, &extdat
);
1238 blk
= be16_to_cpu(PageBuf
[index
]);
1239 if (blk
== MS_LB_NOT_USED
)
1241 if (blk
== info
->MS_Lib
.Log2PhyMap
[0]) {
1242 result
= MS_ERROR_FLASH_READ
;
1253 static int ms_lib_setacquired_errorblock(struct us_data
*us
, u16 phyblk
)
1256 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1258 if (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
)
1261 log
= info
->MS_Lib
.Phy2LogMap
[phyblk
];
1263 if (log
< info
->MS_Lib
.NumberOfLogBlock
)
1264 info
->MS_Lib
.Log2PhyMap
[log
] = MS_LB_NOT_USED
;
1266 if (info
->MS_Lib
.Phy2LogMap
[phyblk
] != MS_LB_INITIAL_ERROR
)
1267 info
->MS_Lib
.Phy2LogMap
[phyblk
] = MS_LB_ACQUIRED_ERROR
;
1272 static int ms_lib_overwrite_extra(struct us_data
*us
, u32 PhyBlockAddr
,
1273 u8 PageNum
, u8 OverwriteFlag
)
1275 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1278 result
= ene_load_bincode(us
, MS_RW_PATTERN
);
1279 if (result
!= USB_STOR_XFER_GOOD
)
1280 return USB_STOR_TRANSPORT_ERROR
;
1282 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1283 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1284 bcb
->DataTransferLength
= 0x4;
1285 bcb
->Flags
= US_BULK_FLAG_IN
;
1288 bcb
->CDB
[5] = (unsigned char)(PageNum
);
1289 bcb
->CDB
[4] = (unsigned char)(PhyBlockAddr
);
1290 bcb
->CDB
[3] = (unsigned char)(PhyBlockAddr
>>8);
1291 bcb
->CDB
[2] = (unsigned char)(PhyBlockAddr
>>16);
1292 bcb
->CDB
[6] = OverwriteFlag
;
1297 result
= ene_send_scsi_cmd(us
, FDIR_READ
, NULL
, 0);
1298 if (result
!= USB_STOR_XFER_GOOD
)
1299 return USB_STOR_TRANSPORT_ERROR
;
1301 return USB_STOR_TRANSPORT_GOOD
;
1304 static int ms_lib_error_phyblock(struct us_data
*us
, u16 phyblk
)
1306 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1308 if (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
)
1309 return MS_STATUS_ERROR
;
1311 ms_lib_setacquired_errorblock(us
, phyblk
);
1313 if (ms_lib_iswritable(info
))
1314 return ms_lib_overwrite_extra(us
, phyblk
, 0, (u8
)(~MS_REG_OVR_BKST
& BYTE_MASK
));
1316 return MS_STATUS_SUCCESS
;
1319 static int ms_lib_erase_phyblock(struct us_data
*us
, u16 phyblk
)
1322 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1324 if (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
)
1325 return MS_STATUS_ERROR
;
1327 log
= info
->MS_Lib
.Phy2LogMap
[phyblk
];
1329 if (log
< info
->MS_Lib
.NumberOfLogBlock
)
1330 info
->MS_Lib
.Log2PhyMap
[log
] = MS_LB_NOT_USED
;
1332 info
->MS_Lib
.Phy2LogMap
[phyblk
] = MS_LB_NOT_USED
;
1334 if (ms_lib_iswritable(info
)) {
1335 switch (ms_read_eraseblock(us
, phyblk
)) {
1336 case MS_STATUS_SUCCESS
:
1337 info
->MS_Lib
.Phy2LogMap
[phyblk
] = MS_LB_NOT_USED_ERASED
;
1338 return MS_STATUS_SUCCESS
;
1339 case MS_ERROR_FLASH_ERASE
:
1340 case MS_STATUS_INT_ERROR
:
1341 ms_lib_error_phyblock(us
, phyblk
);
1342 return MS_ERROR_FLASH_ERASE
;
1343 case MS_STATUS_ERROR
:
1345 ms_lib_ctrl_set(info
, MS_LIB_CTRL_RDONLY
); /* MS_LibCtrlSet will used by ENE_MSInit ,need check, and why us to info*/
1346 ms_lib_setacquired_errorblock(us
, phyblk
);
1347 return MS_STATUS_ERROR
;
1351 ms_lib_setacquired_errorblock(us
, phyblk
);
1353 return MS_STATUS_SUCCESS
;
1356 static int ms_lib_read_extra(struct us_data
*us
, u32 PhyBlock
,
1357 u8 PageNum
, struct ms_lib_type_extdat
*ExtraDat
)
1359 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1360 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1361 u8
*bbuf
= info
->bbuf
;
1364 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1365 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1366 bcb
->DataTransferLength
= 0x4;
1367 bcb
->Flags
= US_BULK_FLAG_IN
;
1370 bcb
->CDB
[5] = (unsigned char)(PageNum
);
1371 bcb
->CDB
[4] = (unsigned char)(PhyBlock
);
1372 bcb
->CDB
[3] = (unsigned char)(PhyBlock
>>8);
1373 bcb
->CDB
[2] = (unsigned char)(PhyBlock
>>16);
1376 result
= ene_send_scsi_cmd(us
, FDIR_READ
, bbuf
, 0);
1377 if (result
!= USB_STOR_XFER_GOOD
)
1378 return USB_STOR_TRANSPORT_ERROR
;
1380 ExtraDat
->reserved
= 0;
1381 ExtraDat
->intr
= 0x80; /* Not yet, waiting for fireware support */
1382 ExtraDat
->status0
= 0x10; /* Not yet, waiting for fireware support */
1383 ExtraDat
->status1
= 0x00; /* Not yet, waiting for fireware support */
1384 ExtraDat
->ovrflg
= bbuf
[0];
1385 ExtraDat
->mngflg
= bbuf
[1];
1386 ExtraDat
->logadr
= memstick_logaddr(bbuf
[2], bbuf
[3]);
1388 return USB_STOR_TRANSPORT_GOOD
;
1391 static int ms_libsearch_block_from_physical(struct us_data
*us
, u16 phyblk
)
1394 struct ms_lib_type_extdat extdat
; /* need check */
1395 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1398 if (phyblk
>= info
->MS_Lib
.NumberOfPhyBlock
)
1401 for (blk
= phyblk
+ 1; blk
!= phyblk
; blk
++) {
1402 if ((blk
& MS_PHYSICAL_BLOCKS_PER_SEGMENT_MASK
) == 0)
1403 blk
-= MS_PHYSICAL_BLOCKS_PER_SEGMENT
;
1405 if (info
->MS_Lib
.Phy2LogMap
[blk
] == MS_LB_NOT_USED_ERASED
) {
1407 } else if (info
->MS_Lib
.Phy2LogMap
[blk
] == MS_LB_NOT_USED
) {
1408 switch (ms_lib_read_extra(us
, blk
, 0, &extdat
)) {
1409 case MS_STATUS_SUCCESS
:
1410 case MS_STATUS_SUCCESS_WITH_ECC
:
1412 case MS_NOCARD_ERROR
:
1413 return MS_NOCARD_ERROR
;
1414 case MS_STATUS_INT_ERROR
:
1416 case MS_ERROR_FLASH_READ
:
1418 ms_lib_setacquired_errorblock(us
, blk
);
1422 if ((extdat
.ovrflg
& MS_REG_OVR_BKST
) != MS_REG_OVR_BKST_OK
) {
1423 ms_lib_setacquired_errorblock(us
, blk
);
1427 switch (ms_lib_erase_phyblock(us
, blk
)) {
1428 case MS_STATUS_SUCCESS
:
1430 case MS_STATUS_ERROR
:
1432 case MS_ERROR_FLASH_ERASE
:
1434 ms_lib_error_phyblock(us
, blk
);
1442 static int ms_libsearch_block_from_logical(struct us_data
*us
, u16 logblk
)
1445 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1447 phyblk
= ms_libconv_to_physical(info
, logblk
);
1448 if (phyblk
>= MS_LB_ERROR
) {
1449 if (logblk
>= info
->MS_Lib
.NumberOfLogBlock
)
1452 phyblk
= (logblk
+ MS_NUMBER_OF_BOOT_BLOCK
) / MS_LOGICAL_BLOCKS_PER_SEGMENT
;
1453 phyblk
*= MS_PHYSICAL_BLOCKS_PER_SEGMENT
;
1454 phyblk
+= MS_PHYSICAL_BLOCKS_PER_SEGMENT
- 1;
1457 return ms_libsearch_block_from_physical(us
, phyblk
);
1460 static int ms_scsi_test_unit_ready(struct us_data
*us
, struct scsi_cmnd
*srb
)
1462 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)(us
->extra
);
1464 /* pr_info("MS_SCSI_Test_Unit_Ready\n"); */
1465 if (info
->MS_Status
.Insert
&& info
->MS_Status
.Ready
) {
1466 return USB_STOR_TRANSPORT_GOOD
;
1469 return USB_STOR_TRANSPORT_GOOD
;
1472 return USB_STOR_TRANSPORT_GOOD
;
1475 static int ms_scsi_mode_sense(struct us_data
*us
, struct scsi_cmnd
*srb
)
1477 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1478 unsigned char mediaNoWP
[12] = {
1479 0x0b, 0x00, 0x00, 0x08, 0x00, 0x00,
1480 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
1481 unsigned char mediaWP
[12] = {
1482 0x0b, 0x00, 0x80, 0x08, 0x00, 0x00,
1483 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
1485 if (info
->MS_Status
.WtP
)
1486 usb_stor_set_xfer_buf(mediaWP
, 12, srb
);
1488 usb_stor_set_xfer_buf(mediaNoWP
, 12, srb
);
1490 return USB_STOR_TRANSPORT_GOOD
;
1493 static int ms_scsi_read_capacity(struct us_data
*us
, struct scsi_cmnd
*srb
)
1497 unsigned int offset
= 0;
1498 unsigned char buf
[8];
1499 struct scatterlist
*sg
= NULL
;
1500 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1502 usb_stor_dbg(us
, "ms_scsi_read_capacity\n");
1504 if (info
->MS_Status
.IsMSPro
)
1505 bl_num
= info
->MSP_TotalBlock
- 1;
1507 bl_num
= info
->MS_Lib
.NumberOfLogBlock
* info
->MS_Lib
.blockSize
* 2 - 1;
1509 info
->bl_num
= bl_num
;
1510 usb_stor_dbg(us
, "bl_len = %x\n", bl_len
);
1511 usb_stor_dbg(us
, "bl_num = %x\n", bl_num
);
1513 /*srb->request_bufflen = 8; */
1514 buf
[0] = (bl_num
>> 24) & 0xff;
1515 buf
[1] = (bl_num
>> 16) & 0xff;
1516 buf
[2] = (bl_num
>> 8) & 0xff;
1517 buf
[3] = (bl_num
>> 0) & 0xff;
1518 buf
[4] = (bl_len
>> 24) & 0xff;
1519 buf
[5] = (bl_len
>> 16) & 0xff;
1520 buf
[6] = (bl_len
>> 8) & 0xff;
1521 buf
[7] = (bl_len
>> 0) & 0xff;
1523 usb_stor_access_xfer_buf(buf
, 8, srb
, &sg
, &offset
, TO_XFER_BUF
);
1525 return USB_STOR_TRANSPORT_GOOD
;
1528 static void ms_lib_phy_to_log_range(u16 PhyBlock
, u16
*LogStart
, u16
*LogEnde
)
1530 PhyBlock
/= MS_PHYSICAL_BLOCKS_PER_SEGMENT
;
1533 *LogStart
= MS_LOGICAL_BLOCKS_IN_1ST_SEGMENT
+ (PhyBlock
- 1) * MS_LOGICAL_BLOCKS_PER_SEGMENT
;/*496*/
1534 *LogEnde
= *LogStart
+ MS_LOGICAL_BLOCKS_PER_SEGMENT
;/*496*/
1537 *LogEnde
= MS_LOGICAL_BLOCKS_IN_1ST_SEGMENT
;/*494*/
1541 static int ms_lib_read_extrablock(struct us_data
*us
, u32 PhyBlock
,
1542 u8 PageNum
, u8 blen
, void *buf
)
1544 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1547 /* Read Extra Data */
1548 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1549 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1550 bcb
->DataTransferLength
= 0x4 * blen
;
1551 bcb
->Flags
= US_BULK_FLAG_IN
;
1554 bcb
->CDB
[5] = (unsigned char)(PageNum
);
1555 bcb
->CDB
[4] = (unsigned char)(PhyBlock
);
1556 bcb
->CDB
[3] = (unsigned char)(PhyBlock
>>8);
1557 bcb
->CDB
[2] = (unsigned char)(PhyBlock
>>16);
1560 result
= ene_send_scsi_cmd(us
, FDIR_READ
, buf
, 0);
1561 if (result
!= USB_STOR_XFER_GOOD
)
1562 return USB_STOR_TRANSPORT_ERROR
;
1564 return USB_STOR_TRANSPORT_GOOD
;
1567 static int ms_lib_scan_logicalblocknumber(struct us_data
*us
, u16 btBlk1st
)
1569 u16 PhyBlock
, newblk
, i
;
1570 u16 LogStart
, LogEnde
;
1571 struct ms_lib_type_extdat extdat
;
1572 u32 count
= 0, index
= 0;
1573 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1574 u8
*bbuf
= info
->bbuf
;
1576 for (PhyBlock
= 0; PhyBlock
< info
->MS_Lib
.NumberOfPhyBlock
;) {
1577 ms_lib_phy_to_log_range(PhyBlock
, &LogStart
, &LogEnde
);
1579 for (i
= 0; i
< MS_PHYSICAL_BLOCKS_PER_SEGMENT
; i
++, PhyBlock
++) {
1580 switch (ms_libconv_to_logical(info
, PhyBlock
)) {
1581 case MS_STATUS_ERROR
:
1587 if (count
== PhyBlock
) {
1588 ms_lib_read_extrablock(us
, PhyBlock
, 0, 0x80,
1592 index
= (PhyBlock
% 0x80) * 4;
1594 extdat
.ovrflg
= bbuf
[index
];
1595 extdat
.mngflg
= bbuf
[index
+1];
1596 extdat
.logadr
= memstick_logaddr(bbuf
[index
+2],
1599 if ((extdat
.ovrflg
& MS_REG_OVR_BKST
) != MS_REG_OVR_BKST_OK
) {
1600 ms_lib_setacquired_errorblock(us
, PhyBlock
);
1604 if ((extdat
.mngflg
& MS_REG_MNG_ATFLG
) == MS_REG_MNG_ATFLG_ATTBL
) {
1605 ms_lib_erase_phyblock(us
, PhyBlock
);
1609 if (extdat
.logadr
!= MS_LB_NOT_USED
) {
1610 if ((extdat
.logadr
< LogStart
) || (LogEnde
<= extdat
.logadr
)) {
1611 ms_lib_erase_phyblock(us
, PhyBlock
);
1615 newblk
= ms_libconv_to_physical(info
, extdat
.logadr
);
1617 if (newblk
!= MS_LB_NOT_USED
) {
1618 if (extdat
.logadr
== 0) {
1619 ms_lib_set_logicalpair(us
, extdat
.logadr
, PhyBlock
);
1620 if (ms_lib_check_disableblock(us
, btBlk1st
)) {
1621 ms_lib_set_logicalpair(us
, extdat
.logadr
, newblk
);
1626 ms_lib_read_extra(us
, newblk
, 0, &extdat
);
1627 if ((extdat
.ovrflg
& MS_REG_OVR_UDST
) == MS_REG_OVR_UDST_UPDATING
) {
1628 ms_lib_erase_phyblock(us
, PhyBlock
);
1631 ms_lib_erase_phyblock(us
, newblk
);
1635 ms_lib_set_logicalpair(us
, extdat
.logadr
, PhyBlock
);
1640 return MS_STATUS_SUCCESS
;
1644 static int ms_scsi_read(struct us_data
*us
, struct scsi_cmnd
*srb
)
1647 unsigned char *cdb
= srb
->cmnd
;
1648 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1649 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1651 u32 bn
= ((cdb
[2] << 24) & 0xff000000) | ((cdb
[3] << 16) & 0x00ff0000) |
1652 ((cdb
[4] << 8) & 0x0000ff00) | ((cdb
[5] << 0) & 0x000000ff);
1653 u16 blen
= ((cdb
[7] << 8) & 0xff00) | ((cdb
[8] << 0) & 0x00ff);
1654 u32 blenByte
= blen
* 0x200;
1656 if (bn
> info
->bl_num
)
1657 return USB_STOR_TRANSPORT_ERROR
;
1659 if (info
->MS_Status
.IsMSPro
) {
1660 result
= ene_load_bincode(us
, MSP_RW_PATTERN
);
1661 if (result
!= USB_STOR_XFER_GOOD
) {
1662 usb_stor_dbg(us
, "Load MPS RW pattern Fail !!\n");
1663 return USB_STOR_TRANSPORT_ERROR
;
1666 /* set up the command wrapper */
1667 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1668 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1669 bcb
->DataTransferLength
= blenByte
;
1670 bcb
->Flags
= US_BULK_FLAG_IN
;
1673 bcb
->CDB
[5] = (unsigned char)(bn
);
1674 bcb
->CDB
[4] = (unsigned char)(bn
>>8);
1675 bcb
->CDB
[3] = (unsigned char)(bn
>>16);
1676 bcb
->CDB
[2] = (unsigned char)(bn
>>24);
1678 result
= ene_send_scsi_cmd(us
, FDIR_READ
, scsi_sglist(srb
), 1);
1687 buf
= kmalloc(blenByte
, GFP_KERNEL
);
1689 return USB_STOR_TRANSPORT_ERROR
;
1691 result
= ene_load_bincode(us
, MS_RW_PATTERN
);
1692 if (result
!= USB_STOR_XFER_GOOD
) {
1693 pr_info("Load MS RW pattern Fail !!\n");
1694 result
= USB_STOR_TRANSPORT_ERROR
;
1698 logblk
= (u16
)(bn
/ info
->MS_Lib
.PagesPerBlock
);
1699 PageNum
= (u8
)(bn
% info
->MS_Lib
.PagesPerBlock
);
1702 if (blen
> (info
->MS_Lib
.PagesPerBlock
-PageNum
))
1703 len
= info
->MS_Lib
.PagesPerBlock
-PageNum
;
1707 phyblk
= ms_libconv_to_physical(info
, logblk
);
1708 blkno
= phyblk
* 0x20 + PageNum
;
1710 /* set up the command wrapper */
1711 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1712 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1713 bcb
->DataTransferLength
= 0x200 * len
;
1714 bcb
->Flags
= US_BULK_FLAG_IN
;
1717 bcb
->CDB
[5] = (unsigned char)(blkno
);
1718 bcb
->CDB
[4] = (unsigned char)(blkno
>>8);
1719 bcb
->CDB
[3] = (unsigned char)(blkno
>>16);
1720 bcb
->CDB
[2] = (unsigned char)(blkno
>>24);
1722 result
= ene_send_scsi_cmd(us
, FDIR_READ
, buf
+offset
, 0);
1723 if (result
!= USB_STOR_XFER_GOOD
) {
1724 pr_info("MS_SCSI_Read --- result = %x\n", result
);
1725 result
= USB_STOR_TRANSPORT_ERROR
;
1734 offset
+= MS_BYTES_PER_PAGE
*len
;
1736 usb_stor_set_xfer_buf(buf
, blenByte
, srb
);
1743 static int ms_scsi_write(struct us_data
*us
, struct scsi_cmnd
*srb
)
1746 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1747 unsigned char *cdb
= srb
->cmnd
;
1748 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1750 u32 bn
= ((cdb
[2] << 24) & 0xff000000) |
1751 ((cdb
[3] << 16) & 0x00ff0000) |
1752 ((cdb
[4] << 8) & 0x0000ff00) |
1753 ((cdb
[5] << 0) & 0x000000ff);
1754 u16 blen
= ((cdb
[7] << 8) & 0xff00) | ((cdb
[8] << 0) & 0x00ff);
1755 u32 blenByte
= blen
* 0x200;
1757 if (bn
> info
->bl_num
)
1758 return USB_STOR_TRANSPORT_ERROR
;
1760 if (info
->MS_Status
.IsMSPro
) {
1761 result
= ene_load_bincode(us
, MSP_RW_PATTERN
);
1762 if (result
!= USB_STOR_XFER_GOOD
) {
1763 pr_info("Load MSP RW pattern Fail !!\n");
1764 return USB_STOR_TRANSPORT_ERROR
;
1767 /* set up the command wrapper */
1768 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1769 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1770 bcb
->DataTransferLength
= blenByte
;
1774 bcb
->CDB
[5] = (unsigned char)(bn
);
1775 bcb
->CDB
[4] = (unsigned char)(bn
>>8);
1776 bcb
->CDB
[3] = (unsigned char)(bn
>>16);
1777 bcb
->CDB
[2] = (unsigned char)(bn
>>24);
1779 result
= ene_send_scsi_cmd(us
, FDIR_WRITE
, scsi_sglist(srb
), 1);
1785 u16 len
, oldphy
, newphy
;
1787 buf
= kmalloc(blenByte
, GFP_KERNEL
);
1789 return USB_STOR_TRANSPORT_ERROR
;
1790 usb_stor_set_xfer_buf(buf
, blenByte
, srb
);
1792 result
= ene_load_bincode(us
, MS_RW_PATTERN
);
1793 if (result
!= USB_STOR_XFER_GOOD
) {
1794 pr_info("Load MS RW pattern Fail !!\n");
1795 result
= USB_STOR_TRANSPORT_ERROR
;
1799 PhyBlockAddr
= (u16
)(bn
/ info
->MS_Lib
.PagesPerBlock
);
1800 PageNum
= (u8
)(bn
% info
->MS_Lib
.PagesPerBlock
);
1803 if (blen
> (info
->MS_Lib
.PagesPerBlock
-PageNum
))
1804 len
= info
->MS_Lib
.PagesPerBlock
-PageNum
;
1808 oldphy
= ms_libconv_to_physical(info
, PhyBlockAddr
); /* need check us <-> info */
1809 newphy
= ms_libsearch_block_from_logical(us
, PhyBlockAddr
);
1811 result
= ms_read_copyblock(us
, oldphy
, newphy
, PhyBlockAddr
, PageNum
, buf
+offset
, len
);
1813 if (result
!= USB_STOR_XFER_GOOD
) {
1814 pr_info("MS_SCSI_Write --- result = %x\n", result
);
1815 result
= USB_STOR_TRANSPORT_ERROR
;
1819 info
->MS_Lib
.Phy2LogMap
[oldphy
] = MS_LB_NOT_USED_ERASED
;
1820 ms_lib_force_setlogical_pair(us
, PhyBlockAddr
, newphy
);
1827 offset
+= MS_BYTES_PER_PAGE
*len
;
1839 static int ene_get_card_type(struct us_data
*us
, u16 index
, void *buf
)
1841 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1844 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1845 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1846 bcb
->DataTransferLength
= 0x01;
1847 bcb
->Flags
= US_BULK_FLAG_IN
;
1849 bcb
->CDB
[2] = (unsigned char)(index
>>8);
1850 bcb
->CDB
[3] = (unsigned char)index
;
1852 result
= ene_send_scsi_cmd(us
, FDIR_READ
, buf
, 0);
1856 static int ene_get_card_status(struct us_data
*us
, u8
*buf
)
1860 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1862 /*usb_stor_dbg(us, "transport --- ENE_ReadSDReg\n");*/
1863 reg4b
= *(u32
*)&buf
[0x18];
1864 info
->SD_READ_BL_LEN
= (u8
)((reg4b
>> 8) & 0x0f);
1866 tmpreg
= (u16
) reg4b
;
1867 reg4b
= *(u32
*)(&buf
[0x14]);
1868 if (info
->SD_Status
.HiCapacity
&& !info
->SD_Status
.IsMMC
)
1869 info
->HC_C_SIZE
= (reg4b
>> 8) & 0x3fffff;
1871 info
->SD_C_SIZE
= ((tmpreg
& 0x03) << 10) | (u16
)(reg4b
>> 22);
1872 info
->SD_C_SIZE_MULT
= (u8
)(reg4b
>> 7) & 0x07;
1873 if (info
->SD_Status
.HiCapacity
&& info
->SD_Status
.IsMMC
)
1874 info
->HC_C_SIZE
= *(u32
*)(&buf
[0x100]);
1876 if (info
->SD_READ_BL_LEN
> SD_BLOCK_LEN
) {
1877 info
->SD_Block_Mult
= 1 << (info
->SD_READ_BL_LEN
-SD_BLOCK_LEN
);
1878 info
->SD_READ_BL_LEN
= SD_BLOCK_LEN
;
1880 info
->SD_Block_Mult
= 1;
1883 return USB_STOR_TRANSPORT_GOOD
;
1886 static int ene_load_bincode(struct us_data
*us
, unsigned char flag
)
1889 char *fw_name
= NULL
;
1890 unsigned char *buf
= NULL
;
1891 const struct firmware
*sd_fw
= NULL
;
1892 int result
= USB_STOR_TRANSPORT_ERROR
;
1893 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
1894 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1896 if (info
->BIN_FLAG
== flag
)
1897 return USB_STOR_TRANSPORT_GOOD
;
1901 case SD_INIT1_PATTERN
:
1902 usb_stor_dbg(us
, "SD_INIT1_PATTERN\n");
1903 fw_name
= SD_INIT1_FIRMWARE
;
1905 case SD_INIT2_PATTERN
:
1906 usb_stor_dbg(us
, "SD_INIT2_PATTERN\n");
1907 fw_name
= SD_INIT2_FIRMWARE
;
1910 usb_stor_dbg(us
, "SD_RW_PATTERN\n");
1911 fw_name
= SD_RW_FIRMWARE
;
1914 case MS_INIT_PATTERN
:
1915 usb_stor_dbg(us
, "MS_INIT_PATTERN\n");
1916 fw_name
= MS_INIT_FIRMWARE
;
1918 case MSP_RW_PATTERN
:
1919 usb_stor_dbg(us
, "MSP_RW_PATTERN\n");
1920 fw_name
= MSP_RW_FIRMWARE
;
1923 usb_stor_dbg(us
, "MS_RW_PATTERN\n");
1924 fw_name
= MS_RW_FIRMWARE
;
1927 usb_stor_dbg(us
, "----------- Unknown PATTERN ----------\n");
1931 err
= request_firmware(&sd_fw
, fw_name
, &us
->pusb_dev
->dev
);
1933 usb_stor_dbg(us
, "load firmware %s failed\n", fw_name
);
1936 buf
= kmemdup(sd_fw
->data
, sd_fw
->size
, GFP_KERNEL
);
1940 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
1941 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
1942 bcb
->DataTransferLength
= sd_fw
->size
;
1946 result
= ene_send_scsi_cmd(us
, FDIR_WRITE
, buf
, 0);
1947 if (us
->srb
!= NULL
)
1948 scsi_set_resid(us
->srb
, 0);
1949 info
->BIN_FLAG
= flag
;
1953 release_firmware(sd_fw
);
1957 static int ms_card_init(struct us_data
*us
)
1961 unsigned char *PageBuffer0
= NULL
, *PageBuffer1
= NULL
;
1962 struct ms_lib_type_extdat extdat
;
1963 u16 btBlk1st
, btBlk2nd
;
1965 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
1967 printk(KERN_INFO
"MS_CardInit start\n");
1969 ms_lib_free_allocatedarea(us
); /* Clean buffer and set struct us_data flag to 0 */
1971 /* get two PageBuffer */
1972 PageBuffer0
= kmalloc(MS_BYTES_PER_PAGE
, GFP_KERNEL
);
1973 PageBuffer1
= kmalloc(MS_BYTES_PER_PAGE
, GFP_KERNEL
);
1974 if ((PageBuffer0
== NULL
) || (PageBuffer1
== NULL
)) {
1975 result
= MS_NO_MEMORY_ERROR
;
1979 btBlk1st
= btBlk2nd
= MS_LB_NOT_USED
;
1982 for (TmpBlock
= 0; TmpBlock
< MS_MAX_INITIAL_ERROR_BLOCKS
+2; TmpBlock
++) {
1984 switch (ms_read_readpage(us
, TmpBlock
, 0, (u32
*)PageBuffer0
, &extdat
)) {
1985 case MS_STATUS_SUCCESS
:
1987 case MS_STATUS_INT_ERROR
:
1989 case MS_STATUS_ERROR
:
1994 if ((extdat
.ovrflg
& MS_REG_OVR_BKST
) == MS_REG_OVR_BKST_NG
)
1997 if (((extdat
.mngflg
& MS_REG_MNG_SYSFLG
) == MS_REG_MNG_SYSFLG_USER
) ||
1998 (be16_to_cpu(((struct ms_bootblock_page0
*)PageBuffer0
)->header
.wBlockID
) != MS_BOOT_BLOCK_ID
) ||
1999 (be16_to_cpu(((struct ms_bootblock_page0
*)PageBuffer0
)->header
.wFormatVersion
) != MS_BOOT_BLOCK_FORMAT_VERSION
) ||
2000 (((struct ms_bootblock_page0
*)PageBuffer0
)->header
.bNumberOfDataEntry
!= MS_BOOT_BLOCK_DATA_ENTRIES
))
2003 if (btBlk1st
!= MS_LB_NOT_USED
) {
2004 btBlk2nd
= TmpBlock
;
2008 btBlk1st
= TmpBlock
;
2009 memcpy(PageBuffer1
, PageBuffer0
, MS_BYTES_PER_PAGE
);
2010 if (extdat
.status1
& (MS_REG_ST1_DTER
| MS_REG_ST1_EXER
| MS_REG_ST1_FGER
))
2014 if (btBlk1st
== MS_LB_NOT_USED
) {
2015 result
= MS_STATUS_ERROR
;
2020 if ((extdat
.status0
& MS_REG_ST0_WP
) == MS_REG_ST0_WP_ON
)
2021 ms_lib_ctrl_set(info
, MS_LIB_CTRL_WRPROTECT
);
2023 result
= MS_STATUS_ERROR
;
2024 /* 1st Boot Block */
2025 if (btBlk1stErred
== 0)
2026 result
= ms_lib_process_bootblock(us
, btBlk1st
, PageBuffer1
);
2028 /* 2nd Boot Block */
2029 if (result
&& (btBlk2nd
!= MS_LB_NOT_USED
))
2030 result
= ms_lib_process_bootblock(us
, btBlk2nd
, PageBuffer0
);
2033 result
= MS_STATUS_ERROR
;
2037 for (TmpBlock
= 0; TmpBlock
< btBlk1st
; TmpBlock
++)
2038 info
->MS_Lib
.Phy2LogMap
[TmpBlock
] = MS_LB_INITIAL_ERROR
;
2040 info
->MS_Lib
.Phy2LogMap
[btBlk1st
] = MS_LB_BOOT_BLOCK
;
2042 if (btBlk2nd
!= MS_LB_NOT_USED
) {
2043 for (TmpBlock
= btBlk1st
+ 1; TmpBlock
< btBlk2nd
; TmpBlock
++)
2044 info
->MS_Lib
.Phy2LogMap
[TmpBlock
] = MS_LB_INITIAL_ERROR
;
2046 info
->MS_Lib
.Phy2LogMap
[btBlk2nd
] = MS_LB_BOOT_BLOCK
;
2049 result
= ms_lib_scan_logicalblocknumber(us
, btBlk1st
);
2053 for (TmpBlock
= MS_PHYSICAL_BLOCKS_PER_SEGMENT
;
2054 TmpBlock
< info
->MS_Lib
.NumberOfPhyBlock
;
2055 TmpBlock
+= MS_PHYSICAL_BLOCKS_PER_SEGMENT
) {
2056 if (ms_count_freeblock(us
, TmpBlock
) == 0) {
2057 ms_lib_ctrl_set(info
, MS_LIB_CTRL_WRPROTECT
);
2063 if (ms_lib_alloc_writebuf(us
)) {
2064 result
= MS_NO_MEMORY_ERROR
;
2068 result
= MS_STATUS_SUCCESS
;
2074 printk(KERN_INFO
"MS_CardInit end\n");
2078 static int ene_ms_init(struct us_data
*us
)
2080 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
2082 u16 MSP_BlockSize
, MSP_UserAreaBlocks
;
2083 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
2084 u8
*bbuf
= info
->bbuf
;
2086 printk(KERN_INFO
"transport --- ENE_MSInit\n");
2088 /* the same part to test ENE */
2090 result
= ene_load_bincode(us
, MS_INIT_PATTERN
);
2091 if (result
!= USB_STOR_XFER_GOOD
) {
2092 printk(KERN_ERR
"Load MS Init Code Fail !!\n");
2093 return USB_STOR_TRANSPORT_ERROR
;
2096 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
2097 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
2098 bcb
->DataTransferLength
= 0x200;
2099 bcb
->Flags
= US_BULK_FLAG_IN
;
2103 result
= ene_send_scsi_cmd(us
, FDIR_READ
, bbuf
, 0);
2104 if (result
!= USB_STOR_XFER_GOOD
) {
2105 printk(KERN_ERR
"Execution MS Init Code Fail !!\n");
2106 return USB_STOR_TRANSPORT_ERROR
;
2108 /* the same part to test ENE */
2109 info
->MS_Status
= *(struct MS_STATUS
*) bbuf
;
2111 if (info
->MS_Status
.Insert
&& info
->MS_Status
.Ready
) {
2112 printk(KERN_INFO
"Insert = %x\n", info
->MS_Status
.Insert
);
2113 printk(KERN_INFO
"Ready = %x\n", info
->MS_Status
.Ready
);
2114 printk(KERN_INFO
"IsMSPro = %x\n", info
->MS_Status
.IsMSPro
);
2115 printk(KERN_INFO
"IsMSPHG = %x\n", info
->MS_Status
.IsMSPHG
);
2116 printk(KERN_INFO
"WtP= %x\n", info
->MS_Status
.WtP
);
2117 if (info
->MS_Status
.IsMSPro
) {
2118 MSP_BlockSize
= (bbuf
[6] << 8) | bbuf
[7];
2119 MSP_UserAreaBlocks
= (bbuf
[10] << 8) | bbuf
[11];
2120 info
->MSP_TotalBlock
= MSP_BlockSize
* MSP_UserAreaBlocks
;
2122 ms_card_init(us
); /* Card is MS (to ms.c)*/
2124 usb_stor_dbg(us
, "MS Init Code OK !!\n");
2126 usb_stor_dbg(us
, "MS Card Not Ready --- %x\n", bbuf
[0]);
2127 return USB_STOR_TRANSPORT_ERROR
;
2130 return USB_STOR_TRANSPORT_GOOD
;
2133 static int ene_sd_init(struct us_data
*us
)
2136 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
2137 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
2138 u8
*bbuf
= info
->bbuf
;
2140 usb_stor_dbg(us
, "transport --- ENE_SDInit\n");
2141 /* SD Init Part-1 */
2142 result
= ene_load_bincode(us
, SD_INIT1_PATTERN
);
2143 if (result
!= USB_STOR_XFER_GOOD
) {
2144 usb_stor_dbg(us
, "Load SD Init Code Part-1 Fail !!\n");
2145 return USB_STOR_TRANSPORT_ERROR
;
2148 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
2149 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
2150 bcb
->Flags
= US_BULK_FLAG_IN
;
2153 result
= ene_send_scsi_cmd(us
, FDIR_READ
, NULL
, 0);
2154 if (result
!= USB_STOR_XFER_GOOD
) {
2155 usb_stor_dbg(us
, "Execution SD Init Code Fail !!\n");
2156 return USB_STOR_TRANSPORT_ERROR
;
2159 /* SD Init Part-2 */
2160 result
= ene_load_bincode(us
, SD_INIT2_PATTERN
);
2161 if (result
!= USB_STOR_XFER_GOOD
) {
2162 usb_stor_dbg(us
, "Load SD Init Code Part-2 Fail !!\n");
2163 return USB_STOR_TRANSPORT_ERROR
;
2166 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
2167 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
2168 bcb
->DataTransferLength
= 0x200;
2169 bcb
->Flags
= US_BULK_FLAG_IN
;
2172 result
= ene_send_scsi_cmd(us
, FDIR_READ
, bbuf
, 0);
2173 if (result
!= USB_STOR_XFER_GOOD
) {
2174 usb_stor_dbg(us
, "Execution SD Init Code Fail !!\n");
2175 return USB_STOR_TRANSPORT_ERROR
;
2178 info
->SD_Status
= *(struct SD_STATUS
*) bbuf
;
2179 if (info
->SD_Status
.Insert
&& info
->SD_Status
.Ready
) {
2180 struct SD_STATUS
*s
= &info
->SD_Status
;
2182 ene_get_card_status(us
, bbuf
);
2183 usb_stor_dbg(us
, "Insert = %x\n", s
->Insert
);
2184 usb_stor_dbg(us
, "Ready = %x\n", s
->Ready
);
2185 usb_stor_dbg(us
, "IsMMC = %x\n", s
->IsMMC
);
2186 usb_stor_dbg(us
, "HiCapacity = %x\n", s
->HiCapacity
);
2187 usb_stor_dbg(us
, "HiSpeed = %x\n", s
->HiSpeed
);
2188 usb_stor_dbg(us
, "WtP = %x\n", s
->WtP
);
2190 usb_stor_dbg(us
, "SD Card Not Ready --- %x\n", bbuf
[0]);
2191 return USB_STOR_TRANSPORT_ERROR
;
2193 return USB_STOR_TRANSPORT_GOOD
;
2197 static int ene_init(struct us_data
*us
)
2201 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)(us
->extra
);
2202 u8
*bbuf
= info
->bbuf
;
2204 result
= ene_get_card_type(us
, REG_CARD_STATUS
, bbuf
);
2205 if (result
!= USB_STOR_XFER_GOOD
)
2206 return USB_STOR_TRANSPORT_ERROR
;
2208 misc_reg03
= bbuf
[0];
2209 if (misc_reg03
& 0x01) {
2210 if (!info
->SD_Status
.Ready
) {
2211 result
= ene_sd_init(us
);
2212 if (result
!= USB_STOR_XFER_GOOD
)
2213 return USB_STOR_TRANSPORT_ERROR
;
2216 if (misc_reg03
& 0x02) {
2217 if (!info
->MS_Status
.Ready
) {
2218 result
= ene_ms_init(us
);
2219 if (result
!= USB_STOR_XFER_GOOD
)
2220 return USB_STOR_TRANSPORT_ERROR
;
2226 /*----- sd_scsi_irp() ---------*/
2227 static int sd_scsi_irp(struct us_data
*us
, struct scsi_cmnd
*srb
)
2230 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)us
->extra
;
2232 switch (srb
->cmnd
[0]) {
2233 case TEST_UNIT_READY
:
2234 result
= sd_scsi_test_unit_ready(us
, srb
);
2237 result
= do_scsi_request_sense(us
, srb
);
2240 result
= do_scsi_inquiry(us
, srb
);
2243 result
= sd_scsi_mode_sense(us
, srb
);
2247 result = SD_SCSI_Start_Stop(us, srb);
2251 result
= sd_scsi_read_capacity(us
, srb
);
2254 result
= sd_scsi_read(us
, srb
);
2257 result
= sd_scsi_write(us
, srb
);
2260 info
->SrbStatus
= SS_ILLEGAL_REQUEST
;
2261 result
= USB_STOR_TRANSPORT_FAILED
;
2264 if (result
== USB_STOR_TRANSPORT_GOOD
)
2265 info
->SrbStatus
= SS_SUCCESS
;
2272 static int ms_scsi_irp(struct us_data
*us
, struct scsi_cmnd
*srb
)
2275 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)us
->extra
;
2277 switch (srb
->cmnd
[0]) {
2278 case TEST_UNIT_READY
:
2279 result
= ms_scsi_test_unit_ready(us
, srb
);
2282 result
= do_scsi_request_sense(us
, srb
);
2285 result
= do_scsi_inquiry(us
, srb
);
2288 result
= ms_scsi_mode_sense(us
, srb
);
2291 result
= ms_scsi_read_capacity(us
, srb
);
2294 result
= ms_scsi_read(us
, srb
);
2297 result
= ms_scsi_write(us
, srb
);
2300 info
->SrbStatus
= SS_ILLEGAL_REQUEST
;
2301 result
= USB_STOR_TRANSPORT_FAILED
;
2304 if (result
== USB_STOR_TRANSPORT_GOOD
)
2305 info
->SrbStatus
= SS_SUCCESS
;
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
);
2417 * FIXME: Notify the subdrivers that they need to reinitialize
2420 info
->Power_IsResum
= true;
2421 /*info->SD_Status.Ready = 0; */
2422 info
->SD_Status
= *(struct SD_STATUS
*)&tmp
;
2423 info
->MS_Status
= *(struct MS_STATUS
*)&tmp
;
2424 info
->SM_Status
= *(struct SM_STATUS
*)&tmp
;
2431 #define ene_ub6250_resume NULL
2432 #define ene_ub6250_reset_resume NULL
2436 static struct usb_driver ene_ub6250_driver
= {
2438 .probe
= ene_ub6250_probe
,
2439 .disconnect
= usb_stor_disconnect
,
2440 .suspend
= usb_stor_suspend
,
2441 .resume
= ene_ub6250_resume
,
2442 .reset_resume
= ene_ub6250_reset_resume
,
2443 .pre_reset
= usb_stor_pre_reset
,
2444 .post_reset
= usb_stor_post_reset
,
2445 .id_table
= ene_ub6250_usb_ids
,
2450 module_usb_stor_driver(ene_ub6250_driver
, ene_ub6250_host_template
, DRV_NAME
);