Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Staging: add USB ENE card reader driver

This driver is for the ENE card reader that can be found in many
different laptops. It was written by ENE, but cleaned up to
work properly in the kernel tree by Novell.

Signed-off-by: Al Cho <acho@novell.com>
Cc: <yiyingc@ene.com.tw>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Al Cho and committed by
Greg Kroah-Hartman
126bb03b 15b9e327

+10081
+2
drivers/staging/Kconfig
··· 159 159 160 160 source "drivers/staging/ath6kl/Kconfig" 161 161 162 + source "drivers/staging/keucr/Kconfig" 163 + 162 164 endif # !STAGING_EXCLUDE_BUILD 163 165 endif # STAGING
+1
drivers/staging/Makefile
··· 60 60 obj-$(CONFIG_WESTBRIDGE_ASTORIA) += westbridge/astoria/ 61 61 obj-$(CONFIG_SBE_2T3E3) += sbe-2t3e3/ 62 62 obj-$(CONFIG_ATH6K_LEGACY) += ath6kl/ 63 + obj-$(CONFIG_USB_ENESTORAGE) += keucr/
+13
drivers/staging/keucr/Kconfig
··· 1 + config USB_ENESTORAGE 2 + tristate "USB ENE card reader support" 3 + depends on USB && SCSI 4 + ---help--- 5 + Say Y here if you wish to control a ENE Card reader. 6 + 7 + This option depends on 'SCSI' support being enabled, but you 8 + probably also need 'SCSI device support: SCSI disk support' 9 + (BLK_DEV_SD) for most USB storage devices. 10 + 11 + To compile this driver as a module, choose M here: the 12 + module will be called keucr. 13 +
+16
drivers/staging/keucr/Makefile
··· 1 + EXTRA_CFLAGS += -Idrivers/scsi 2 + 3 + obj-$(CONFIG_USB_ENESTORAGE) += keucr.o 4 + 5 + keucr-objs := \ 6 + usb.o \ 7 + scsiglue.o \ 8 + transport.o \ 9 + init.o \ 10 + sdscsi.o \ 11 + msscsi.o \ 12 + ms.o \ 13 + smscsi.o \ 14 + smilmain.o \ 15 + smilsub.o \ 16 + smilecc.o
drivers/staging/keucr/Module.symvers
+11
drivers/staging/keucr/TODO
··· 1 + TODO: 2 + - checkpatch.pl clean 3 + - sparse clean 4 + - determine if the driver should not be using a duplicate 5 + version of the usb-storage scsi interface code, but should 6 + be merged into the drivers/usb/storage/ directory and 7 + infrastructure instead. 8 + - review by the USB developer community 9 + 10 + Please send any patches for this driver to Al Cho <acho@novell.com> and 11 + Greg Kroah-Hartman <gregkh@suse.de>.
+25
drivers/staging/keucr/common.h
··· 1 + #ifndef COMMON_INCD 2 + #define COMMON_INCD 3 + 4 + typedef void VOID; 5 + typedef u8 BOOLEAN; 6 + typedef u8 BYTE; 7 + typedef u8 *PBYTE; 8 + typedef u16 WORD; 9 + typedef u16 *PWORD; 10 + typedef u32 DWORD; 11 + typedef u32 *PDWORD; 12 + 13 + #define swapWORD(w) ((((unsigned short)(w) << 8) & 0xff00) | (((unsigned short)(w) >> 8) & 0x00ff)) 14 + #define swapDWORD(dw) ((((unsigned long)(dw) << 24) & 0xff000000) | \ 15 + (((unsigned long)(dw) << 8) & 0x00ff0000) | \ 16 + (((unsigned long)(dw) >> 8) & 0x0000ff00) | \ 17 + (((unsigned long)(dw) >> 24) & 0x000000ff)) 18 + 19 + #define LittleEndianWORD(w) (w) 20 + #define LittleEndianDWORD(dw) (dw) 21 + #define BigEndianWORD(w) swapWORD(w) 22 + #define BigEndianDWORD(dw) swapDWORD(dw) 23 + 24 + #endif 25 +
+541
drivers/staging/keucr/init.c
··· 1 + #include <linux/sched.h> 2 + #include <linux/errno.h> 3 + #include <linux/slab.h> 4 + 5 + #include <scsi/scsi.h> 6 + #include <scsi/scsi_eh.h> 7 + #include <scsi/scsi_device.h> 8 + 9 + #include "usb.h" 10 + #include "scsiglue.h" 11 + #include "transport.h" 12 + #include "init.h" 13 + 14 + BYTE IsSSFDCCompliance; 15 + BYTE IsXDCompliance; 16 + extern DWORD MediaChange; 17 + extern int Check_D_MediaFmt(struct us_data *); 18 + 19 + //----- ENE_InitMedia() ---------------------------------------- 20 + int ENE_InitMedia(struct us_data *us) 21 + { 22 + int result; 23 + BYTE MiscReg03 = 0; 24 + 25 + printk("--- Initial Nedia ---\n"); 26 + result = ENE_Read_BYTE(us, REG_CARD_STATUS, &MiscReg03); 27 + if (result != USB_STOR_XFER_GOOD) 28 + { 29 + printk("Read register fail !!\n"); 30 + return USB_STOR_TRANSPORT_ERROR; 31 + } 32 + printk("MiscReg03 = %x\n", MiscReg03); 33 + 34 + if (MiscReg03 & 0x01) 35 + { 36 + if (!us->SD_Status.Ready) 37 + { 38 + result = ENE_SDInit(us); 39 + if (result != USB_STOR_XFER_GOOD) 40 + return USB_STOR_TRANSPORT_ERROR; 41 + } 42 + } 43 + 44 + if (MiscReg03 & 0x02) 45 + { 46 + if (!us->SM_Status.Ready && !us->MS_Status.Ready) 47 + { 48 + result = ENE_SMInit(us); 49 + if (result != USB_STOR_XFER_GOOD) 50 + { 51 + result = ENE_MSInit(us); 52 + if (result != USB_STOR_XFER_GOOD) 53 + return USB_STOR_TRANSPORT_ERROR; 54 + } 55 + } 56 + 57 + } 58 + return result; 59 + } 60 + 61 + //----- ENE_Read_BYTE() ---------------------------------------- 62 + int ENE_Read_BYTE(struct us_data *us, WORD index, void *buf) 63 + { 64 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 65 + int result; 66 + 67 + memset(bcb, 0, sizeof(bcb)); 68 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 69 + bcb->DataTransferLength = 0x01; 70 + bcb->Flags = 0x80; 71 + bcb->CDB[0] = 0xED; 72 + bcb->CDB[2] = (BYTE)(index>>8); 73 + bcb->CDB[3] = (BYTE)index; 74 + 75 + result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0); 76 + return result; 77 + } 78 + 79 + //----- ENE_SDInit() --------------------- 80 + int ENE_SDInit(struct us_data *us) 81 + { 82 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 83 + int result; 84 + BYTE buf[0x200]; 85 + 86 + printk("transport --- ENE_SDInit\n"); 87 + // SD Init Part-1 88 + result = ENE_LoadBinCode(us, SD_INIT1_PATTERN); 89 + if (result != USB_STOR_XFER_GOOD) 90 + { 91 + printk("Load SD Init Code Part-1 Fail !!\n"); 92 + return USB_STOR_TRANSPORT_ERROR; 93 + } 94 + 95 + memset(bcb, 0, sizeof(bcb)); 96 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 97 + bcb->Flags = 0x80; 98 + bcb->CDB[0] = 0xF2; 99 + 100 + result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0); 101 + if (result != USB_STOR_XFER_GOOD) 102 + { 103 + printk("Exection SD Init Code Fail !!\n"); 104 + return USB_STOR_TRANSPORT_ERROR; 105 + } 106 + 107 + // SD Init Part-2 108 + result = ENE_LoadBinCode(us, SD_INIT2_PATTERN); 109 + if (result != USB_STOR_XFER_GOOD) 110 + { 111 + printk("Load SD Init Code Part-2 Fail !!\n"); 112 + return USB_STOR_TRANSPORT_ERROR; 113 + } 114 + 115 + memset(bcb, 0, sizeof(bcb)); 116 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 117 + bcb->DataTransferLength = 0x200; 118 + bcb->Flags = 0x80; 119 + bcb->CDB[0] = 0xF1; 120 + 121 + result = ENE_SendScsiCmd(us, FDIR_READ, &buf, 0); 122 + if (result != USB_STOR_XFER_GOOD) 123 + { 124 + printk("Exection SD Init Code Fail !!\n"); 125 + return USB_STOR_TRANSPORT_ERROR; 126 + } 127 + 128 + us->SD_Status = *(PSD_STATUS)&buf[0]; 129 + if (us->SD_Status.Insert && us->SD_Status.Ready) 130 + { 131 + ENE_ReadSDReg(us, (PBYTE)&buf); 132 + printk("Insert = %x\n", us->SD_Status.Insert); 133 + printk("Ready = %x\n", us->SD_Status.Ready); 134 + printk("IsMMC = %x\n", us->SD_Status.IsMMC); 135 + printk("HiCapacity = %x\n", us->SD_Status.HiCapacity); 136 + printk("HiSpeed = %x\n", us->SD_Status.HiSpeed); 137 + printk("WtP = %x\n", us->SD_Status.WtP); 138 + } 139 + else 140 + { 141 + printk("SD Card Not Ready --- %x\n", buf[0]); 142 + return USB_STOR_TRANSPORT_ERROR; 143 + } 144 + return USB_STOR_TRANSPORT_GOOD; 145 + } 146 + 147 + //----- ENE_MSInit() ---------------------------------------- 148 + int ENE_MSInit(struct us_data *us) 149 + { 150 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 151 + int result; 152 + BYTE buf[0x200]; 153 + WORD MSP_BlockSize, MSP_UserAreaBlocks; 154 + 155 + 156 + printk("transport --- ENE_MSInit\n"); 157 + result = ENE_LoadBinCode(us, MS_INIT_PATTERN); 158 + if (result != USB_STOR_XFER_GOOD) 159 + { 160 + printk("Load MS Init Code Fail !!\n"); 161 + return USB_STOR_TRANSPORT_ERROR; 162 + } 163 + 164 + memset(bcb, 0, sizeof(bcb)); 165 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 166 + bcb->DataTransferLength = 0x200; 167 + bcb->Flags = 0x80; 168 + bcb->CDB[0] = 0xF1; 169 + bcb->CDB[1] = 0x01; 170 + 171 + result = ENE_SendScsiCmd(us, FDIR_READ, &buf, 0); 172 + if (result != USB_STOR_XFER_GOOD) 173 + { 174 + printk("Exection MS Init Code Fail !!\n"); 175 + return USB_STOR_TRANSPORT_ERROR; 176 + } 177 + 178 + us->MS_Status = *(PMS_STATUS)&buf[0]; 179 + 180 + if (us->MS_Status.Insert && us->MS_Status.Ready) 181 + { 182 + printk("Insert = %x\n", us->MS_Status.Insert); 183 + printk("Ready = %x\n", us->MS_Status.Ready); 184 + printk("IsMSPro = %x\n", us->MS_Status.IsMSPro); 185 + printk("IsMSPHG = %x\n", us->MS_Status.IsMSPHG); 186 + printk("WtP = %x\n", us->MS_Status.WtP); 187 + if (us->MS_Status.IsMSPro) 188 + { 189 + MSP_BlockSize = (buf[6] <<8) | buf[7]; 190 + MSP_UserAreaBlocks = (buf[10]<<8) | buf[11]; 191 + us->MSP_TotalBlock = MSP_BlockSize * MSP_UserAreaBlocks; 192 + } 193 + else 194 + MS_CardInit(us); 195 + printk("MS Init Code OK !!\n"); 196 + } 197 + else 198 + { 199 + printk("MS Card Not Ready --- %x\n", buf[0]); 200 + return USB_STOR_TRANSPORT_ERROR; 201 + } 202 + 203 + return USB_STOR_TRANSPORT_GOOD; 204 + } 205 + 206 + //----- ENE_SMInit() ---------------------------------------- 207 + int ENE_SMInit(struct us_data *us) 208 + { 209 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 210 + int result; 211 + BYTE buf[0x200]; 212 + 213 + printk("transport --- ENE_SMInit\n"); 214 + 215 + result = ENE_LoadBinCode(us, SM_INIT_PATTERN); 216 + if (result != USB_STOR_XFER_GOOD) 217 + { 218 + printk("Load SM Init Code Fail !!\n"); 219 + return USB_STOR_TRANSPORT_ERROR; 220 + } 221 + 222 + memset(bcb, 0, sizeof(bcb)); 223 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 224 + bcb->DataTransferLength = 0x200; 225 + bcb->Flags = 0x80; 226 + bcb->CDB[0] = 0xF1; 227 + bcb->CDB[1] = 0x01; 228 + 229 + result = ENE_SendScsiCmd(us, FDIR_READ, &buf, 0); 230 + if (result != USB_STOR_XFER_GOOD) 231 + { 232 + printk("Exection SM Init Code Fail !! result = %x\n", result); 233 + return USB_STOR_TRANSPORT_ERROR; 234 + } 235 + 236 + us->SM_Status = *(PSM_STATUS)&buf[0]; 237 + 238 + us->SM_DeviceID = buf[1]; 239 + us->SM_CardID = buf[2]; 240 + 241 + if (us->SM_Status.Insert && us->SM_Status.Ready) 242 + { 243 + printk("Insert = %x\n", us->SM_Status.Insert); 244 + printk("Ready = %x\n", us->SM_Status.Ready); 245 + printk("WtP = %x\n", us->SM_Status.WtP); 246 + printk("DeviceID = %x\n", us->SM_DeviceID); 247 + printk("CardID = %x\n", us->SM_CardID); 248 + MediaChange = 1; 249 + Check_D_MediaFmt(us); 250 + } 251 + else 252 + { 253 + printk("SM Card Not Ready --- %x\n", buf[0]); 254 + return USB_STOR_TRANSPORT_ERROR; 255 + } 256 + 257 + return USB_STOR_TRANSPORT_GOOD; 258 + } 259 + 260 + //----- ENE_ReadSDReg() ---------------------------------------------- 261 + int ENE_ReadSDReg(struct us_data *us, u8 *RdBuf) 262 + { 263 + WORD tmpreg; 264 + DWORD reg4b; 265 + 266 + //printk("transport --- ENE_ReadSDReg\n"); 267 + reg4b = *(PDWORD)&RdBuf[0x18]; 268 + us->SD_READ_BL_LEN = (BYTE)((reg4b >> 8) & 0x0f); 269 + 270 + tmpreg = (WORD) reg4b; 271 + reg4b = *(PDWORD)(&RdBuf[0x14]); 272 + if (us->SD_Status.HiCapacity && !us->SD_Status.IsMMC) 273 + us->HC_C_SIZE = (reg4b >> 8) & 0x3fffff; 274 + 275 + us->SD_C_SIZE = ((tmpreg & 0x03) << 10) | (WORD)(reg4b >> 22); 276 + us->SD_C_SIZE_MULT = (BYTE)(reg4b >> 7) & 0x07; 277 + if (us->SD_Status.HiCapacity && us->SD_Status.IsMMC) 278 + us->HC_C_SIZE = *(PDWORD)(&RdBuf[0x100]); 279 + 280 + if (us->SD_READ_BL_LEN > SD_BLOCK_LEN) 281 + { 282 + us->SD_Block_Mult = 1 << (us->SD_READ_BL_LEN - SD_BLOCK_LEN); us->SD_READ_BL_LEN = SD_BLOCK_LEN; 283 + } 284 + else 285 + { us->SD_Block_Mult = 1; 286 + } 287 + return USB_STOR_TRANSPORT_GOOD; 288 + } 289 + 290 + //----- ENE_LoadBinCode() --------------------- 291 + int ENE_LoadBinCode(struct us_data *us, BYTE flag) 292 + { 293 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 294 + int result; 295 + //void *buf; 296 + PBYTE buf; 297 + 298 + //printk("transport --- ENE_LoadBinCode\n"); 299 + if (us->BIN_FLAG == flag) 300 + return USB_STOR_TRANSPORT_GOOD; 301 + 302 + buf = kmalloc(0x800, GFP_KERNEL); 303 + switch ( flag ) 304 + { 305 + // For SD 306 + case SD_INIT1_PATTERN: 307 + printk("SD_INIT1_PATTERN\n"); 308 + memcpy(buf, SD_Init1, 0x800); 309 + break; 310 + case SD_INIT2_PATTERN: 311 + printk("SD_INIT2_PATTERN\n"); 312 + memcpy(buf, SD_Init2, 0x800); 313 + break; 314 + case SD_RW_PATTERN: 315 + printk("SD_RW_PATTERN\n"); 316 + memcpy(buf, SD_Rdwr, 0x800); 317 + break; 318 + // For MS 319 + case MS_INIT_PATTERN: 320 + printk("MS_INIT_PATTERN\n"); 321 + memcpy(buf, MS_Init, 0x800); 322 + break; 323 + case MSP_RW_PATTERN: 324 + printk("MSP_RW_PATTERN\n"); 325 + memcpy(buf, MSP_Rdwr, 0x800); 326 + break; 327 + case MS_RW_PATTERN: 328 + printk("MS_RW_PATTERN\n"); 329 + memcpy(buf, MS_Rdwr, 0x800); 330 + break; 331 + // For SS 332 + case SM_INIT_PATTERN: 333 + printk("SM_INIT_PATTERN\n"); 334 + memcpy(buf, SM_Init, 0x800); 335 + break; 336 + case SM_RW_PATTERN: 337 + printk("SM_RW_PATTERN\n"); 338 + memcpy(buf, SM_Rdwr, 0x800); 339 + break; 340 + } 341 + 342 + memset(bcb, 0, sizeof(bcb)); 343 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 344 + bcb->DataTransferLength = 0x800; 345 + bcb->Flags =0x00; 346 + bcb->CDB[0] = 0xEF; 347 + 348 + result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0); 349 + 350 + kfree(buf); 351 + us->BIN_FLAG = flag; 352 + return result; 353 + } 354 + 355 + //----- ENE_SendScsiCmd() --------------------- 356 + int ENE_SendScsiCmd(struct us_data *us, BYTE fDir, void *buf, int use_sg) 357 + { 358 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 359 + struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; 360 + 361 + int result; 362 + unsigned int transfer_length=bcb->DataTransferLength, cswlen=0, partial=0; 363 + unsigned int residue; 364 + 365 + //printk("transport --- ENE_SendScsiCmd\n"); 366 + // send cmd to out endpoint 367 + result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb, US_BULK_CB_WRAP_LEN, NULL); 368 + if (result != USB_STOR_XFER_GOOD) 369 + { 370 + printk("send cmd to out endpoint fail ---\n"); 371 + return USB_STOR_TRANSPORT_ERROR; 372 + } 373 + 374 + if (buf) 375 + { 376 + unsigned int pipe = fDir == FDIR_READ ? us->recv_bulk_pipe : us->send_bulk_pipe; 377 + // Bulk 378 + if (use_sg) 379 + result = usb_stor_bulk_srb(us, pipe, us->srb); 380 + else 381 + result = usb_stor_bulk_transfer_sg(us, pipe, buf, transfer_length, 0, &partial); 382 + if (result != USB_STOR_XFER_GOOD) 383 + { 384 + printk("data transfer fail ---\n"); 385 + return USB_STOR_TRANSPORT_ERROR; 386 + } 387 + } 388 + 389 + // Get CSW for device status 390 + result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, &cswlen); 391 + 392 + if (result == USB_STOR_XFER_SHORT && cswlen == 0) 393 + { 394 + printk("Received 0-length CSW; retrying...\n"); 395 + result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, &cswlen); 396 + } 397 + 398 + if (result == USB_STOR_XFER_STALLED) 399 + { 400 + /* get the status again */ 401 + printk("Attempting to get CSW (2nd try)...\n"); 402 + result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, NULL); 403 + } 404 + 405 + if (result != USB_STOR_XFER_GOOD) 406 + return USB_STOR_TRANSPORT_ERROR; 407 + 408 + /* check bulk status */ 409 + residue = le32_to_cpu(bcs->Residue); 410 + 411 + /* try to compute the actual residue, based on how much data 412 + * was really transferred and what the device tells us */ 413 + if (residue && !(us->fflags & US_FL_IGNORE_RESIDUE)) 414 + { 415 + residue = min(residue, transfer_length); 416 + scsi_set_resid(us->srb, max(scsi_get_resid(us->srb), (int) residue)); 417 + } 418 + 419 + if (bcs->Status != US_BULK_STAT_OK) 420 + return USB_STOR_TRANSPORT_ERROR; 421 + 422 + return USB_STOR_TRANSPORT_GOOD; 423 + } 424 + 425 + //----- ENE_Read_Data() --------------------- 426 + int ENE_Read_Data(struct us_data *us, void *buf, unsigned int length) 427 + { 428 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 429 + struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; 430 + int result; 431 + 432 + //printk("transport --- ENE_Read_Data\n"); 433 + // set up the command wrapper 434 + memset(bcb, 0, sizeof(bcb)); 435 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 436 + bcb->DataTransferLength = length; 437 + bcb->Flags =0x80; 438 + bcb->CDB[0] = 0xED; 439 + bcb->CDB[2] = 0xFF; 440 + bcb->CDB[3] = 0x81; 441 + 442 + // send cmd to out endpoint 443 + result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb, US_BULK_CB_WRAP_LEN, NULL); 444 + if (result != USB_STOR_XFER_GOOD) 445 + return USB_STOR_TRANSPORT_ERROR; 446 + 447 + // R/W data 448 + result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, buf, length, NULL); 449 + if (result != USB_STOR_XFER_GOOD) 450 + return USB_STOR_TRANSPORT_ERROR; 451 + 452 + // Get CSW for device status 453 + result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, NULL); 454 + if (result != USB_STOR_XFER_GOOD) 455 + return USB_STOR_TRANSPORT_ERROR; 456 + if (bcs->Status != US_BULK_STAT_OK) 457 + return USB_STOR_TRANSPORT_ERROR; 458 + 459 + return USB_STOR_TRANSPORT_GOOD; 460 + } 461 + 462 + //----- ENE_Write_Data() --------------------- 463 + int ENE_Write_Data(struct us_data *us, void *buf, unsigned int length) 464 + { 465 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 466 + struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; 467 + int result; 468 + 469 + //printk("transport --- ENE_Write_Data\n"); 470 + // set up the command wrapper 471 + memset(bcb, 0, sizeof(bcb)); 472 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 473 + bcb->DataTransferLength = length; 474 + bcb->Flags =0x00; 475 + bcb->CDB[0] = 0xEE; 476 + bcb->CDB[2] = 0xFF; 477 + bcb->CDB[3] = 0x81; 478 + 479 + // send cmd to out endpoint 480 + result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb, US_BULK_CB_WRAP_LEN, NULL); 481 + if (result != USB_STOR_XFER_GOOD) 482 + return USB_STOR_TRANSPORT_ERROR; 483 + 484 + // R/W data 485 + result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, buf, length, NULL); 486 + if (result != USB_STOR_XFER_GOOD) 487 + return USB_STOR_TRANSPORT_ERROR; 488 + 489 + // Get CSW for device status 490 + result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, NULL); 491 + if (result != USB_STOR_XFER_GOOD) 492 + return USB_STOR_TRANSPORT_ERROR; 493 + if (bcs->Status != US_BULK_STAT_OK) 494 + return USB_STOR_TRANSPORT_ERROR; 495 + 496 + return USB_STOR_TRANSPORT_GOOD; 497 + } 498 + 499 + //----- usb_stor_print_cmd() --------------------- 500 + void usb_stor_print_cmd(struct scsi_cmnd *srb) 501 + { 502 + PBYTE Cdb = srb->cmnd; 503 + DWORD cmd = Cdb[0]; 504 + DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) | 505 + ((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff); 506 + WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff); 507 + 508 + switch (cmd) { 509 + case TEST_UNIT_READY: 510 + //printk("scsi cmd %X --- SCSIOP_TEST_UNIT_READY\n", cmd); 511 + break; 512 + case INQUIRY: 513 + printk("scsi cmd %X --- SCSIOP_INQUIRY\n", cmd); 514 + break; 515 + case MODE_SENSE: 516 + printk("scsi cmd %X --- SCSIOP_MODE_SENSE\n", cmd); 517 + break; 518 + case START_STOP: 519 + printk("scsi cmd %X --- SCSIOP_START_STOP\n", cmd); 520 + break; 521 + case READ_CAPACITY: 522 + printk("scsi cmd %X --- SCSIOP_READ_CAPACITY\n", cmd); 523 + break; 524 + case READ_10: 525 + //printk("scsi cmd %X --- SCSIOP_READ, bn = %X, blen = %X\n", cmd, bn, blen); 526 + break; 527 + case WRITE_10: 528 + //printk("scsi cmd %X --- SCSIOP_WRITE, bn = %X, blen = %X\n", cmd, bn, blen); 529 + break; 530 + case ALLOW_MEDIUM_REMOVAL: 531 + printk("scsi cmd %X --- SCSIOP_ALLOW_MEDIUM_REMOVAL\n", cmd); 532 + break; 533 + default: 534 + printk("scsi cmd %X --- Other cmd\n", cmd); 535 + break; 536 + } 537 + bn = 0; 538 + blen = 0; 539 + } 540 + 541 +
+1042
drivers/staging/keucr/init.h
··· 1 + #include "common.h" 2 + 3 + BYTE SD_Init1[] = { 4 + 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 0xFF, 0x23, 0x74, 0x80, 0xF0, 0x90, 0xFF, 0x09, 5 + 0xE0, 0x30, 0xE5, 0xFC, 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE0, 0x92, 0x14, 0x20, 0x14, 0x0A, 0xC2, 6 + 0x0F, 0xD2, 0x10, 0xC2, 0x17, 0xC3, 0x02, 0xE3, 0x13, 0x7F, 0x03, 0x12, 0x2F, 0xCB, 0x7E, 0x00, 7 + 0x7F, 0x10, 0x12, 0xE3, 0xFA, 0x90, 0xFE, 0x07, 0xE0, 0x54, 0xBA, 0xF0, 0x75, 0x16, 0x00, 0x75, 8 + 0x17, 0x00, 0x90, 0xFE, 0x05, 0x74, 0x80, 0xF0, 0x90, 0xFE, 0x07, 0x74, 0x80, 0xF0, 0x7F, 0x32, 9 + 0x7E, 0x00, 0x12, 0xE3, 0xFA, 0x90, 0xFE, 0x05, 0xE0, 0x44, 0x01, 0xF0, 0xE0, 0x44, 0x08, 0xF0, 10 + 0x7F, 0x32, 0x7E, 0x00, 0x12, 0xE3, 0xFA, 0x90, 0xFE, 0x05, 0xE0, 0x54, 0xF7, 0xF0, 0x7F, 0x32, 11 + 0x7E, 0x00, 0x12, 0xE3, 0xFA, 0x90, 0xFF, 0x81, 0xE0, 0xC2, 0xE3, 0xF0, 0xE0, 0x54, 0xCF, 0x44, 12 + 0x20, 0xD2, 0xE3, 0xF0, 0x90, 0xFF, 0x84, 0xE0, 0x54, 0x1F, 0x44, 0x40, 0xF0, 0x90, 0xFE, 0x05, 13 + 0xE0, 0xD2, 0xE0, 0xF0, 0xE0, 0x30, 0xE0, 0xF8, 0x90, 0xFE, 0x04, 0xE0, 0x44, 0x06, 0xF0, 0x90, 14 + 0xFE, 0x04, 0x30, 0x14, 0x06, 0xE0, 0x70, 0xFA, 0xD3, 0x80, 0x01, 0xC3, 0x90, 0xFE, 0x05, 0xE0, 15 + 0x44, 0x30, 0xF0, 0x90, 0xFE, 0x06, 0x74, 0x70, 0xF0, 0x74, 0xFF, 0x90, 0xFE, 0x08, 0xF0, 0x74, 16 + 0xFF, 0x90, 0xFE, 0x09, 0xF0, 0x90, 0xFE, 0x04, 0xE0, 0x44, 0x06, 0xF0, 0xE4, 0x90, 0xFE, 0x0C, 17 + 0xF0, 0x90, 0xFE, 0x0D, 0xF0, 0x90, 0xFE, 0x0E, 0xF0, 0xC2, 0x12, 0xE4, 0x90, 0xEB, 0xF9, 0xF0, 18 + 0x90, 0xEB, 0xFA, 0xF0, 0x90, 0xFF, 0x81, 0xE0, 0x54, 0x8F, 0x44, 0x7F, 0xF0, 0x7F, 0x32, 0x7E, 19 + 0x00, 0x12, 0xE3, 0xFA, 0x90, 0xFE, 0x05, 0xE0, 0x54, 0xBF, 0xF0, 0x75, 0xF0, 0xFF, 0xD2, 0x17, 20 + 0xC2, 0x13, 0xE5, 0xF0, 0x14, 0xF5, 0xF0, 0x70, 0x03, 0x02, 0xE2, 0xFC, 0x90, 0xFF, 0x83, 0xE0, 21 + 0xA2, 0xE0, 0x92, 0x14, 0x20, 0x14, 0x03, 0x02, 0xE2, 0xFC, 0xE4, 0xFE, 0x74, 0xFF, 0xFF, 0x78, 22 + 0x00, 0x79, 0x08, 0x12, 0xE3, 0x22, 0x20, 0x13, 0x24, 0x30, 0x17, 0x21, 0x90, 0xFF, 0x83, 0xE0, 23 + 0xA2, 0xE0, 0x92, 0x14, 0x20, 0x14, 0x03, 0x02, 0xE2, 0xFC, 0x78, 0x08, 0x79, 0x28, 0x7D, 0xAA, 24 + 0x7C, 0x01, 0x7B, 0x00, 0x7A, 0x00, 0x12, 0xE3, 0x22, 0x50, 0x02, 0x21, 0xED, 0x90, 0xFF, 0x83, 25 + 0xE0, 0xA2, 0xE0, 0x92, 0x14, 0x20, 0x14, 0x03, 0x02, 0xE2, 0xFC, 0x30, 0x13, 0x02, 0x80, 0x17, 26 + 0x78, 0x37, 0x79, 0x50, 0x7A, 0x00, 0x7B, 0x00, 0x7C, 0x00, 0x7D, 0x00, 0x12, 0xE3, 0x22, 0x50, 27 + 0x02, 0x80, 0x7A, 0x78, 0x69, 0x80, 0x02, 0x78, 0x01, 0x79, 0x2A, 0x7A, 0x80, 0x30, 0x17, 0x02, 28 + 0x7A, 0x40, 0x7B, 0x70, 0x7C, 0x00, 0x7D, 0x00, 0x12, 0xE3, 0x22, 0x50, 0x16, 0x90, 0xFE, 0x04, 29 + 0xE0, 0x44, 0x06, 0xF0, 0x90, 0xFE, 0x04, 0x30, 0x14, 0x06, 0xE0, 0x70, 0xFA, 0xD3, 0x80, 0x01, 30 + 0xC3, 0x80, 0x4A, 0x90, 0xFE, 0x20, 0xE0, 0x54, 0x00, 0xB4, 0x00, 0x23, 0x90, 0xFE, 0x21, 0xE0, 31 + 0x54, 0x00, 0xB4, 0x00, 0x1A, 0x90, 0xFE, 0x22, 0xE0, 0x54, 0x70, 0xB4, 0x70, 0x11, 0x90, 0xFE, 32 + 0x23, 0xE0, 0x30, 0xE7, 0x0A, 0x30, 0x17, 0x05, 0x20, 0xE6, 0x02, 0xC2, 0x17, 0x41, 0x02, 0xC3, 33 + 0xEF, 0x94, 0x01, 0xFF, 0xEE, 0x94, 0x00, 0xFE, 0xC0, 0x06, 0xC0, 0x07, 0x7F, 0x64, 0x7E, 0x00, 34 + 0x12, 0xE3, 0xFA, 0xD0, 0x07, 0xD0, 0x06, 0xEE, 0x4F, 0x60, 0x02, 0x21, 0x4D, 0x7F, 0x64, 0x7E, 35 + 0x00, 0x12, 0xE3, 0xFA, 0xB2, 0x17, 0x30, 0x17, 0x07, 0xB2, 0x13, 0x20, 0x13, 0x02, 0x01, 0xFE, 36 + 0x21, 0x0C, 0x78, 0x02, 0x79, 0x2D, 0x12, 0xE3, 0x22, 0x50, 0x03, 0x02, 0xE2, 0xFC, 0x7B, 0x0F, 37 + 0x7C, 0xFE, 0x7D, 0x20, 0x7E, 0xEA, 0x7F, 0x1A, 0x12, 0xE3, 0xD3, 0x78, 0x03, 0x20, 0x13, 0x02, 38 + 0x78, 0x03, 0x79, 0x28, 0x90, 0xEB, 0xFA, 0xE0, 0xFA, 0x90, 0xEB, 0xF9, 0xE0, 0xFB, 0x7C, 0x00, 39 + 0x7D, 0x00, 0x12, 0xE3, 0x22, 0x50, 0x03, 0x02, 0xE2, 0xFC, 0x90, 0xFE, 0x22, 0xE0, 0x90, 0xEB, 40 + 0xF9, 0xF0, 0x90, 0xFE, 0x23, 0xE0, 0x90, 0xEB, 0xFA, 0xF0, 0x90, 0xFF, 0x81, 0xE0, 0xC2, 0xE3, 41 + 0xF0, 0x30, 0x13, 0x11, 0x90, 0xFF, 0x85, 0xE0, 0x54, 0xCF, 0x44, 0x20, 0xF0, 0x90, 0xFF, 0x81, 42 + 0x74, 0x94, 0xF0, 0x80, 0x0F, 0x90, 0xFF, 0x85, 0xE0, 0x54, 0xCF, 0x44, 0x30, 0xF0, 0x90, 0xFF, 43 + 0x81, 0x74, 0x94, 0xF0, 0x90, 0xFF, 0x81, 0xE0, 0xD2, 0xE3, 0xF0, 0x7F, 0x32, 0x7E, 0x00, 0x12, 44 + 0xE3, 0xFA, 0x78, 0x09, 0x79, 0x4D, 0x90, 0xEB, 0xFA, 0xE0, 0xFA, 0x90, 0xEB, 0xF9, 0xE0, 0xFB, 45 + 0x7C, 0x00, 0x7D, 0x00, 0x12, 0xE3, 0x22, 0x50, 0x03, 0x02, 0xE2, 0xFC, 0x12, 0xE3, 0x91, 0x78, 46 + 0x87, 0x79, 0x50, 0x90, 0xEB, 0xFA, 0xE0, 0xFA, 0x90, 0xEB, 0xF9, 0xE0, 0xFB, 0x7C, 0x00, 0x7D, 47 + 0x00, 0x12, 0xE3, 0x22, 0x50, 0x03, 0x02, 0xE2, 0xFC, 0x30, 0x13, 0x09, 0x90, 0xFE, 0x05, 0xE0, 48 + 0x54, 0xBF, 0xF0, 0x80, 0x35, 0x78, 0x37, 0x79, 0x50, 0x90, 0xEB, 0xFA, 0xE0, 0xFA, 0x90, 0xEB, 49 + 0xF9, 0xE0, 0xFB, 0x7C, 0x00, 0x7D, 0x00, 0x12, 0xE3, 0x22, 0x50, 0x03, 0x02, 0xE2, 0xFC, 0x78, 50 + 0x46, 0x79, 0x50, 0x7A, 0x00, 0x7B, 0x00, 0x7C, 0x00, 0x7D, 0x02, 0x12, 0xE3, 0x22, 0x50, 0x03, 51 + 0x02, 0xE2, 0xFC, 0x90, 0xFE, 0x05, 0xE0, 0x44, 0x40, 0xF0, 0xD3, 0x22, 0x30, 0x14, 0x14, 0x90, 52 + 0xFE, 0x04, 0xE0, 0x44, 0x06, 0xF0, 0x90, 0xFE, 0x04, 0x30, 0x14, 0x06, 0xE0, 0x70, 0xFA, 0xD3, 53 + 0x80, 0x01, 0xC3, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0x90, 0xFE, 0xCC, 0xE0, 0x44, 0x80, 0xF0, 54 + 0xC3, 0x22, 0xE8, 0x90, 0xFE, 0x15, 0xF0, 0xE9, 0x90, 0xFE, 0x14, 0xF0, 0xED, 0x90, 0xFE, 0x18, 55 + 0xF0, 0xEC, 0x90, 0xFE, 0x19, 0xF0, 0xEB, 0x90, 0xFE, 0x1A, 0xF0, 0xEA, 0x90, 0xFE, 0x1B, 0xF0, 56 + 0x74, 0xFF, 0x90, 0xFE, 0x10, 0xF0, 0x90, 0xFE, 0x11, 0xF0, 0x90, 0xFE, 0x12, 0xF0, 0xE8, 0x54, 57 + 0x80, 0xFE, 0x90, 0xFE, 0x04, 0x74, 0x01, 0xF0, 0x30, 0x14, 0x08, 0x90, 0xFE, 0x10, 0xE0, 0x54, 58 + 0x05, 0x60, 0x02, 0xD3, 0x22, 0x90, 0xFE, 0x11, 0xE0, 0x30, 0xE0, 0xEC, 0xBE, 0x80, 0x03, 0x30, 59 + 0xE1, 0xE6, 0x90, 0xFE, 0x10, 0xE0, 0x54, 0x05, 0x70, 0xE9, 0xC3, 0x22, 0x30, 0x13, 0x02, 0xC3, 60 + 0x22, 0x90, 0xFE, 0x22, 0xE0, 0x70, 0x06, 0x90, 0xFE, 0x23, 0xE0, 0x60, 0x02, 0xD3, 0x22, 0xC3, 61 + 0x22, 0x7B, 0x0F, 0x7C, 0xFE, 0x7D, 0x20, 0x7E, 0xEA, 0x7F, 0x29, 0x12, 0xE3, 0xD3, 0x30, 0x13, 62 + 0x1B, 0x90, 0xFE, 0x20, 0xE0, 0x54, 0x30, 0x64, 0x30, 0x70, 0x02, 0xD2, 0x11, 0x30, 0x13, 0x0C, 63 + 0x90, 0xFE, 0x2E, 0xE0, 0x54, 0x3C, 0x64, 0x10, 0x70, 0x02, 0xD2, 0x12, 0x30, 0x17, 0x03, 0x02, 64 + 0xE3, 0xC4, 0x80, 0x03, 0x20, 0x13, 0x00, 0xC2, 0x11, 0x90, 0xFE, 0x13, 0xE0, 0x30, 0xE2, 0x02, 65 + 0xD2, 0x11, 0x22, 0xC0, 0x04, 0xC0, 0x05, 0x8E, 0x83, 0x8F, 0x82, 0xEB, 0x60, 0x17, 0xC0, 0x82, 66 + 0xC0, 0x83, 0x8C, 0x83, 0x8D, 0x82, 0xE0, 0xA3, 0xAC, 0x83, 0xAD, 0x82, 0xD0, 0x83, 0xD0, 0x82, 67 + 0xF0, 0xA3, 0x1B, 0x80, 0xE6, 0xD0, 0x05, 0xD0, 0x04, 0x22, 0x75, 0x8A, 0x00, 0x75, 0x8C, 0xCE, 68 + 0xC2, 0x8D, 0x90, 0xEA, 0x65, 0xE4, 0xF0, 0xA3, 0xF0, 0xD2, 0x8C, 0x90, 0xEA, 0x65, 0xE0, 0xFC, 69 + 0xA3, 0xE0, 0xFD, 0xEC, 0xC3, 0x9E, 0x40, 0xF3, 0x70, 0x05, 0xED, 0xC3, 0x9F, 0x40, 0xEC, 0xC2, 70 + 0x8C, 0x22, 0xF5, 0xD3, 0xE0, 0x64, 0x01, 0x70, 0x02, 0xD2, 0x3F, 0x75, 0x17, 0x00, 0x75, 0x18, 71 + 0x00, 0x85, 0x14, 0x19, 0x75, 0x1B, 0x01, 0x12, 0x2F, 0x8C, 0x40, 0x03, 0x02, 0xE4, 0x45, 0x90, 72 + 0xEA, 0x49, 0xE5, 0x14, 0xF0, 0x05, 0x14, 0x02, 0xE2, 0xDC, 0xD2, 0x22, 0x90, 0xEA, 0x49, 0xE0, 73 + 0x64, 0xFF, 0x70, 0x02, 0x80, 0x02, 0x80, 0x12, 0x90, 0xFE, 0x44, 0x74, 0x02, 0xF0, 0x30, 0x25, 74 + 0x04, 0xE0, 0x20, 0xE1, 0xF9, 0x12, 0x2F, 0x9E, 0xC3, 0x22, 0x30, 0x3F, 0x36, 0x74, 0x88, 0x90, 75 + 0xEA, 0x44, 0xF0, 0x75, 0x17, 0x00, 0x79, 0x00, 0x7A, 0x00, 0x7B, 0x10, 0x7C, 0x02, 0x7D, 0x02, 76 + 0x12, 0x2F, 0xA7, 0x7F, 0x80, 0x12, 0x2F, 0xC5, 0x90, 0xFE, 0x45, 0xE0, 0x54, 0xFE, 0xF0, 0x90, 77 + 0xFE, 0x45, 0xE0, 0x44, 0x04, 0xF0, 0x90, 0xFE, 0x44, 0x74, 0x02, 0xF0, 0x30, 0x25, 0x04, 0xE0, 78 + 0x20, 0xE1, 0xF9, 0xD3, 0x22, 0x75, 0x8A, 0x00, 0x75, 0x8C, 0xCE, 0xC2, 0x8D, 0x90, 0xEA, 0x65, 79 + 0xE4, 0xF0, 0xA3, 0xF0, 0xD2, 0x8C, 0x90, 0xEA, 0x65, 0xE0, 0xFC, 0xA3, 0xE0, 0xFD, 0xEC, 0xC3, 80 + 0x9E, 0x40, 0xF3, 0x70, 0x05, 0xED, 0xC3, 0x9F, 0x40, 0xEC, 0xC2, 0x8C, 0x22, 0x00, 0x00, 0x00, 81 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 82 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 83 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 84 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 85 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 86 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 87 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 88 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 89 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 90 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 91 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 92 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 93 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 94 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 95 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 96 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 97 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 98 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 99 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 100 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 101 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 102 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 103 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 104 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 105 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 106 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 107 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 108 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 109 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 110 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 111 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 112 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 113 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 114 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 115 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 116 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 117 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 118 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 119 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 120 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 121 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 122 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 123 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 124 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 125 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 126 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 127 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 128 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 129 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 130 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 131 + 0x53, 0x44, 0x2D, 0x49, 0x6E, 0x69, 0x74, 0x31, 0x20, 0x20, 0x20, 0x31, 0x30, 0x30, 0x30, 0x31 }; 132 + 133 + BYTE SD_Init2[] = { 134 + 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 0xFF, 0x23, 0x74, 0x80, 0xF0, 0x90, 0xFF, 0x09, 135 + 0xE0, 0x30, 0xE5, 0xFC, 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE0, 0x92, 0x14, 0x20, 0x14, 0x0A, 0xC2, 136 + 0x0F, 0xD2, 0x10, 0xC2, 0x17, 0xC3, 0x02, 0xE0, 0xA0, 0x20, 0x13, 0x05, 0x12, 0xE3, 0x8D, 0x80, 137 + 0x03, 0x12, 0xE1, 0x1F, 0xD2, 0x0F, 0xC2, 0x10, 0xD3, 0x90, 0xF3, 0xFF, 0x75, 0xF0, 0xFF, 0x74, 138 + 0x00, 0xA3, 0xF0, 0xD5, 0xF0, 0xFB, 0x7B, 0x0F, 0x7C, 0xEA, 0x7D, 0x29, 0x7E, 0xF4, 0x7F, 0x10, 139 + 0x12, 0xE5, 0x5D, 0x90, 0xF4, 0x00, 0xE4, 0xA2, 0x14, 0x92, 0xE0, 0xA2, 0x0F, 0x92, 0xE1, 0xA2, 140 + 0x10, 0x92, 0xE2, 0xA2, 0x13, 0x92, 0xE3, 0xA2, 0x17, 0x92, 0xE4, 0xA2, 0x12, 0x92, 0xE5, 0xA2, 141 + 0x11, 0x92, 0xE6, 0xF0, 0xF0, 0x74, 0xFF, 0xA3, 0xF0, 0xA3, 0xF0, 0xA3, 0xF0, 0x90, 0xFF, 0x2A, 142 + 0x74, 0x02, 0xF0, 0xA3, 0x74, 0x00, 0xF0, 0xD3, 0x22, 0x30, 0x14, 0x14, 0x90, 0xFE, 0x04, 0xE0, 143 + 0x44, 0x06, 0xF0, 0x90, 0xFE, 0x04, 0x30, 0x14, 0x06, 0xE0, 0x70, 0xFA, 0xD3, 0x80, 0x01, 0xC3, 144 + 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0x90, 0xFE, 0xCC, 0xE0, 0x44, 0x80, 0xF0, 0x02, 0xE0, 0x39, 145 + 0xE8, 0x90, 0xFE, 0x15, 0xF0, 0xE9, 0x90, 0xFE, 0x14, 0xF0, 0xED, 0x90, 0xFE, 0x18, 0xF0, 0xEC, 146 + 0x90, 0xFE, 0x19, 0xF0, 0xEB, 0x90, 0xFE, 0x1A, 0xF0, 0xEA, 0x90, 0xFE, 0x1B, 0xF0, 0x74, 0xFF, 147 + 0x90, 0xFE, 0x10, 0xF0, 0x90, 0xFE, 0x11, 0xF0, 0x90, 0xFE, 0x12, 0xF0, 0xE8, 0x54, 0x80, 0xFE, 148 + 0x90, 0xFE, 0x04, 0x74, 0x01, 0xF0, 0x30, 0x14, 0x08, 0x90, 0xFE, 0x10, 0xE0, 0x54, 0x05, 0x60, 149 + 0x02, 0xD3, 0x22, 0x90, 0xFE, 0x11, 0xE0, 0x30, 0xE0, 0xEC, 0xBE, 0x80, 0x03, 0x30, 0xE1, 0xE6, 150 + 0x90, 0xFE, 0x10, 0xE0, 0x54, 0x05, 0x70, 0xE9, 0xC3, 0x22, 0x30, 0x13, 0x02, 0xC3, 0x22, 0x90, 151 + 0xFE, 0x22, 0xE0, 0x70, 0x06, 0x90, 0xFE, 0x23, 0xE0, 0x60, 0x02, 0xD3, 0x22, 0xC3, 0x22, 0x20, 152 + 0x12, 0x03, 0x02, 0xE3, 0x17, 0x90, 0xFE, 0x1C, 0x74, 0xFF, 0xF0, 0x90, 0xFE, 0x1D, 0x74, 0x01, 153 + 0xF0, 0x74, 0x00, 0x90, 0xFE, 0x1E, 0xF0, 0x90, 0xFE, 0x1F, 0xF0, 0x90, 0xFE, 0xCC, 0xE0, 0x54, 154 + 0x7F, 0xF0, 0x90, 0xFE, 0x06, 0xE0, 0x54, 0xF0, 0xF0, 0x90, 0xFE, 0xC0, 0x74, 0xF4, 0xF0, 0xA3, 155 + 0x74, 0x00, 0xF0, 0x90, 0xFE, 0xC6, 0x74, 0x01, 0xF0, 0xA3, 0x74, 0xFF, 0xF0, 0x90, 0xFE, 0xC5, 156 + 0xE4, 0xF0, 0x90, 0xFE, 0xC4, 0x74, 0x04, 0xF0, 0x78, 0x10, 0x79, 0x50, 0x7A, 0x00, 0x7B, 0x00, 157 + 0x7C, 0x02, 0x7D, 0x00, 0x12, 0xE0, 0xB0, 0x50, 0x03, 0x02, 0xE3, 0x17, 0x78, 0x08, 0x79, 0xE8, 158 + 0x12, 0xE0, 0xB0, 0x50, 0x03, 0x02, 0xE3, 0x17, 0x90, 0xFE, 0xC8, 0xE0, 0xF0, 0x90, 0xFE, 0xC4, 159 + 0xE0, 0x44, 0x01, 0xF0, 0x30, 0x14, 0x10, 0x90, 0xFE, 0xC8, 0xE0, 0x64, 0x01, 0x60, 0x11, 0x90, 160 + 0xFE, 0x10, 0xE0, 0x54, 0x0A, 0x60, 0xED, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0xC3, 0x80, 0x01, 161 + 0xD3, 0x40, 0x03, 0x02, 0xE3, 0x17, 0x20, 0x17, 0x02, 0x80, 0x39, 0xC3, 0x90, 0xF4, 0xD4, 0xE0, 162 + 0x90, 0xF5, 0x00, 0xF0, 0x90, 0xEB, 0xF8, 0x94, 0x01, 0xF0, 0x90, 0xF4, 0xD5, 0xE0, 0x90, 0xF5, 163 + 0x01, 0xF0, 0x90, 0xEB, 0xF7, 0x94, 0x00, 0xF0, 0x90, 0xF4, 0xD6, 0xE0, 0x90, 0xF5, 0x02, 0xF0, 164 + 0x90, 0xEB, 0xF6, 0x94, 0x00, 0xF0, 0x90, 0xF4, 0xD7, 0xE0, 0x90, 0xF5, 0x03, 0xF0, 0x90, 0xEB, 165 + 0xF5, 0x94, 0x00, 0xF0, 0x90, 0xF4, 0x00, 0x43, 0x82, 0xC4, 0xE0, 0x54, 0x03, 0xF5, 0x09, 0x90, 166 + 0xFE, 0xCC, 0xE0, 0x44, 0x80, 0xF0, 0x90, 0xFE, 0x06, 0xE0, 0x54, 0x3F, 0x44, 0x00, 0xF0, 0x90, 167 + 0xFE, 0x04, 0xE0, 0x44, 0x06, 0xF0, 0x90, 0xFE, 0x04, 0x30, 0x14, 0x06, 0xE0, 0x70, 0xFA, 0xD3, 168 + 0x80, 0x01, 0xC3, 0x74, 0x03, 0x90, 0xFE, 0x1C, 0xF0, 0x74, 0x00, 0x90, 0xFE, 0x1D, 0xF0, 0x90, 169 + 0xFE, 0x1E, 0xF0, 0x90, 0xFE, 0x1F, 0xF0, 0x78, 0x10, 0x79, 0x50, 0x7A, 0x00, 0x7B, 0x00, 0x7C, 170 + 0x00, 0x7D, 0x04, 0x12, 0xE0, 0xB0, 0x50, 0x03, 0x02, 0xE3, 0x17, 0x90, 0xFE, 0x07, 0xE0, 0xC2, 171 + 0xE6, 0xF0, 0x90, 0xFE, 0x07, 0xE0, 0xD2, 0xE0, 0xF0, 0x90, 0xFE, 0x05, 0xE0, 0xD2, 0xE7, 0xF0, 172 + 0x7B, 0x55, 0x7C, 0xAA, 0x7D, 0xAA, 0x7E, 0x55, 0x12, 0xE3, 0x35, 0x50, 0x05, 0x75, 0x08, 0x02, 173 + 0x41, 0xB0, 0x90, 0xFE, 0x07, 0xE0, 0x54, 0xBE, 0xF0, 0x90, 0xFE, 0x05, 0xE0, 0x44, 0x40, 0xF0, 174 + 0x90, 0xFE, 0x04, 0xE0, 0x44, 0x06, 0xF0, 0x90, 0xFE, 0x04, 0x30, 0x14, 0x06, 0xE0, 0x70, 0xFA, 175 + 0xD3, 0x80, 0x01, 0xC3, 0x7B, 0x5A, 0x7C, 0x5A, 0x7D, 0xA5, 0x7E, 0x00, 0x12, 0xE3, 0x35, 0x50, 176 + 0x05, 0x75, 0x08, 0x01, 0x41, 0xB0, 0x90, 0xFE, 0x05, 0xE0, 0x54, 0xBF, 0xF0, 0x02, 0xE3, 0x17, 177 + 0x90, 0xFE, 0x04, 0xE0, 0x44, 0x06, 0xF0, 0x90, 0xFE, 0x04, 0x30, 0x14, 0x06, 0xE0, 0x70, 0xFA, 178 + 0xD3, 0x80, 0x01, 0xC3, 0xE5, 0x08, 0x78, 0x86, 0x79, 0x50, 0x7A, 0x03, 0x7B, 0xB7, 0xFC, 0x7D, 179 + 0x00, 0x12, 0xE0, 0xB0, 0x50, 0x03, 0x02, 0xE3, 0x17, 0x78, 0x86, 0x79, 0x50, 0x7A, 0x03, 0x7B, 180 + 0xB9, 0x7C, 0x01, 0x7D, 0x00, 0x12, 0xE0, 0xB0, 0x40, 0xBC, 0xE5, 0x09, 0x20, 0xE1, 0x04, 0x74, 181 + 0x94, 0x80, 0x02, 0x74, 0x84, 0x90, 0xFF, 0x81, 0xF0, 0x90, 0xFE, 0x07, 0xE0, 0xD2, 0xE6, 0xF0, 182 + 0x90, 0xFF, 0x85, 0xE0, 0x54, 0xCF, 0x44, 0x30, 0xF0, 0x90, 0xFF, 0x81, 0xE0, 0xD2, 0xE3, 0xF0, 183 + 0x7F, 0x32, 0x7E, 0x00, 0x12, 0xE5, 0x84, 0x90, 0xFE, 0x06, 0xE0, 0x54, 0x3F, 0x44, 0x40, 0xF0, 184 + 0x90, 0xFE, 0x04, 0xE0, 0x44, 0x06, 0xF0, 0x90, 0xFE, 0x04, 0x30, 0x14, 0x06, 0xE0, 0x70, 0xFA, 185 + 0xD3, 0x80, 0x01, 0xC3, 0x22, 0xC0, 0x05, 0xC0, 0x06, 0x78, 0x13, 0x79, 0x68, 0x12, 0xE0, 0xB0, 186 + 0x50, 0x03, 0x02, 0xE3, 0x8B, 0xEB, 0x90, 0xFE, 0x00, 0xF0, 0xEC, 0xF0, 0x90, 0xFE, 0x12, 0xE0, 187 + 0x30, 0xE1, 0xF9, 0x90, 0xFE, 0x04, 0xE0, 0x44, 0x06, 0xF0, 0x90, 0xFE, 0x04, 0x30, 0x14, 0x06, 188 + 0xE0, 0x70, 0xFA, 0xD3, 0x80, 0x01, 0xC3, 0x78, 0x0E, 0x79, 0xE8, 0x12, 0xE0, 0xB0, 0x50, 0x03, 189 + 0x02, 0xE3, 0x8B, 0x90, 0xFE, 0x12, 0xE0, 0x20, 0xE1, 0xF9, 0xD0, 0x06, 0xD0, 0x05, 0x90, 0xFE, 190 + 0x00, 0xE0, 0x6D, 0x70, 0x06, 0xE0, 0x6E, 0x70, 0x02, 0xD3, 0x22, 0xC3, 0x22, 0x90, 0xFE, 0x06, 191 + 0xE0, 0x54, 0x3F, 0x44, 0x00, 0xF0, 0x90, 0xFE, 0x04, 0xE0, 0x44, 0x06, 0xF0, 0x90, 0xFE, 0x04, 192 + 0x30, 0x14, 0x06, 0xE0, 0x70, 0xFA, 0xD3, 0x80, 0x01, 0xC3, 0x74, 0x07, 0x90, 0xFE, 0x1C, 0xF0, 193 + 0x74, 0x00, 0x90, 0xFE, 0x1D, 0xF0, 0x90, 0xFE, 0x1E, 0xF0, 0x90, 0xFE, 0x1F, 0xF0, 0x78, 0x10, 194 + 0x79, 0x50, 0x7A, 0x00, 0x7B, 0x00, 0x30, 0x17, 0x06, 0x7C, 0x02, 0x7D, 0x00, 0x80, 0x04, 0x7C, 195 + 0x00, 0x7D, 0x08, 0x12, 0xE0, 0xB0, 0x50, 0x03, 0x02, 0xE4, 0x39, 0x78, 0x37, 0x79, 0x50, 0x90, 196 + 0xEB, 0xFA, 0xE0, 0xFA, 0x90, 0xEB, 0xF9, 0xE0, 0xFB, 0x7C, 0x00, 0x7D, 0x00, 0x12, 0xE0, 0xB0, 197 + 0x50, 0x03, 0x02, 0xE4, 0x39, 0x78, 0x73, 0x79, 0xE8, 0x7A, 0x00, 0x7B, 0x00, 0x7C, 0x00, 0x7D, 198 + 0x00, 0x12, 0xE0, 0xB0, 0x50, 0x03, 0x02, 0xE4, 0x39, 0x90, 0xFE, 0x12, 0xE0, 0x20, 0xE1, 0xF9, 199 + 0x78, 0x08, 0x90, 0xEA, 0x3F, 0xC0, 0x83, 0xC0, 0x82, 0x90, 0xFE, 0x00, 0xE0, 0xD0, 0x82, 0xD0, 200 + 0x83, 0xF0, 0xC3, 0xE5, 0x82, 0x24, 0xFF, 0xF5, 0x82, 0xE5, 0x83, 0x34, 0xFF, 0xF5, 0x83, 0xD8, 201 + 0xE4, 0x90, 0xEA, 0x3F, 0xE0, 0x54, 0x0F, 0x70, 0x25, 0x90, 0xFE, 0x07, 0xE0, 0xC2, 0xE6, 0xF0, 202 + 0x90, 0xFE, 0x06, 0xE0, 0x54, 0x3F, 0x44, 0x40, 0xF0, 0x90, 0xFE, 0x04, 0xE0, 0x44, 0x06, 0xF0, 203 + 0x90, 0xFE, 0x04, 0x30, 0x14, 0x06, 0xE0, 0x70, 0xFA, 0xD3, 0x80, 0x01, 0xC3, 0x22, 0x90, 0xFE, 204 + 0x06, 0xE0, 0x54, 0x3F, 0x44, 0x40, 0xF0, 0x90, 0xFE, 0x04, 0xE0, 0x44, 0x06, 0xF0, 0x90, 0xFE, 205 + 0x04, 0x30, 0x14, 0x06, 0xE0, 0x70, 0xFA, 0xD3, 0x80, 0x01, 0xC3, 0x7E, 0x00, 0x12, 0xE4, 0xBF, 206 + 0x40, 0x03, 0x02, 0xE4, 0xBE, 0x7E, 0x80, 0x12, 0xE4, 0xBF, 0x40, 0x03, 0x02, 0xE4, 0xBE, 0x90, 207 + 0xFF, 0x81, 0xE0, 0xC2, 0xE3, 0xF0, 0x90, 0xFF, 0x81, 0x74, 0x84, 0xF0, 0x90, 0xFE, 0x07, 0xE0, 208 + 0xD2, 0xE6, 0xF0, 0x90, 0xFF, 0x81, 0xE0, 0xD2, 0xE3, 0xF0, 0x90, 0xFE, 0x04, 0xE0, 0x44, 0x06, 209 + 0xF0, 0x90, 0xFE, 0x04, 0x30, 0x14, 0x06, 0xE0, 0x70, 0xFA, 0xD3, 0x80, 0x01, 0xC3, 0x22, 0x90, 210 + 0xFE, 0x1C, 0x74, 0x3F, 0xF0, 0x90, 0xFE, 0x1D, 0x74, 0x00, 0xF0, 0x74, 0x00, 0x90, 0xFE, 0x1E, 211 + 0xF0, 0x90, 0xFE, 0x1F, 0xF0, 0x90, 0xFE, 0xCC, 0xE0, 0x54, 0x7F, 0xF0, 0x90, 0xFE, 0x06, 0xE0, 212 + 0x54, 0xF0, 0xF0, 0x90, 0xFE, 0xC0, 0x74, 0xF4, 0xF0, 0xA3, 0x74, 0x00, 0xF0, 0x90, 0xFE, 0xC6, 213 + 0x74, 0x00, 0xF0, 0xA3, 0x74, 0x3F, 0xF0, 0x90, 0xFE, 0xC5, 0xE4, 0xF0, 0x90, 0xFE, 0xC4, 0x74, 214 + 0x04, 0xF0, 0x78, 0x06, 0x79, 0xE8, 0xAA, 0x06, 0x7B, 0xFF, 0x7C, 0xFF, 0x7D, 0x01, 0x12, 0xE0, 215 + 0xB0, 0x50, 0x03, 0x02, 0xE5, 0x5B, 0x90, 0xFE, 0xC8, 0x74, 0x01, 0xF0, 0x90, 0xFE, 0xC4, 0xE0, 216 + 0x44, 0x01, 0xF0, 0x30, 0x14, 0x10, 0x90, 0xFE, 0xC8, 0xE0, 0x64, 0x01, 0x60, 0x11, 0x90, 0xFE, 217 + 0x10, 0xE0, 0x54, 0x0A, 0x60, 0xED, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0xC3, 0x80, 0x01, 0xD3, 218 + 0x40, 0x03, 0x02, 0xE5, 0x5B, 0x90, 0xFE, 0xCC, 0xE0, 0x44, 0x80, 0xF0, 0x90, 0xF4, 0x0D, 0xE0, 219 + 0x90, 0xF4, 0x10, 0xE0, 0x64, 0x0F, 0x60, 0x03, 0xD3, 0x80, 0x01, 0xC3, 0x22, 0xC0, 0x04, 0xC0, 220 + 0x05, 0x8E, 0x83, 0x8F, 0x82, 0xEB, 0x60, 0x17, 0xC0, 0x82, 0xC0, 0x83, 0x8C, 0x83, 0x8D, 0x82, 221 + 0xE0, 0xA3, 0xAC, 0x83, 0xAD, 0x82, 0xD0, 0x83, 0xD0, 0x82, 0xF0, 0xA3, 0x1B, 0x80, 0xE6, 0xD0, 222 + 0x05, 0xD0, 0x04, 0x22, 0x75, 0x8A, 0x00, 0x75, 0x8C, 0xCE, 0xC2, 0x8D, 0x90, 0xEA, 0x65, 0xE4, 223 + 0xF0, 0xA3, 0xF0, 0xD2, 0x8C, 0x90, 0xEA, 0x65, 0xE0, 0xFC, 0xA3, 0xE0, 0xFD, 0xEC, 0xC3, 0x9E, 224 + 0x40, 0xF3, 0x70, 0x05, 0xED, 0xC3, 0x9F, 0x40, 0xEC, 0xC2, 0x8C, 0x22, 0x00, 0x00, 0x00, 0x00, 225 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 226 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 227 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 228 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 229 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 230 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 231 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 232 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 233 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 234 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 235 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 236 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 237 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 238 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 239 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 240 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 241 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 242 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 243 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 244 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 245 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 246 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 247 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 248 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 249 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 250 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 251 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 252 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 253 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 254 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 255 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 256 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 257 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 258 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 259 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 260 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 261 + 0x53, 0x44, 0x2D, 0x49, 0x6E, 0x69, 0x74, 0x32, 0x20, 0x20, 0x20, 0x31, 0x30, 0x30, 0x30, 0x31 }; 262 + 263 + BYTE SD_Rdwr[] = { 264 + 0x90, 0xF0, 0x11, 0xE0, 0x90, 0xEB, 0x2A, 0xF0, 0x90, 0xF0, 0x12, 0xE0, 0x90, 0xEB, 0x2B, 0xF0, 265 + 0x90, 0xF0, 0x13, 0xE0, 0x90, 0xEB, 0x2C, 0xF0, 0x90, 0xF0, 0x14, 0xE0, 0x90, 0xEB, 0x2D, 0xF0, 266 + 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE0, 0x92, 0x14, 0x30, 0x14, 0x3E, 0x30, 0x0F, 0x3B, 0x90, 0xEB, 267 + 0x2A, 0xE0, 0xF5, 0x10, 0xA3, 0xE0, 0xF5, 0x11, 0xA3, 0xE0, 0xF5, 0x12, 0xA3, 0xE0, 0xF5, 0x13, 268 + 0xC3, 0xE5, 0x3D, 0x13, 0xF5, 0x14, 0xE5, 0x3E, 0x13, 0xF5, 0x15, 0x85, 0x14, 0x16, 0x85, 0x15, 269 + 0x17, 0x90, 0xF0, 0x0C, 0xE0, 0x54, 0x80, 0x70, 0x12, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 270 + 0x90, 0xFF, 0x23, 0x74, 0x80, 0xF0, 0x02, 0xE2, 0x31, 0xC3, 0x22, 0x90, 0xFF, 0x09, 0xE0, 0x30, 271 + 0xE1, 0x06, 0x90, 0xFF, 0x23, 0x74, 0x80, 0xF0, 0xE5, 0x15, 0x24, 0xFF, 0x90, 0xFE, 0x1E, 0xF0, 272 + 0xE5, 0x14, 0x34, 0xFF, 0x90, 0xFE, 0x1F, 0xF0, 0x90, 0xFE, 0x1C, 0x74, 0xFF, 0xF0, 0x90, 0xFE, 273 + 0x1D, 0x74, 0x01, 0xF0, 0x90, 0xFE, 0xCC, 0xE0, 0x54, 0x7F, 0xF0, 0x90, 0xFE, 0x06, 0xE0, 0x54, 274 + 0xF0, 0xF0, 0x90, 0xFE, 0xC0, 0x74, 0xF4, 0xF0, 0xA3, 0x74, 0x00, 0xF0, 0x90, 0xFE, 0xC6, 0x74, 275 + 0x01, 0xF0, 0xA3, 0x74, 0xFF, 0xF0, 0x90, 0xFE, 0xC5, 0xE4, 0xF0, 0x90, 0xFE, 0xC4, 0x74, 0x04, 276 + 0xF0, 0x78, 0x10, 0x79, 0x50, 0x7A, 0x00, 0x7B, 0x00, 0x7C, 0x02, 0x7D, 0x00, 0x12, 0xE3, 0xEA, 277 + 0x50, 0x03, 0x02, 0xE1, 0xFA, 0x12, 0xE4, 0x44, 0x50, 0x03, 0x02, 0xE1, 0xFA, 0xAD, 0x13, 0xAC, 278 + 0x12, 0xAB, 0x11, 0xAA, 0x10, 0x80, 0x00, 0xE5, 0x15, 0x64, 0x01, 0x45, 0x14, 0x70, 0x0E, 0x78, 279 + 0x11, 0x79, 0xE8, 0x12, 0xE3, 0xEA, 0x50, 0x03, 0x02, 0xE1, 0xFA, 0x80, 0x0C, 0x78, 0x12, 0x79, 280 + 0xE8, 0x12, 0xE3, 0xEA, 0x50, 0x03, 0x02, 0xE1, 0xFA, 0x12, 0xE4, 0x44, 0x50, 0x03, 0x02, 0xE1, 281 + 0xFA, 0x30, 0x14, 0x07, 0x90, 0xFE, 0x12, 0xE0, 0x30, 0xE4, 0xF6, 0x20, 0x14, 0x03, 0x02, 0xE1, 282 + 0xFA, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE5, 0xFC, 0x90, 0xFE, 0xC8, 0x74, 0x01, 0xF0, 0x90, 0xFE, 283 + 0xC4, 0xE0, 0x44, 0x01, 0xF0, 0xC3, 0xE5, 0x17, 0x94, 0x01, 0xF5, 0x17, 0xE5, 0x16, 0x94, 0x00, 284 + 0xF5, 0x16, 0x45, 0x17, 0x60, 0x42, 0x30, 0x14, 0x10, 0x90, 0xFE, 0xC8, 0xE0, 0x64, 0x01, 0x60, 285 + 0x11, 0x90, 0xFE, 0x10, 0xE0, 0x54, 0x0A, 0x60, 0xED, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0xC3, 286 + 0x80, 0x01, 0xD3, 0x40, 0x03, 0x02, 0xE1, 0xFA, 0x90, 0xFF, 0x2A, 0x74, 0x02, 0xF0, 0xA3, 0x74, 287 + 0x00, 0xF0, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE5, 0xFC, 0x90, 0xFE, 0xC8, 0x74, 0x01, 0xF0, 0x90, 288 + 0xFE, 0xC4, 0xE0, 0x44, 0x01, 0xF0, 0x80, 0xAD, 0x30, 0x14, 0x10, 0x90, 0xFE, 0xC8, 0xE0, 0x64, 289 + 0x01, 0x60, 0x11, 0x90, 0xFE, 0x10, 0xE0, 0x54, 0x0A, 0x60, 0xED, 0x90, 0xFE, 0xD8, 0x74, 0x01, 290 + 0xF0, 0xC3, 0x80, 0x01, 0xD3, 0x40, 0x03, 0x02, 0xE1, 0xFA, 0x90, 0xFF, 0x2A, 0x74, 0x02, 0xF0, 291 + 0xA3, 0x74, 0x00, 0xF0, 0xE5, 0x15, 0x64, 0x01, 0x45, 0x14, 0x60, 0x29, 0x90, 0xFF, 0x09, 0xE0, 292 + 0x30, 0xE5, 0xFC, 0x78, 0x8C, 0x79, 0x50, 0x12, 0xE3, 0xEA, 0x50, 0x03, 0x02, 0xE1, 0xFA, 0x12, 293 + 0xE4, 0x44, 0x50, 0x11, 0x90, 0xFE, 0x22, 0xE0, 0x70, 0x20, 0x90, 0xFE, 0x23, 0xE0, 0x64, 0x80, 294 + 0x60, 0x03, 0x02, 0xE1, 0xFA, 0x90, 0xFE, 0xCC, 0xE0, 0x44, 0x80, 0xF0, 0x75, 0x3C, 0x00, 0x75, 295 + 0x3D, 0x00, 0x75, 0x3E, 0x00, 0x75, 0x3F, 0x00, 0xD3, 0x22, 0x30, 0x14, 0x14, 0x90, 0xFE, 0x04, 296 + 0xE0, 0x44, 0x06, 0xF0, 0x90, 0xFE, 0x04, 0x30, 0x14, 0x06, 0xE0, 0x70, 0xFA, 0xD3, 0x80, 0x01, 297 + 0xC3, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0x90, 0xFE, 0xCC, 0xE0, 0x44, 0x80, 0xF0, 0x75, 0x3F, 298 + 0x00, 0xC3, 0xE5, 0x17, 0x33, 0xF5, 0x3E, 0xE5, 0x16, 0x33, 0xF5, 0x3D, 0x75, 0x3C, 0x00, 0xC3, 299 + 0x22, 0xE5, 0x3E, 0x54, 0x01, 0x45, 0x3F, 0x60, 0x03, 0x02, 0xE0, 0x69, 0xE5, 0x15, 0x24, 0xFF, 300 + 0x90, 0xFE, 0x1E, 0xF0, 0xE5, 0x14, 0x34, 0xFF, 0x90, 0xFE, 0x1F, 0xF0, 0x90, 0xFE, 0x1C, 0x74, 301 + 0xFF, 0xF0, 0x90, 0xFE, 0x1D, 0x74, 0x01, 0xF0, 0x90, 0xFE, 0x06, 0xE0, 0x54, 0xF0, 0x44, 0x0F, 302 + 0xF0, 0x90, 0xFE, 0xC0, 0x74, 0xF0, 0xF0, 0xA3, 0x74, 0x00, 0xF0, 0xE5, 0x4D, 0x24, 0xFF, 0xFF, 303 + 0xE5, 0x4C, 0x34, 0xFF, 0x90, 0xFE, 0xC6, 0xF0, 0xA3, 0xEF, 0xF0, 0xE4, 0x90, 0xFE, 0xC5, 0xF0, 304 + 0x74, 0x06, 0x90, 0xFE, 0xC4, 0xF0, 0x90, 0xFE, 0xCC, 0xE0, 0x54, 0x7F, 0xF0, 0x78, 0x10, 0x79, 305 + 0x50, 0x7A, 0x00, 0x7B, 0x00, 0x7C, 0x02, 0x7D, 0x00, 0x12, 0xE3, 0xEA, 0x50, 0x03, 0x02, 0xE3, 306 + 0x9E, 0x12, 0xE4, 0x44, 0x50, 0x03, 0x02, 0xE3, 0x9E, 0xAD, 0x13, 0xAC, 0x12, 0xAB, 0x11, 0xAA, 307 + 0x10, 0x80, 0x10, 0x74, 0x00, 0xFD, 0xC3, 0xE5, 0x13, 0x33, 0xFC, 0xE5, 0x12, 0x33, 0xFB, 0xE5, 308 + 0x11, 0x33, 0xFA, 0xE5, 0x15, 0x64, 0x01, 0x45, 0x14, 0x70, 0x0E, 0x78, 0x18, 0x79, 0x68, 0x12, 309 + 0xE3, 0xEA, 0x50, 0x03, 0x02, 0xE3, 0x9E, 0x80, 0x0C, 0x78, 0x19, 0x79, 0x68, 0x12, 0xE3, 0xEA, 310 + 0x50, 0x03, 0x02, 0xE3, 0x9E, 0x12, 0xE4, 0x44, 0x50, 0x03, 0x02, 0xE3, 0x9E, 0x75, 0x1F, 0x01, 311 + 0x20, 0x2D, 0x03, 0x75, 0x1F, 0x08, 0xE5, 0x16, 0x45, 0x17, 0x70, 0x03, 0x02, 0xE3, 0x6B, 0x85, 312 + 0x1F, 0x1E, 0x30, 0x14, 0x3C, 0x90, 0xFF, 0x09, 0x30, 0x14, 0x04, 0xE0, 0x30, 0xE1, 0xF9, 0x90, 313 + 0xFE, 0xC8, 0x74, 0x01, 0xF0, 0x90, 0xFE, 0xC4, 0xE0, 0x44, 0x01, 0xF0, 0x30, 0x14, 0x10, 0x90, 314 + 0xFE, 0xC8, 0xE0, 0x64, 0x01, 0x60, 0x11, 0x90, 0xFE, 0x10, 0xE0, 0x54, 0x0A, 0x60, 0xED, 0x90, 315 + 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0xC3, 0x80, 0x01, 0xD3, 0x40, 0x03, 0x02, 0xE3, 0x9E, 0x90, 0xFE, 316 + 0x12, 0x30, 0x14, 0x2A, 0xE0, 0x30, 0xE1, 0xF9, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 317 + 0xFF, 0x23, 0x74, 0x80, 0xF0, 0x15, 0x1E, 0xE5, 0x1E, 0x70, 0xA7, 0xC3, 0xE5, 0x17, 0x94, 0x01, 318 + 0xF5, 0x17, 0xE5, 0x16, 0x94, 0x00, 0xF5, 0x16, 0x02, 0xE2, 0xF6, 0x90, 0xFE, 0x12, 0x30, 0x14, 319 + 0x2D, 0xE0, 0x20, 0xE4, 0xF9, 0xE5, 0x15, 0x64, 0x01, 0x45, 0x14, 0x60, 0x58, 0x78, 0x8C, 0x79, 320 + 0x50, 0x12, 0xE3, 0xEA, 0x50, 0x03, 0x02, 0xE3, 0x9E, 0x12, 0xE4, 0x44, 0x50, 0x03, 0x02, 0xE3, 321 + 0x9E, 0x30, 0x14, 0x41, 0x90, 0xFE, 0x12, 0xE0, 0x20, 0xE4, 0xF6, 0x02, 0xE3, 0xD5, 0x30, 0x14, 322 + 0x14, 0x90, 0xFE, 0x04, 0xE0, 0x44, 0x06, 0xF0, 0x90, 0xFE, 0x04, 0x30, 0x14, 0x06, 0xE0, 0x70, 323 + 0xFA, 0xD3, 0x80, 0x01, 0xC3, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0x90, 0xFE, 0xCC, 0xE0, 0x44, 324 + 0x80, 0xF0, 0x75, 0x3F, 0x00, 0xC3, 0xE5, 0x17, 0x33, 0xF5, 0x3E, 0xE5, 0x16, 0x33, 0xF5, 0x3D, 325 + 0x75, 0x3C, 0x00, 0xC3, 0x22, 0x90, 0xFE, 0xCC, 0xE0, 0x44, 0x80, 0xF0, 0x75, 0x3C, 0x00, 0x75, 326 + 0x3D, 0x00, 0x75, 0x3E, 0x00, 0x75, 0x3F, 0x00, 0xD3, 0x22, 0xE8, 0x90, 0xFE, 0x15, 0xF0, 0xE9, 327 + 0x90, 0xFE, 0x14, 0xF0, 0xED, 0x90, 0xFE, 0x18, 0xF0, 0xEC, 0x90, 0xFE, 0x19, 0xF0, 0xEB, 0x90, 328 + 0xFE, 0x1A, 0xF0, 0xEA, 0x90, 0xFE, 0x1B, 0xF0, 0x74, 0xFF, 0x90, 0xFE, 0x10, 0xF0, 0x90, 0xFE, 329 + 0x11, 0xF0, 0x90, 0xFE, 0x12, 0xF0, 0xE8, 0x54, 0x80, 0xFE, 0x90, 0xFE, 0x04, 0x74, 0x01, 0xF0, 330 + 0x30, 0x14, 0x08, 0x90, 0xFE, 0x10, 0xE0, 0x54, 0x05, 0x60, 0x02, 0xD3, 0x22, 0x90, 0xFE, 0x11, 331 + 0xE0, 0x30, 0xE0, 0xEC, 0xBE, 0x80, 0x03, 0x30, 0xE1, 0xE6, 0x90, 0xFE, 0x10, 0xE0, 0x54, 0x05, 332 + 0x70, 0xE9, 0xC3, 0x22, 0x30, 0x13, 0x02, 0xC3, 0x22, 0x90, 0xFE, 0x22, 0xE0, 0x70, 0x06, 0x90, 333 + 0xFE, 0x23, 0xE0, 0x60, 0x02, 0xD3, 0x22, 0xC3, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 334 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 335 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 336 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 337 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 338 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 339 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 340 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 341 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 342 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 343 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 344 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 345 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 346 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 347 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 348 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 349 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 350 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 351 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 352 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 353 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 354 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 355 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 356 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 357 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 358 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 359 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 360 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 361 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 362 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 363 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 364 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 365 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 366 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 367 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 368 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 369 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 370 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 371 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 372 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 373 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 374 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 375 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 376 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 377 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 378 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 379 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 380 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 381 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 382 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 383 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 384 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 385 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 386 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 387 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 388 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 389 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 390 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 391 + 0x53, 0x44, 0x2D, 0x52, 0x57, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x31, 0x30, 0x30, 0x30, 0x31 }; 392 + 393 + BYTE MS_Init[] = { 394 + 0x90, 0xF0, 0x15, 0xE0, 0xF5, 0x1C, 0x11, 0x2C, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 395 + 0xFF, 0x23, 0x74, 0x80, 0xF0, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE5, 0xFC, 0x51, 0x59, 0x75, 0x3F, 396 + 0x00, 0x75, 0x3E, 0x00, 0x75, 0x3D, 0x00, 0x75, 0x3C, 0x00, 0xD3, 0x22, 0x90, 0xFF, 0x83, 0xE0, 397 + 0xA2, 0xE1, 0x92, 0x25, 0x20, 0x25, 0x06, 0xC2, 0x1F, 0xD2, 0x19, 0xC3, 0x22, 0x7F, 0x02, 0x12, 398 + 0x2F, 0xCB, 0x20, 0x19, 0x05, 0x30, 0x1F, 0x02, 0xD3, 0x22, 0x90, 0xEA, 0x44, 0x74, 0x80, 0xF0, 399 + 0x7F, 0x10, 0x12, 0x2F, 0xC5, 0x90, 0xFE, 0x47, 0xE0, 0x44, 0x80, 0xF0, 0x78, 0x00, 0xE8, 0xC3, 400 + 0x94, 0x04, 0x50, 0x0A, 0x7F, 0x88, 0x7E, 0x13, 0x12, 0xE4, 0xA6, 0x08, 0x80, 0xF0, 0x90, 0xFE, 401 + 0x45, 0xE0, 0x54, 0xFB, 0xF0, 0x90, 0xFE, 0x47, 0xE0, 0x54, 0xBF, 0xF0, 0x90, 0xFE, 0x45, 0xE0, 402 + 0x54, 0xFE, 0xF0, 0x90, 0xFE, 0x45, 0xE0, 0x54, 0x7F, 0xF0, 0x90, 0xFE, 0x46, 0xE0, 0x44, 0x40, 403 + 0xF0, 0x90, 0xFE, 0x45, 0xE0, 0x54, 0xC7, 0x44, 0x18, 0xF0, 0x90, 0xFE, 0x47, 0xE0, 0x44, 0x08, 404 + 0xF0, 0x90, 0xFE, 0x45, 0xE0, 0x44, 0x40, 0xF0, 0x7F, 0x32, 0x7E, 0x00, 0x12, 0xE4, 0xA6, 0x90, 405 + 0xFE, 0x51, 0xE0, 0x54, 0x33, 0xF0, 0x90, 0xFE, 0x44, 0x74, 0x02, 0xF0, 0x30, 0x25, 0x04, 0xE0, 406 + 0x20, 0xE1, 0xF9, 0x90, 0xFE, 0x51, 0xE0, 0x54, 0x0F, 0xF0, 0x90, 0xFE, 0x44, 0x74, 0x02, 0xF0, 407 + 0x30, 0x25, 0x04, 0xE0, 0x20, 0xE1, 0xF9, 0x90, 0xFE, 0x44, 0x74, 0x04, 0xF0, 0x30, 0x25, 0x04, 408 + 0xE0, 0x20, 0xE2, 0xF9, 0x90, 0xFE, 0x4C, 0xE0, 0xF0, 0x90, 0xFE, 0x4D, 0xE0, 0xF0, 0x90, 0xFE, 409 + 0x48, 0x74, 0x7F, 0xF0, 0x90, 0xFE, 0x49, 0x74, 0x9F, 0xF0, 0x90, 0xFE, 0x51, 0xE0, 0x54, 0x3C, 410 + 0x44, 0x02, 0xF0, 0x90, 0xFE, 0x44, 0x74, 0x02, 0xF0, 0x30, 0x25, 0x04, 0xE0, 0x20, 0xE1, 0xF9, 411 + 0x90, 0xFE, 0x46, 0xE0, 0x44, 0x20, 0xF0, 0x79, 0x02, 0x7A, 0x06, 0x7B, 0x00, 0x7C, 0x00, 0x7D, 412 + 0x06, 0x7E, 0xEB, 0x7F, 0xC9, 0x12, 0x2F, 0xA7, 0x40, 0x03, 0x02, 0xE2, 0x37, 0xC2, 0x45, 0xC2, 413 + 0x1E, 0x90, 0xEB, 0xCB, 0xE0, 0x64, 0x01, 0x70, 0x65, 0x90, 0xEB, 0xCD, 0xE0, 0x70, 0x5F, 0x90, 414 + 0xEB, 0xCE, 0xE0, 0x60, 0x08, 0x54, 0x03, 0x60, 0x55, 0xD2, 0x1E, 0x80, 0x09, 0x90, 0xEB, 0xC9, 415 + 0xE0, 0x30, 0xE0, 0x02, 0xD2, 0x1E, 0x90, 0xEA, 0x45, 0x74, 0x01, 0xF0, 0x75, 0x0B, 0x00, 0xE5, 416 + 0x0B, 0xC3, 0x94, 0x80, 0x50, 0x31, 0x12, 0x2F, 0xB9, 0x40, 0x03, 0x02, 0xE2, 0x37, 0x90, 0xEB, 417 + 0xC8, 0xE0, 0x54, 0x80, 0x70, 0x0B, 0x7F, 0x38, 0x7E, 0x13, 0x12, 0xE4, 0xA6, 0x05, 0x0B, 0x80, 418 + 0xDE, 0x12, 0x2F, 0xB9, 0x40, 0x03, 0x02, 0xE2, 0x37, 0x90, 0xEB, 0xC8, 0xE0, 0xF9, 0x54, 0x40, 419 + 0x60, 0x0A, 0xE9, 0x54, 0x01, 0x70, 0x03, 0x02, 0xE2, 0x37, 0xD2, 0x1E, 0x80, 0x24, 0x90, 0xEB, 420 + 0xCB, 0xE0, 0x64, 0x00, 0x60, 0x03, 0x02, 0xE2, 0x37, 0x90, 0xEA, 0x45, 0x74, 0x00, 0xF0, 0x7F, 421 + 0x90, 0x12, 0x2F, 0xC5, 0x12, 0xE2, 0xB0, 0x40, 0x03, 0x02, 0xE2, 0x37, 0xD2, 0x1F, 0xC2, 0x19, 422 + 0xD3, 0x22, 0x90, 0xEA, 0x44, 0x74, 0x00, 0xF0, 0x75, 0x17, 0x00, 0x79, 0x00, 0x7A, 0x00, 0x7B, 423 + 0x10, 0x7C, 0x02, 0x7D, 0x02, 0x12, 0x2F, 0xA7, 0x40, 0x02, 0x80, 0x5B, 0x7F, 0x80, 0x12, 0x2F, 424 + 0xC5, 0x90, 0xFE, 0x45, 0xE0, 0x54, 0xFE, 0xF0, 0x90, 0xFE, 0x45, 0xE0, 0x44, 0x04, 0xF0, 0x90, 425 + 0xEB, 0xCC, 0xE0, 0x64, 0x07, 0x70, 0x2D, 0x90, 0xEA, 0x44, 0x74, 0x40, 0xF0, 0x75, 0x17, 0x00, 426 + 0x79, 0x00, 0x7A, 0x00, 0x7B, 0x10, 0x7C, 0x02, 0x7D, 0x02, 0x12, 0x2F, 0xA7, 0x40, 0x02, 0x80, 427 + 0x26, 0x7F, 0x80, 0x12, 0x2F, 0xC5, 0x90, 0xFE, 0x45, 0xE0, 0x54, 0xFA, 0xF0, 0x90, 0xFE, 0x45, 428 + 0xE0, 0x44, 0x01, 0xF0, 0x90, 0xEA, 0x45, 0xE0, 0x60, 0x07, 0x12, 0x2F, 0xCE, 0x40, 0x02, 0x80, 429 + 0x06, 0xD2, 0x1F, 0xC2, 0x19, 0xD3, 0x22, 0xE4, 0x90, 0xFE, 0x48, 0xF0, 0x90, 0xFE, 0x49, 0xF0, 430 + 0x90, 0xFE, 0x4C, 0xE0, 0xF0, 0x90, 0xFE, 0x4D, 0xE0, 0xF0, 0x90, 0xFE, 0x47, 0xE0, 0x54, 0x7F, 431 + 0xF0, 0xC2, 0x25, 0xC2, 0x1F, 0xD2, 0x19, 0xC3, 0x22, 0x90, 0xEA, 0x45, 0xE0, 0x64, 0x01, 0x70, 432 + 0x03, 0xD3, 0x80, 0x01, 0xC3, 0xE4, 0x92, 0xE3, 0xC0, 0xE0, 0x90, 0xEB, 0xCC, 0xE0, 0x64, 0x07, 433 + 0x70, 0x03, 0xD3, 0x80, 0x01, 0xC3, 0xD0, 0xE0, 0x92, 0xE4, 0xA2, 0x25, 0x92, 0xE0, 0xA2, 0x1F, 434 + 0x92, 0xE1, 0xA2, 0x19, 0x92, 0xE2, 0xA2, 0x1E, 0x92, 0xE6, 0x90, 0xF4, 0x00, 0xF0, 0x74, 0xFF, 435 + 0xA3, 0xF0, 0xA3, 0xF0, 0xA3, 0xF0, 0xA3, 0x7B, 0x40, 0x7C, 0xEB, 0x7D, 0x6F, 0xAE, 0x83, 0xAF, 436 + 0x82, 0x12, 0x2F, 0xC8, 0x90, 0xFF, 0x2A, 0x74, 0x02, 0xF0, 0xA3, 0x74, 0x00, 0xF0, 0xD3, 0x22, 437 + 0xC2, 0x1E, 0x74, 0xFF, 0x90, 0xEA, 0x49, 0xF0, 0x90, 0xFE, 0x44, 0x74, 0x02, 0xF0, 0x30, 0x25, 438 + 0x04, 0xE0, 0x20, 0xE1, 0xF9, 0x90, 0xFF, 0x09, 0x30, 0x25, 0x07, 0xE0, 0x30, 0xE5, 0xF9, 0xD3, 439 + 0x80, 0x01, 0xC3, 0x40, 0x01, 0x22, 0xC2, 0x1A, 0xC2, 0x22, 0x75, 0x14, 0x00, 0xE5, 0x14, 0x64, 440 + 0x0C, 0x70, 0x03, 0x02, 0xE4, 0x4B, 0x75, 0x17, 0x00, 0x75, 0x18, 0x00, 0x85, 0x14, 0x19, 0x75, 441 + 0x1B, 0x00, 0x12, 0x2F, 0x8C, 0x40, 0x03, 0x02, 0xE4, 0x46, 0x30, 0x41, 0x03, 0x02, 0xE4, 0x46, 442 + 0x90, 0xEB, 0xDD, 0xE0, 0x20, 0xE7, 0x03, 0x02, 0xE4, 0x46, 0x90, 0xEB, 0xDE, 0xE0, 0x20, 0xE2, 443 + 0x02, 0x80, 0x03, 0x02, 0xE4, 0x46, 0x90, 0xF4, 0x00, 0xE0, 0xFE, 0x90, 0xF4, 0x01, 0xE0, 0x64, 444 + 0x01, 0x4E, 0x60, 0x03, 0x02, 0xE4, 0x46, 0x90, 0xEA, 0x49, 0xE0, 0x64, 0xFF, 0x60, 0x03, 0x02, 445 + 0xE4, 0x4B, 0x90, 0xF5, 0xA0, 0xE0, 0x64, 0x01, 0x60, 0x03, 0x02, 0xE4, 0x46, 0x90, 0xF5, 0xD6, 446 + 0xE0, 0x64, 0x01, 0x60, 0x03, 0x02, 0xE4, 0x46, 0x90, 0xF5, 0xD8, 0xE0, 0xFF, 0xC3, 0x74, 0x03, 447 + 0x9F, 0x50, 0x03, 0x02, 0xE4, 0x46, 0xEF, 0x60, 0x04, 0xD2, 0x1E, 0x80, 0x0B, 0xC2, 0x1E, 0x90, 448 + 0xEB, 0xC9, 0xE0, 0x30, 0xE0, 0x02, 0xD2, 0x1E, 0x90, 0xF5, 0xA2, 0xE0, 0xFE, 0x90, 0xF5, 0xA3, 449 + 0xE0, 0xFF, 0x25, 0xE0, 0x90, 0xEA, 0x47, 0xF0, 0xE4, 0x74, 0x10, 0x9F, 0x74, 0x00, 0x9E, 0x50, 450 + 0x03, 0x02, 0xE4, 0x46, 0x90, 0xF5, 0xA4, 0xE0, 0xFE, 0x90, 0xF5, 0xA5, 0xE0, 0xFF, 0xC3, 0x74, 451 + 0x00, 0x9F, 0x74, 0x20, 0x9E, 0x50, 0x03, 0x02, 0xE4, 0x46, 0xEE, 0x4F, 0x70, 0x03, 0x02, 0xE4, 452 + 0x46, 0x90, 0xF5, 0xA6, 0xE0, 0xFE, 0x90, 0xF5, 0xA7, 0xE0, 0xFF, 0xEE, 0x4F, 0x70, 0x03, 0x02, 453 + 0xE4, 0x46, 0x90, 0xF5, 0x78, 0xE0, 0x64, 0x01, 0x60, 0x03, 0x02, 0xE4, 0x46, 0x90, 0xF5, 0x74, 454 + 0xE0, 0xFC, 0x90, 0xF5, 0x75, 0xE0, 0xFD, 0x90, 0xF5, 0x76, 0xE0, 0x90, 0xEA, 0x5B, 0xF0, 0xFE, 455 + 0x90, 0xF5, 0x77, 0xE0, 0x90, 0xEA, 0x5C, 0xF0, 0xFF, 0x4E, 0x4D, 0x4C, 0x70, 0x03, 0x02, 0xE4, 456 + 0x46, 0x90, 0xF5, 0x70, 0xE0, 0xFC, 0x90, 0xF5, 0x71, 0xE0, 0xFD, 0x90, 0xF5, 0x72, 0xE0, 0xFE, 457 + 0x90, 0xF5, 0x73, 0xE0, 0xFF, 0xEC, 0x90, 0xEA, 0x55, 0xF0, 0xED, 0x90, 0xEA, 0x56, 0xF0, 0xEE, 458 + 0x90, 0xEA, 0x57, 0xF0, 0xEF, 0x90, 0xEA, 0x58, 0xF0, 0xEC, 0x64, 0xFF, 0x70, 0x12, 0xED, 0x64, 459 + 0xFF, 0x70, 0x0D, 0xEE, 0x64, 0xFF, 0x70, 0x08, 0xEF, 0x64, 0xFF, 0x70, 0x03, 0x02, 0xE4, 0x46, 460 + 0xC2, 0x3F, 0x90, 0xF5, 0xD3, 0xE0, 0x64, 0x01, 0x70, 0x02, 0xD2, 0x3F, 0x75, 0x17, 0x00, 0x75, 461 + 0x18, 0x00, 0x85, 0x14, 0x19, 0x75, 0x1B, 0x01, 0x12, 0x2F, 0x8C, 0x40, 0x03, 0x02, 0xE4, 0x46, 462 + 0x90, 0xEA, 0x49, 0xE5, 0x14, 0xF0, 0x05, 0x14, 0x02, 0xE2, 0xDD, 0xD2, 0x22, 0x90, 0xEA, 0x49, 463 + 0xE0, 0x64, 0xFF, 0x70, 0x02, 0x80, 0x02, 0x80, 0x12, 0x90, 0xFE, 0x44, 0x74, 0x02, 0xF0, 0x30, 464 + 0x25, 0x04, 0xE0, 0x20, 0xE1, 0xF9, 0x12, 0x2F, 0x9E, 0xC3, 0x22, 0x30, 0x3F, 0x36, 0x74, 0x88, 465 + 0x90, 0xEA, 0x44, 0xF0, 0x75, 0x17, 0x00, 0x79, 0x00, 0x7A, 0x00, 0x7B, 0x10, 0x7C, 0x02, 0x7D, 466 + 0x02, 0x12, 0x2F, 0xA7, 0x7F, 0x80, 0x12, 0x2F, 0xC5, 0x90, 0xFE, 0x45, 0xE0, 0x54, 0xFE, 0xF0, 467 + 0x90, 0xFE, 0x45, 0xE0, 0x44, 0x04, 0xF0, 0x90, 0xFE, 0x44, 0x74, 0x02, 0xF0, 0x30, 0x25, 0x04, 468 + 0xE0, 0x20, 0xE1, 0xF9, 0xD3, 0x22, 0x75, 0x8A, 0x00, 0x75, 0x8C, 0xCE, 0xC2, 0x8D, 0x90, 0xEA, 469 + 0x65, 0xE4, 0xF0, 0xA3, 0xF0, 0xD2, 0x8C, 0x90, 0xEA, 0x65, 0xE0, 0xFC, 0xA3, 0xE0, 0xFD, 0xEC, 470 + 0xC3, 0x9E, 0x40, 0xF3, 0x70, 0x05, 0xED, 0xC3, 0x9F, 0x40, 0xEC, 0xC2, 0x8C, 0x22, 0x00, 0x00, 471 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 472 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 473 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 474 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 475 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 476 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 477 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 478 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 479 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 480 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 481 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 482 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 483 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 484 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 485 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 486 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 487 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 488 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 489 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 490 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 491 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 492 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 493 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 494 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 495 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 496 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 497 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 498 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 499 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 500 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 501 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 502 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 503 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 504 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 505 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 506 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 507 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 508 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 509 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 510 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 511 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 512 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 513 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 514 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 515 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 516 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 517 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 518 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 519 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 520 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 521 + 0x4D, 0x53, 0x2D, 0x49, 0x6E, 0x69, 0x74, 0x20, 0x20, 0x20, 0x20, 0x31, 0x30, 0x30, 0x30, 0x30 }; 522 + 523 + BYTE MSP_Rdwr[] = { 524 + 0x90, 0xF0, 0x10, 0xE0, 0x90, 0xEA, 0x46, 0xF0, 0xB4, 0x04, 0x03, 0x02, 0xE1, 0x1E, 0x90, 0xFF, 525 + 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 0xFF, 0x23, 0x74, 0x80, 0xF0, 0x90, 0xFF, 0x09, 0xE0, 0x30, 526 + 0xE5, 0xFC, 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE1, 0x92, 0x25, 0x40, 0x01, 0x22, 0x20, 0x1F, 0x02, 527 + 0xC3, 0x22, 0x30, 0x45, 0x02, 0xC3, 0x22, 0xC3, 0xE5, 0x3D, 0x13, 0xF5, 0x08, 0xE5, 0x3E, 0x13, 528 + 0xF5, 0x09, 0x78, 0x96, 0x79, 0x20, 0xAA, 0x08, 0xAB, 0x09, 0x12, 0xE2, 0x53, 0x20, 0x1D, 0x10, 529 + 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE1, 0x92, 0x25, 0x30, 0x25, 0x03, 0x30, 0x24, 0xEF, 0xD2, 0x24, 530 + 0x20, 0x23, 0x10, 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE1, 0x92, 0x25, 0x30, 0x25, 0x03, 0x30, 0x24, 531 + 0xEF, 0xD2, 0x24, 0x30, 0x24, 0x02, 0xC3, 0x22, 0xC2, 0x24, 0xC2, 0x23, 0x90, 0xEA, 0x4B, 0xE0, 532 + 0x30, 0xE3, 0x0B, 0xC2, 0x25, 0x90, 0xFF, 0x85, 0xE0, 0x54, 0xFD, 0xF0, 0xC3, 0x22, 0x30, 0xE2, 533 + 0x78, 0x90, 0xFF, 0x09, 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE1, 0x92, 0x25, 0x30, 0x25, 0x0A, 0x90, 534 + 0xFF, 0x09, 0xE0, 0x30, 0xE5, 0xEE, 0xD3, 0x80, 0x01, 0xC3, 0x40, 0x01, 0x22, 0x79, 0x00, 0x90, 535 + 0xFE, 0x46, 0xE0, 0x54, 0xF0, 0x49, 0xF0, 0x78, 0x2D, 0x12, 0x2F, 0xAA, 0x7E, 0xF4, 0x7F, 0x00, 536 + 0x7D, 0x00, 0x7C, 0x02, 0x12, 0x2F, 0xC2, 0x20, 0x1D, 0x10, 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE1, 537 + 0x92, 0x25, 0x30, 0x25, 0x03, 0x30, 0x24, 0xEF, 0xD2, 0x24, 0x30, 0x24, 0x13, 0x75, 0x3F, 0x00, 538 + 0xC3, 0xE5, 0x09, 0x33, 0xF5, 0x3E, 0xE5, 0x08, 0x33, 0xF5, 0x3D, 0x75, 0x3C, 0x00, 0xC3, 0x22, 539 + 0x90, 0xFF, 0x2A, 0x74, 0x02, 0xF0, 0xA3, 0x74, 0x00, 0xF0, 0xE5, 0x09, 0x24, 0xFF, 0xF5, 0x09, 540 + 0xE5, 0x08, 0x34, 0xFF, 0xF5, 0x08, 0x02, 0xE0, 0x60, 0x90, 0xEA, 0x4B, 0xE0, 0x20, 0xE0, 0x03, 541 + 0x02, 0xE0, 0x60, 0xE4, 0xF5, 0x3F, 0xF5, 0x3E, 0xF5, 0x3D, 0xF5, 0x3C, 0xD3, 0x22, 0x90, 0xFF, 542 + 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 0xFF, 0x23, 0x74, 0x80, 0xF0, 0x90, 0xFF, 0x09, 0xE0, 0x30, 543 + 0xE5, 0xFC, 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE1, 0x92, 0x25, 0x40, 0x01, 0x22, 0x20, 0x1F, 0x02, 544 + 0xC3, 0x22, 0x30, 0x1E, 0x02, 0xC3, 0x22, 0xC3, 0xE5, 0x3D, 0x13, 0xF5, 0x08, 0xE5, 0x3E, 0x13, 545 + 0xF5, 0x09, 0x78, 0x96, 0x79, 0x21, 0xAA, 0x08, 0xAB, 0x09, 0x12, 0xE2, 0x53, 0x20, 0x1D, 0x10, 546 + 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE1, 0x92, 0x25, 0x30, 0x25, 0x03, 0x30, 0x24, 0xEF, 0xD2, 0x24, 547 + 0x30, 0x2D, 0x05, 0x75, 0x0A, 0x01, 0x80, 0x03, 0x75, 0x0A, 0x08, 0x20, 0x23, 0x10, 0x90, 0xFF, 548 + 0x83, 0xE0, 0xA2, 0xE1, 0x92, 0x25, 0x30, 0x25, 0x03, 0x30, 0x24, 0xEF, 0xD2, 0x24, 0x30, 0x24, 549 + 0x02, 0xC3, 0x22, 0xC2, 0x24, 0xC2, 0x23, 0x90, 0xEA, 0x4B, 0xE0, 0x30, 0xE1, 0x0B, 0xC2, 0x25, 550 + 0x90, 0xFF, 0x85, 0xE0, 0x54, 0xFD, 0xF0, 0xC3, 0x22, 0x20, 0xE2, 0x03, 0x02, 0xE2, 0x3E, 0x79, 551 + 0x0F, 0x90, 0xFE, 0x46, 0xE0, 0x54, 0xF0, 0x49, 0xF0, 0x75, 0x0B, 0x00, 0xE5, 0x0B, 0xC3, 0x95, 552 + 0x0A, 0x50, 0x43, 0x90, 0xFF, 0x09, 0x30, 0x25, 0x0B, 0xE0, 0x30, 0xE1, 0xF9, 0x90, 0xFF, 0x09, 553 + 0xF0, 0xD3, 0x80, 0x01, 0xC3, 0x50, 0x0F, 0xAF, 0x0B, 0x7C, 0xF0, 0x7D, 0x00, 0xAB, 0x4D, 0xAA, 554 + 0x4C, 0x12, 0x2F, 0xBF, 0x40, 0x0F, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 0xFF, 0x23, 555 + 0x74, 0x80, 0xF0, 0xC3, 0x22, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 0xFF, 0x23, 0x74, 556 + 0x80, 0xF0, 0x05, 0x0B, 0x80, 0xB6, 0x20, 0x1D, 0x10, 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE1, 0x92, 557 + 0x25, 0x30, 0x25, 0x03, 0x30, 0x24, 0xEF, 0xD2, 0x24, 0x30, 0x24, 0x13, 0x75, 0x3F, 0x00, 0xC3, 558 + 0xE5, 0x09, 0x33, 0xF5, 0x3E, 0xE5, 0x08, 0x33, 0xF5, 0x3D, 0x75, 0x3C, 0x00, 0xC3, 0x22, 0xE5, 559 + 0x09, 0x24, 0xFF, 0xF5, 0x09, 0xE5, 0x08, 0x34, 0xFF, 0xF5, 0x08, 0x02, 0xE1, 0x7B, 0x90, 0xEA, 560 + 0x4B, 0xE0, 0x20, 0xE0, 0x03, 0x02, 0xE1, 0x7B, 0xE4, 0xF5, 0x3F, 0xF5, 0x3E, 0xF5, 0x3D, 0xF5, 561 + 0x3C, 0xD3, 0x22, 0x90, 0xFE, 0x4C, 0xE0, 0xF0, 0x90, 0xFE, 0x4D, 0xE0, 0xF0, 0xC2, 0x24, 0xC2, 562 + 0x23, 0xC2, 0x1D, 0x90, 0xFE, 0x50, 0xE8, 0xF0, 0x90, 0xFE, 0x40, 0xE9, 0xF0, 0x90, 0xFE, 0x40, 563 + 0xEA, 0xF0, 0x90, 0xFE, 0x40, 0xEB, 0xF0, 0x90, 0xEB, 0x2A, 0xE0, 0x90, 0xFE, 0x40, 0xF0, 0x90, 564 + 0xEB, 0x2B, 0xE0, 0x90, 0xFE, 0x40, 0xF0, 0x90, 0xEB, 0x2C, 0xE0, 0x90, 0xFE, 0x40, 0xF0, 0x90, 565 + 0xEB, 0x2D, 0xE0, 0x90, 0xFE, 0x40, 0xF0, 0x90, 0xFE, 0x44, 0x74, 0x01, 0xF0, 0x22, 0x00, 0x00, 566 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 567 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 568 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 569 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 570 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 571 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 572 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 573 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 574 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 575 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 576 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 577 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 578 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 579 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 580 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 581 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 582 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 583 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 584 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 585 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 586 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 587 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 588 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 589 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 590 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 591 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 592 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 593 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 594 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 595 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 596 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 597 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 598 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 599 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 600 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 601 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 602 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 603 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 604 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 605 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 606 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 607 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 608 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 609 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 610 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 611 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 612 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 613 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 614 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 615 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 616 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 617 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 618 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 619 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 620 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 621 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 622 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 623 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 624 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 625 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 626 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 627 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 628 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 629 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 630 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 631 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 632 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 633 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 634 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 635 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 636 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 637 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 638 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 639 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 640 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 641 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 642 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 643 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 644 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 645 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 646 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 647 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 648 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 649 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 650 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 651 + 0x4D, 0x53, 0x50, 0x2D, 0x52, 0x57, 0x20, 0x20, 0x20, 0x20, 0x20, 0x31, 0x30, 0x30, 0x30, 0x30 }; 652 + 653 + BYTE MS_Rdwr[] = { 654 + 0x90, 0xF0, 0x10, 0xE0, 0x90, 0xEA, 0x46, 0xF0, 0xB4, 0x02, 0x02, 0x80, 0x36, 0x90, 0xF0, 0x11, 655 + 0xE0, 0xF5, 0x17, 0x90, 0xF0, 0x12, 0xE0, 0xF5, 0x18, 0x90, 0xF0, 0x13, 0xE0, 0xF5, 0x19, 0x90, 656 + 0xF0, 0x14, 0xE0, 0xF5, 0x1B, 0x90, 0xF0, 0x15, 0xE0, 0xF5, 0x1C, 0x90, 0xF0, 0x16, 0xE0, 0xF5, 657 + 0x1D, 0x90, 0xF0, 0x17, 0xE0, 0xF5, 0x1E, 0x90, 0xF0, 0x18, 0xE0, 0xF5, 0x1F, 0x90, 0xF0, 0x19, 658 + 0xE0, 0xF5, 0x10, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 0xFF, 0x23, 0x74, 0x80, 0xF0, 659 + 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE5, 0xFC, 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE1, 0x92, 0x25, 0x40, 660 + 0x01, 0x22, 0x90, 0xEA, 0x46, 0xE0, 0xB4, 0x02, 0x02, 0x80, 0x2B, 0xB4, 0x03, 0x03, 0x02, 0xE0, 661 + 0x96, 0xB4, 0x04, 0x05, 0xD2, 0x21, 0x02, 0xE2, 0xBC, 0xB4, 0x08, 0x0E, 0x85, 0x1C, 0x11, 0x85, 662 + 0x1D, 0x12, 0x85, 0x10, 0x1B, 0xC2, 0x21, 0x02, 0xE2, 0xBC, 0xB4, 0x06, 0x03, 0x02, 0xE2, 0x2F, 663 + 0xB4, 0x05, 0x03, 0x02, 0xE2, 0x7A, 0x20, 0x1F, 0x02, 0xC3, 0x22, 0x90, 0xEA, 0x46, 0xE0, 0xB4, 664 + 0x03, 0x03, 0x02, 0xE1, 0x94, 0xC3, 0xE5, 0x3D, 0x13, 0xF5, 0x14, 0xE5, 0x3E, 0x13, 0xF5, 0x15, 665 + 0x90, 0xEB, 0x2A, 0xE0, 0xFC, 0x90, 0xEB, 0x2B, 0xE0, 0xFD, 0x90, 0xEB, 0x2C, 0xE0, 0xFE, 0x90, 666 + 0xEB, 0x2D, 0xE0, 0xFF, 0x90, 0xEA, 0x47, 0xE0, 0x14, 0xFB, 0x60, 0x12, 0xC3, 0xEC, 0x13, 0xFC, 667 + 0xED, 0x13, 0xFD, 0xEE, 0x13, 0xFE, 0xEF, 0x13, 0xFF, 0xC3, 0xEB, 0x13, 0x80, 0xEB, 0x8E, 0x1E, 668 + 0x8F, 0x1F, 0x90, 0xEB, 0x2D, 0xE0, 0xFF, 0x90, 0xEA, 0x47, 0xE0, 0x14, 0x5F, 0xF5, 0x1B, 0xD2, 669 + 0x1A, 0x90, 0xEA, 0x47, 0xE0, 0xC3, 0x95, 0x1B, 0xF5, 0x16, 0xE5, 0x14, 0x70, 0x0A, 0xE5, 0x16, 670 + 0xD3, 0x95, 0x15, 0x40, 0x03, 0x85, 0x15, 0x16, 0xE5, 0x1E, 0xF5, 0x18, 0xE5, 0x1F, 0xF5, 0x19, 671 + 0x75, 0x17, 0x00, 0x90, 0xEA, 0x5C, 0xE0, 0xF8, 0x90, 0xEB, 0x6D, 0xE0, 0x65, 0x18, 0x70, 0x08, 672 + 0xA3, 0xE0, 0x65, 0x19, 0x70, 0x03, 0x80, 0x07, 0xA3, 0xA3, 0xD8, 0xEF, 0xC3, 0x80, 0x01, 0xD3, 673 + 0x40, 0x4F, 0xE5, 0x16, 0x64, 0x01, 0x70, 0x07, 0x12, 0x2F, 0x8C, 0x50, 0x41, 0x80, 0x07, 0xAB, 674 + 0x16, 0x12, 0xE5, 0x60, 0x50, 0x38, 0xC3, 0xE5, 0x15, 0x95, 0x16, 0xF5, 0x15, 0xE5, 0x14, 0x94, 675 + 0x00, 0xF5, 0x14, 0xE5, 0x14, 0x45, 0x15, 0x60, 0x17, 0x05, 0x0D, 0xE5, 0x0D, 0x70, 0x02, 0x05, 676 + 0x0C, 0x05, 0x1F, 0xE5, 0x1F, 0x70, 0x02, 0x05, 0x1E, 0x74, 0x00, 0xF5, 0x1B, 0x02, 0xE0, 0xF1, 677 + 0x75, 0x3F, 0x00, 0x75, 0x3E, 0x00, 0x75, 0x3D, 0x00, 0x75, 0x3C, 0x00, 0xD3, 0x22, 0x12, 0x2F, 678 + 0x9E, 0x75, 0x3F, 0x00, 0xC3, 0xE5, 0x15, 0x33, 0xF5, 0x3E, 0xE5, 0x14, 0x33, 0xF5, 0x3D, 0x75, 679 + 0x3C, 0x00, 0xC3, 0x22, 0xE5, 0x1C, 0x70, 0x03, 0x75, 0x1C, 0x01, 0xC3, 0x94, 0x80, 0x40, 0x03, 680 + 0x75, 0x1C, 0x80, 0xAA, 0x1C, 0xAD, 0x1B, 0x90, 0xF4, 0x00, 0xC0, 0x83, 0xC0, 0x82, 0xEA, 0x60, 681 + 0x5F, 0xAE, 0x18, 0xAF, 0x19, 0xE4, 0x90, 0xFE, 0x48, 0xF0, 0x90, 0xFE, 0x49, 0xF0, 0x12, 0x2F, 682 + 0x8F, 0x90, 0xFE, 0x48, 0x74, 0x7F, 0xF0, 0x90, 0xFE, 0x49, 0x74, 0x9F, 0xF0, 0x90, 0xEB, 0xDD, 683 + 0xE0, 0xD0, 0x82, 0xD0, 0x83, 0xF0, 0xA3, 0xC0, 0x83, 0xC0, 0x82, 0x90, 0xEB, 0xDE, 0xE0, 0xD0, 684 + 0x82, 0xD0, 0x83, 0xF0, 0xA3, 0xC0, 0x83, 0xC0, 0x82, 0x90, 0xEB, 0xDF, 0xE0, 0xD0, 0x82, 0xD0, 685 + 0x83, 0xF0, 0xA3, 0xC0, 0x83, 0xC0, 0x82, 0x90, 0xEB, 0xE0, 0xE0, 0xD0, 0x82, 0xD0, 0x83, 0xF0, 686 + 0xA3, 0xC0, 0x83, 0xC0, 0x82, 0x1A, 0x05, 0x19, 0xE5, 0x19, 0x70, 0x02, 0x05, 0x18, 0x80, 0x9E, 687 + 0xD0, 0x82, 0xD0, 0x83, 0xE5, 0x1C, 0x25, 0xE0, 0xFF, 0x74, 0x00, 0x33, 0xFE, 0xEF, 0x25, 0xE0, 688 + 0xFF, 0xEE, 0x33, 0xFE, 0x90, 0xFF, 0x2A, 0xEE, 0xF0, 0xA3, 0xEF, 0xF0, 0x02, 0xE1, 0x70, 0x20, 689 + 0x1F, 0x02, 0xC3, 0x22, 0x30, 0x1E, 0x02, 0x80, 0xF9, 0xD2, 0x1A, 0x75, 0x17, 0x00, 0x75, 0x3F, 690 + 0x00, 0x75, 0x3E, 0x00, 0x75, 0x3D, 0x00, 0x75, 0x3C, 0x00, 0x90, 0xEA, 0x5C, 0xE0, 0xF8, 0x90, 691 + 0xEB, 0x6D, 0xE0, 0x65, 0x18, 0x70, 0x08, 0xA3, 0xE0, 0x65, 0x19, 0x70, 0x03, 0x80, 0x07, 0xA3, 692 + 0xA3, 0xD8, 0xEF, 0xC3, 0x80, 0x01, 0xD3, 0x40, 0x0E, 0x75, 0x1C, 0xF8, 0x75, 0x1D, 0xFF, 0x12, 693 + 0xE7, 0x77, 0x40, 0x05, 0x12, 0x2F, 0x9E, 0xC3, 0x22, 0x22, 0x20, 0x1F, 0x02, 0xC3, 0x22, 0x30, 694 + 0x1E, 0x02, 0x80, 0xF9, 0xD2, 0x1A, 0x75, 0x3F, 0x00, 0x75, 0x3E, 0x00, 0x75, 0x3D, 0x00, 0x75, 695 + 0x3C, 0x00, 0x90, 0xEA, 0x5C, 0xE0, 0xF8, 0x90, 0xEB, 0x6D, 0xE0, 0x65, 0x18, 0x70, 0x08, 0xA3, 696 + 0xE0, 0x65, 0x19, 0x70, 0x03, 0x80, 0x07, 0xA3, 0xA3, 0xD8, 0xEF, 0xC3, 0x80, 0x01, 0xD3, 0x40, 697 + 0x08, 0x12, 0xE6, 0x6F, 0x40, 0x05, 0x12, 0x2F, 0x9E, 0xC3, 0x22, 0x22, 0x20, 0x1F, 0x02, 0xC3, 698 + 0x22, 0x30, 0x1E, 0x02, 0x80, 0xF9, 0xC3, 0xE5, 0x3D, 0x13, 0xF5, 0x14, 0xE5, 0x3E, 0x13, 0xF5, 699 + 0x15, 0x30, 0x21, 0x39, 0x90, 0xEB, 0x2A, 0xE0, 0xFC, 0xA3, 0xE0, 0xFD, 0xA3, 0xE0, 0xFE, 0xA3, 700 + 0xE0, 0xFF, 0x90, 0xEA, 0x47, 0xE0, 0x14, 0xFB, 0x60, 0x12, 0xC3, 0xEC, 0x13, 0xFC, 0xED, 0x13, 701 + 0xFD, 0xEE, 0x13, 0xFE, 0xEF, 0x13, 0xFF, 0xC3, 0xEB, 0x13, 0x80, 0xEB, 0x8E, 0x18, 0x8F, 0x19, 702 + 0x90, 0xEB, 0x2D, 0xE0, 0xFF, 0x90, 0xEA, 0x47, 0xE0, 0x14, 0x5F, 0xF5, 0x1B, 0xD2, 0x1C, 0xC3, 703 + 0x90, 0xEA, 0x47, 0xE0, 0x95, 0x1B, 0xF5, 0x16, 0xE5, 0x14, 0x70, 0x0A, 0xD3, 0xE5, 0x16, 0x95, 704 + 0x15, 0x40, 0x03, 0x85, 0x15, 0x16, 0x90, 0xEA, 0x5C, 0xE0, 0xF8, 0x90, 0xEB, 0x6D, 0xE0, 0x65, 705 + 0x18, 0x70, 0x08, 0xA3, 0xE0, 0x65, 0x19, 0x70, 0x03, 0x80, 0x07, 0xA3, 0xA3, 0xD8, 0xEF, 0xC3, 706 + 0x80, 0x01, 0xD3, 0x50, 0x03, 0x02, 0xE4, 0x34, 0x20, 0x21, 0x2F, 0xC2, 0x42, 0x75, 0x10, 0x00, 707 + 0xE5, 0x10, 0x65, 0x1B, 0x70, 0x03, 0x02, 0xE3, 0x7A, 0x12, 0x2F, 0x89, 0x40, 0x03, 0x02, 0xE4, 708 + 0x31, 0xE5, 0x10, 0x70, 0x11, 0xC0, 0x1C, 0xC0, 0x1B, 0x75, 0x1B, 0x00, 0x75, 0x1C, 0xEF, 0x12, 709 + 0x2F, 0x95, 0xD0, 0x1B, 0xD0, 0x1C, 0x05, 0x10, 0x80, 0xD6, 0x75, 0x17, 0x00, 0x30, 0x21, 0x06, 710 + 0xC0, 0x18, 0xC0, 0x19, 0x80, 0x10, 0x75, 0x1C, 0xF8, 0x75, 0x1D, 0xFF, 0xC0, 0x18, 0xC0, 0x19, 711 + 0x85, 0x11, 0x18, 0x85, 0x12, 0x19, 0xE5, 0x16, 0xB4, 0x01, 0x0C, 0x12, 0xE5, 0x11, 0x40, 0x13, 712 + 0xD0, 0x19, 0xD0, 0x18, 0x02, 0xE4, 0x31, 0x12, 0x2F, 0x92, 0x40, 0x07, 0xD0, 0x19, 0xD0, 0x18, 713 + 0x02, 0xE4, 0x31, 0xD0, 0x19, 0xD0, 0x18, 0xE5, 0x10, 0x25, 0x16, 0xF5, 0x10, 0x20, 0x21, 0x3A, 714 + 0x90, 0xEA, 0x47, 0xE0, 0x65, 0x10, 0x60, 0x0C, 0x12, 0x2F, 0x89, 0x40, 0x03, 0x02, 0xE4, 0x31, 715 + 0x05, 0x10, 0x80, 0xEC, 0x20, 0x42, 0x05, 0x12, 0xE7, 0x77, 0x80, 0x09, 0x75, 0x1B, 0x00, 0x75, 716 + 0x1C, 0x7F, 0x12, 0x2F, 0x95, 0x75, 0x17, 0x00, 0x85, 0x11, 0x18, 0x85, 0x12, 0x19, 0x75, 0x1B, 717 + 0x00, 0x75, 0x1C, 0xF8, 0x75, 0x1D, 0xFF, 0x12, 0xE6, 0x6F, 0xC3, 0xE5, 0x15, 0x95, 0x16, 0xF5, 718 + 0x15, 0xE5, 0x14, 0x94, 0x00, 0xF5, 0x14, 0xE5, 0x15, 0x45, 0x14, 0x60, 0x16, 0x05, 0x19, 0xE5, 719 + 0x19, 0x70, 0x02, 0x05, 0x18, 0x05, 0x0D, 0xE5, 0x0D, 0x70, 0x02, 0x05, 0x0C, 0x75, 0x1B, 0x00, 720 + 0x02, 0xE3, 0x0F, 0x75, 0x3F, 0x00, 0x75, 0x3E, 0x00, 0x75, 0x3D, 0x00, 0x75, 0x3C, 0x00, 0xD3, 721 + 0x22, 0x12, 0x2F, 0x9E, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 0xFF, 0x23, 0x74, 0x80, 722 + 0xF0, 0x75, 0x3F, 0x00, 0xC3, 0xE5, 0x15, 0x33, 0xF5, 0x3E, 0xE5, 0x14, 0x33, 0xF5, 0x3D, 0x75, 723 + 0x3C, 0x00, 0xC3, 0x22, 0x75, 0x1A, 0x20, 0x12, 0x2F, 0xA4, 0x40, 0x03, 0x02, 0xE5, 0x0F, 0x79, 724 + 0x0F, 0x90, 0xFE, 0x46, 0xE0, 0x54, 0xF0, 0x49, 0xF0, 0x78, 0xD2, 0x12, 0x2F, 0xAA, 0x30, 0x1C, 725 + 0x5A, 0x30, 0x2D, 0x05, 0x75, 0x16, 0x01, 0x80, 0x03, 0x75, 0x16, 0x08, 0x75, 0x08, 0x00, 0xE5, 726 + 0x08, 0x65, 0x16, 0x70, 0x02, 0x80, 0x55, 0x90, 0xFF, 0x09, 0x30, 0x25, 0x0B, 0xE0, 0x30, 0xE1, 727 + 0xF9, 0x90, 0xFF, 0x09, 0xF0, 0xD3, 0x80, 0x01, 0xC3, 0x50, 0x0F, 0xAF, 0x08, 0x7C, 0xF0, 0x7D, 728 + 0x00, 0xAB, 0x4D, 0xAA, 0x4C, 0x12, 0x2F, 0xBF, 0x40, 0x10, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 729 + 0x06, 0x90, 0xFF, 0x23, 0x74, 0x80, 0xF0, 0x02, 0xE5, 0x0A, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 730 + 0x06, 0x90, 0xFF, 0x23, 0x74, 0x80, 0xF0, 0x05, 0x08, 0x80, 0xB4, 0x7C, 0xF0, 0x7D, 0x00, 0x7B, 731 + 0x00, 0x7A, 0x02, 0x7F, 0x00, 0x12, 0x2F, 0xBF, 0x40, 0x02, 0x80, 0x2E, 0x20, 0x1D, 0x08, 0x30, 732 + 0x25, 0x03, 0x30, 0x24, 0xF7, 0xD2, 0x24, 0x30, 0x24, 0x02, 0xC3, 0x22, 0x79, 0x55, 0x7A, 0x01, 733 + 0x12, 0x2F, 0xAD, 0x40, 0x02, 0x80, 0x18, 0x12, 0x2F, 0xB0, 0x30, 0x24, 0x02, 0xC3, 0x22, 0xEF, 734 + 0x54, 0xC1, 0x64, 0x80, 0x60, 0x02, 0x80, 0x02, 0xD3, 0x22, 0x79, 0xC3, 0x12, 0x2F, 0x9B, 0xC3, 735 + 0x22, 0xC0, 0x16, 0x30, 0x1E, 0x03, 0x02, 0xE5, 0x5C, 0x75, 0x09, 0x00, 0x7C, 0x08, 0x30, 0x2D, 736 + 0x02, 0x7C, 0x20, 0x20, 0x25, 0x03, 0x02, 0xE5, 0x5C, 0xC0, 0x04, 0x12, 0xE4, 0x54, 0xD0, 0x04, 737 + 0x50, 0x04, 0xD0, 0x16, 0xD3, 0x22, 0xA9, 0x09, 0xE9, 0x54, 0x07, 0x60, 0x0C, 0x90, 0xFE, 0x4C, 738 + 0xE0, 0xF0, 0x90, 0xFE, 0x4D, 0xE0, 0xF0, 0x80, 0x09, 0x20, 0x25, 0x03, 0x02, 0xE5, 0x5C, 0x12, 739 + 0x2F, 0xB3, 0x05, 0x09, 0xE5, 0x09, 0x6C, 0x60, 0x03, 0x02, 0xE5, 0x23, 0xD0, 0x16, 0xC3, 0x22, 740 + 0xC0, 0x03, 0x75, 0x1A, 0x00, 0x12, 0x2F, 0xB6, 0x40, 0x04, 0xD0, 0x03, 0xC3, 0x22, 0xC2, 0x41, 741 + 0x79, 0xAA, 0x7A, 0x00, 0x12, 0x2F, 0xAD, 0x50, 0xF1, 0xD0, 0x03, 0x1B, 0x8B, 0x08, 0xC2, 0x40, 742 + 0x20, 0x20, 0x08, 0x30, 0x25, 0x03, 0x30, 0x24, 0xF7, 0xD2, 0x24, 0x30, 0x24, 0x02, 0xC3, 0x22, 743 + 0x12, 0x2F, 0xB0, 0xC2, 0x20, 0xC2, 0x24, 0xEF, 0x54, 0xE1, 0xFF, 0x30, 0xE0, 0x03, 0x02, 0xE6, 744 + 0x6D, 0x20, 0xE6, 0x0F, 0x30, 0xE7, 0x02, 0xD2, 0x40, 0x20, 0xE5, 0x19, 0x64, 0x80, 0x70, 0x03, 745 + 0x02, 0xE6, 0x4B, 0x12, 0x2F, 0xB9, 0x40, 0x03, 0x02, 0xE6, 0x68, 0x90, 0xEB, 0xCA, 0xE0, 0x54, 746 + 0x15, 0x60, 0x02, 0xD2, 0x41, 0xE5, 0x08, 0x70, 0x0E, 0x20, 0x40, 0x0B, 0x79, 0x33, 0x7A, 0x01, 747 + 0x12, 0x2F, 0xAD, 0x40, 0x02, 0xC1, 0x6D, 0x12, 0x2F, 0xBC, 0x40, 0x02, 0xC1, 0x6D, 0x90, 0xEB, 748 + 0xDE, 0xE0, 0x54, 0x30, 0x64, 0x30, 0x60, 0x02, 0xC1, 0x6D, 0x79, 0x00, 0x90, 0xFE, 0x46, 0xE0, 749 + 0x54, 0xF0, 0x49, 0xF0, 0x79, 0x00, 0x78, 0x2D, 0x12, 0x2F, 0xAA, 0x90, 0xFF, 0x09, 0x30, 0x25, 750 + 0x07, 0xE0, 0x30, 0xE5, 0xF9, 0xD3, 0x80, 0x01, 0xC3, 0x40, 0x02, 0x80, 0x5B, 0xC0, 0x01, 0x7E, 751 + 0xF4, 0x7F, 0x00, 0x7D, 0x00, 0x7C, 0x02, 0x12, 0x2F, 0xC2, 0xD0, 0x01, 0x40, 0x09, 0x09, 0xE9, 752 + 0x64, 0x20, 0x70, 0xD2, 0x02, 0xE6, 0x68, 0x90, 0xFF, 0x2A, 0x74, 0x02, 0xF0, 0xA3, 0x74, 0x00, 753 + 0xF0, 0x20, 0x1D, 0x08, 0x30, 0x25, 0x03, 0x30, 0x24, 0xF7, 0xD2, 0x24, 0x30, 0x24, 0x02, 0xC3, 754 + 0x22, 0x30, 0x40, 0x02, 0x80, 0x05, 0x15, 0x08, 0x02, 0xE5, 0x80, 0x30, 0x41, 0x16, 0x79, 0xCC, 755 + 0x12, 0x2F, 0x9B, 0xC2, 0x1A, 0x90, 0xEA, 0x47, 0xE0, 0x65, 0x1B, 0x60, 0x07, 0x12, 0x2F, 0x8C, 756 + 0x05, 0x1B, 0x80, 0xF1, 0xD2, 0x1A, 0xD3, 0x22, 0x79, 0xC3, 0x12, 0x2F, 0x9B, 0xC3, 0x22, 0xC0, 757 + 0x08, 0x30, 0x1E, 0x02, 0x80, 0x33, 0x75, 0x1A, 0x40, 0x75, 0x1D, 0xFF, 0x75, 0x08, 0x00, 0x20, 758 + 0x25, 0x02, 0x80, 0x25, 0x12, 0xE6, 0xAD, 0x50, 0x04, 0xD0, 0x08, 0xD3, 0x22, 0xA9, 0x08, 0xE9, 759 + 0x54, 0x07, 0x60, 0x02, 0x80, 0x08, 0x20, 0x25, 0x02, 0x80, 0x0E, 0x12, 0x2F, 0xB3, 0x05, 0x08, 760 + 0xE5, 0x08, 0x64, 0x20, 0x60, 0x03, 0x02, 0xE6, 0x7F, 0xD0, 0x08, 0xC3, 0x22, 0x90, 0xFE, 0x4C, 761 + 0xE0, 0xF0, 0x90, 0xFE, 0x4D, 0xE0, 0xF0, 0xC2, 0x1D, 0xC2, 0x24, 0x90, 0xFE, 0x50, 0x74, 0x87, 762 + 0xF0, 0x90, 0xFE, 0x40, 0x74, 0x00, 0xF0, 0x90, 0xFE, 0x40, 0x74, 0x00, 0xF0, 0x90, 0xFE, 0x40, 763 + 0x74, 0x10, 0xF0, 0x90, 0xFE, 0x40, 0x74, 0x0F, 0xF0, 0x90, 0xFE, 0x57, 0x74, 0x0F, 0xF0, 0x90, 764 + 0xFE, 0x44, 0x74, 0x01, 0xF0, 0x20, 0x1D, 0x08, 0x30, 0x25, 0x03, 0x30, 0x24, 0xF7, 0xD2, 0x24, 765 + 0x30, 0x24, 0x02, 0xC3, 0x22, 0x79, 0x00, 0x90, 0xFE, 0x46, 0xE0, 0x54, 0xF0, 0x49, 0xF0, 0x90, 766 + 0xFE, 0x4D, 0x30, 0x25, 0x07, 0xE0, 0x30, 0xE5, 0xF9, 0xD3, 0x80, 0x01, 0xC3, 0x40, 0x01, 0x22, 767 + 0x78, 0xB4, 0x12, 0x2F, 0xAA, 0x90, 0xEA, 0x44, 0xE0, 0x90, 0xFE, 0x40, 0xF0, 0x78, 0x17, 0x7D, 768 + 0x09, 0xE6, 0x08, 0x90, 0xFE, 0x40, 0xF0, 0xDD, 0xF8, 0x74, 0xFF, 0x90, 0xFE, 0x40, 0xF0, 0xF0, 769 + 0xF0, 0xF0, 0xC2, 0x1D, 0xC2, 0x24, 0xF0, 0x20, 0x1D, 0x08, 0x30, 0x25, 0x03, 0x30, 0x24, 0xF7, 770 + 0xD2, 0x24, 0x30, 0x24, 0x02, 0xC3, 0x22, 0x90, 0xFE, 0x4E, 0x30, 0x25, 0x07, 0xE0, 0x30, 0xE6, 771 + 0xF9, 0xD3, 0x80, 0x01, 0xC3, 0x79, 0x55, 0x7A, 0x01, 0x12, 0x2F, 0xAD, 0x40, 0x02, 0x80, 0x13, 772 + 0x12, 0x2F, 0xB0, 0x30, 0x24, 0x02, 0xC3, 0x22, 0xEF, 0x20, 0xE0, 0x07, 0x54, 0xC0, 0xB4, 0x80, 773 + 0x02, 0x80, 0x02, 0xC3, 0x22, 0xD3, 0x22, 0x30, 0x1E, 0x02, 0x80, 0x0A, 0x12, 0xE7, 0x88, 0x40, 774 + 0x03, 0x02, 0xE7, 0x86, 0xD3, 0x22, 0xC3, 0x22, 0xC0, 0x08, 0x75, 0x08, 0x00, 0x20, 0x25, 0x02, 775 + 0x80, 0x25, 0x12, 0x2F, 0xA1, 0x50, 0x03, 0xD0, 0x08, 0x22, 0xA9, 0x08, 0xE9, 0x54, 0x07, 0x60, 776 + 0x02, 0x80, 0x09, 0xA2, 0x25, 0x40, 0x02, 0x80, 0x0E, 0x12, 0x2F, 0xB3, 0x05, 0x08, 0xE5, 0x08, 777 + 0x64, 0x20, 0x60, 0x03, 0x02, 0xE7, 0x8D, 0xD0, 0x08, 0xC3, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 778 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 779 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 780 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 781 + 0x4D, 0x53, 0x2D, 0x52, 0x57, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x31, 0x30, 0x30, 0x30, 0x30 }; 782 + 783 + BYTE SM_Init[] = { 784 + 0x7B, 0x09, 0x7C, 0xF0, 0x7D, 0x10, 0x7E, 0xE9, 0x7F, 0xCC, 0x12, 0x2F, 0x71, 0x90, 0xE9, 0xCC, 785 + 0xE0, 0xB4, 0x07, 0x12, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 0xFF, 0x23, 0x74, 0x80, 786 + 0xF0, 0x12, 0x2F, 0x5C, 0xD3, 0x22, 0x78, 0x00, 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE1, 0x92, 0x0A, 787 + 0x20, 0x0A, 0x03, 0x02, 0xE0, 0xD0, 0x7F, 0x00, 0x12, 0x2F, 0xCB, 0x20, 0x01, 0x05, 0xC2, 0x25, 788 + 0x02, 0xE0, 0xEB, 0xC3, 0xE8, 0x94, 0x02, 0x40, 0x03, 0x02, 0xE0, 0xD0, 0xC0, 0x00, 0x90, 0xFE, 789 + 0x66, 0x74, 0x90, 0xF0, 0x12, 0xE1, 0x40, 0x90, 0xFF, 0x95, 0xE0, 0xC2, 0xE4, 0xF0, 0x90, 0xFF, 790 + 0x97, 0x74, 0x01, 0xF0, 0x7E, 0x01, 0x7F, 0x90, 0x12, 0x2F, 0x74, 0x90, 0xFF, 0x97, 0x74, 0x03, 791 + 0xF0, 0x90, 0xFE, 0xC5, 0xE4, 0xF0, 0x74, 0x00, 0x90, 0xFE, 0x6A, 0xF0, 0xA3, 0xF0, 0xA3, 0xF0, 792 + 0xA3, 0xF0, 0x7E, 0x23, 0x7F, 0xDC, 0x12, 0x2F, 0x74, 0x12, 0x2F, 0x5C, 0x90, 0xFE, 0x64, 0xE0, 793 + 0x54, 0x01, 0x60, 0x04, 0xD2, 0x02, 0x80, 0x02, 0xC2, 0x02, 0x90, 0xFF, 0x95, 0xE0, 0xD2, 0xE4, 794 + 0xF0, 0x78, 0x10, 0x79, 0x04, 0x12, 0xE1, 0x71, 0x50, 0x3A, 0x90, 0xE9, 0xC6, 0xE0, 0x90, 0xE9, 795 + 0xC3, 0xF0, 0x78, 0x9A, 0x79, 0x04, 0x12, 0xE1, 0x71, 0x50, 0x29, 0x90, 0xE9, 0xC7, 0xE0, 0xB4, 796 + 0xB5, 0x22, 0x90, 0xE9, 0xC4, 0xF0, 0xD0, 0x00, 0xD2, 0x00, 0xC2, 0x01, 0xC2, 0x25, 0x80, 0x1B, 797 + 0xC2, 0x00, 0xD2, 0x01, 0x74, 0xFF, 0x90, 0xE9, 0xC3, 0xF0, 0xA3, 0xF0, 0x51, 0x01, 0xC2, 0x0A, 798 + 0xC2, 0x02, 0x80, 0x07, 0xD0, 0x00, 0x05, 0x00, 0x02, 0xE0, 0x43, 0x90, 0xFF, 0x09, 0xE0, 0x30, 799 + 0xE1, 0x06, 0x90, 0xFF, 0x23, 0x74, 0x80, 0xF0, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE5, 0xFC, 0xE4, 800 + 0xA2, 0x0A, 0x92, 0xE0, 0xA2, 0x00, 0x92, 0xE1, 0xA2, 0x01, 0x92, 0xE2, 0xA2, 0x02, 0x92, 0xE6, 801 + 0xA2, 0x25, 0x92, 0xE7, 0x90, 0xF4, 0x00, 0xF0, 0x90, 0xE9, 0xC3, 0xE0, 0x90, 0xF4, 0x01, 0xF0, 802 + 0x90, 0xE9, 0xC4, 0xE0, 0x90, 0xF4, 0x02, 0xF0, 0x90, 0xFF, 0x2A, 0x74, 0x02, 0xF0, 0xA3, 0x74, 803 + 0x00, 0xF0, 0x75, 0x3C, 0x00, 0x75, 0x3D, 0x00, 0x75, 0x3E, 0x00, 0x75, 0x3F, 0x00, 0xD3, 0x22, 804 + 0x90, 0xFE, 0x71, 0xE4, 0xF0, 0x90, 0xFE, 0x72, 0x74, 0x01, 0xF0, 0x90, 0xFE, 0x64, 0x74, 0x0C, 805 + 0xF0, 0x90, 0xFE, 0x64, 0x74, 0x00, 0x45, 0x4E, 0xF0, 0x90, 0xFE, 0x64, 0xE0, 0x54, 0x10, 0x60, 806 + 0x08, 0x90, 0xFE, 0x72, 0x74, 0x81, 0xF0, 0xD3, 0x22, 0x90, 0xFE, 0x64, 0x74, 0x08, 0xF0, 0xC3, 807 + 0x22, 0x90, 0xFE, 0x6F, 0xE9, 0x14, 0xF0, 0x90, 0xFE, 0x70, 0xE0, 0x54, 0xFC, 0xF0, 0x90, 0xFE, 808 + 0x68, 0x74, 0x00, 0xF0, 0xB8, 0x9A, 0x2A, 0x74, 0x15, 0x90, 0xFE, 0x64, 0xF0, 0x74, 0x9A, 0x90, 809 + 0xFE, 0x60, 0xF0, 0x74, 0x16, 0x90, 0xFE, 0x64, 0xF0, 0x74, 0x00, 0x90, 0xFE, 0x60, 0xF0, 0x30, 810 + 0x0A, 0x5D, 0x90, 0xFE, 0x64, 0xE0, 0x20, 0xE7, 0xF6, 0x74, 0x14, 0x90, 0xFE, 0x64, 0xF0, 0x80, 811 + 0x20, 0x90, 0xFE, 0x6E, 0xE8, 0x44, 0x01, 0xF0, 0xC2, 0x09, 0x12, 0xE3, 0x26, 0x20, 0x08, 0x0E, 812 + 0x12, 0xE3, 0x32, 0x30, 0x3E, 0xF7, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0xD2, 0x09, 0x20, 0x09, 813 + 0x2E, 0x7A, 0xE9, 0x7B, 0xC5, 0x7C, 0xFE, 0x7D, 0x60, 0xB8, 0x10, 0x07, 0x90, 0xFE, 0x69, 0xE0, 814 + 0x20, 0xE6, 0xFC, 0x8C, 0x83, 0x8D, 0x82, 0xE0, 0x8A, 0x83, 0x8B, 0x82, 0xF0, 0xA3, 0xAA, 0x83, 815 + 0xAB, 0x82, 0xD9, 0xE5, 0xB8, 0x9A, 0x06, 0x74, 0x10, 0x90, 0xFE, 0x64, 0xF0, 0xD3, 0x22, 0xC3, 816 + 0x22, 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE1, 0x92, 0x25, 0x20, 0x25, 0x06, 0xC2, 0x1F, 0xD2, 0x19, 817 + 0xC3, 0x22, 0x7F, 0x02, 0x12, 0x2F, 0xCB, 0x20, 0x19, 0x05, 0x30, 0x1F, 0x02, 0xD3, 0x22, 0x90, 818 + 0xEA, 0x44, 0x74, 0x80, 0xF0, 0x7F, 0x10, 0x12, 0x2F, 0xC5, 0x90, 0xFE, 0x47, 0xE0, 0x44, 0x80, 819 + 0xF0, 0x78, 0x00, 0xE8, 0xC3, 0x94, 0x04, 0x50, 0x0A, 0x7F, 0x88, 0x7E, 0x13, 0x12, 0xE3, 0x4D, 820 + 0x08, 0x80, 0xF0, 0x90, 0xFE, 0x45, 0xE0, 0x54, 0xFB, 0xF0, 0x90, 0xFE, 0x47, 0xE0, 0x54, 0xBF, 821 + 0xF0, 0x90, 0xFE, 0x45, 0xE0, 0x54, 0xFE, 0xF0, 0x90, 0xFE, 0x45, 0xE0, 0x54, 0x7F, 0xF0, 0x90, 822 + 0xFE, 0x46, 0xE0, 0x44, 0x40, 0xF0, 0x90, 0xFE, 0x45, 0xE0, 0x54, 0xC7, 0x44, 0x18, 0xF0, 0x90, 823 + 0xFE, 0x47, 0xE0, 0x44, 0x08, 0xF0, 0x90, 0xFE, 0x45, 0xE0, 0x44, 0x40, 0xF0, 0x7F, 0x32, 0x7E, 824 + 0x00, 0x12, 0xE3, 0x4D, 0x90, 0xFE, 0x51, 0xE0, 0x54, 0x33, 0xF0, 0x90, 0xFE, 0x44, 0x74, 0x02, 825 + 0xF0, 0x30, 0x25, 0x04, 0xE0, 0x20, 0xE1, 0xF9, 0x90, 0xFE, 0x51, 0xE0, 0x54, 0x0F, 0xF0, 0x90, 826 + 0xFE, 0x44, 0x74, 0x02, 0xF0, 0x30, 0x25, 0x04, 0xE0, 0x20, 0xE1, 0xF9, 0x90, 0xFE, 0x44, 0x74, 827 + 0x04, 0xF0, 0x30, 0x25, 0x04, 0xE0, 0x20, 0xE2, 0xF9, 0x90, 0xFE, 0x4C, 0xE0, 0xF0, 0x90, 0xFE, 828 + 0x4D, 0xE0, 0xF0, 0x90, 0xFE, 0x48, 0x74, 0x7F, 0xF0, 0x90, 0xFE, 0x49, 0x74, 0x9F, 0xF0, 0x90, 829 + 0xFE, 0x51, 0xE0, 0x54, 0x3C, 0x44, 0x02, 0xF0, 0x90, 0xFE, 0x44, 0x74, 0x02, 0xF0, 0x30, 0x25, 830 + 0x04, 0xE0, 0x20, 0xE1, 0xF9, 0x90, 0xFE, 0x46, 0xE0, 0x44, 0x20, 0xF0, 0x79, 0x02, 0x7A, 0x06, 831 + 0x7B, 0x00, 0x7C, 0x00, 0x7D, 0x06, 0x7E, 0xEB, 0x7F, 0xC9, 0x12, 0x2F, 0xA7, 0x40, 0x03, 0x02, 832 + 0xE3, 0x04, 0xD3, 0x22, 0xE4, 0x90, 0xFE, 0x48, 0xF0, 0x90, 0xFE, 0x49, 0xF0, 0x90, 0xFE, 0x4C, 833 + 0xE0, 0xF0, 0x90, 0xFE, 0x4D, 0xE0, 0xF0, 0x90, 0xFE, 0x47, 0xE0, 0x54, 0x7F, 0xF0, 0xC2, 0x25, 834 + 0xC2, 0x1F, 0xD2, 0x19, 0xC3, 0x22, 0xC2, 0x3E, 0x75, 0x7C, 0x00, 0x75, 0x7D, 0x00, 0x75, 0x7E, 835 + 0x00, 0x22, 0x05, 0x7C, 0xE5, 0x7C, 0x70, 0x14, 0x05, 0x7D, 0xE5, 0x7D, 0x70, 0x04, 0x05, 0x7E, 836 + 0x80, 0x0A, 0xB4, 0x17, 0x07, 0xE5, 0x7E, 0xB4, 0x06, 0x02, 0xD2, 0x3E, 0x22, 0x75, 0x8A, 0x00, 837 + 0x75, 0x8C, 0xCE, 0xC2, 0x8D, 0x90, 0xEA, 0x65, 0xE4, 0xF0, 0xA3, 0xF0, 0xD2, 0x8C, 0x90, 0xEA, 838 + 0x65, 0xE0, 0xFC, 0xA3, 0xE0, 0xFD, 0xEC, 0xC3, 0x9E, 0x40, 0xF3, 0x70, 0x05, 0xED, 0xC3, 0x9F, 839 + 0x40, 0xEC, 0xC2, 0x8C, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 840 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 841 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 842 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 843 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 844 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 845 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 846 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 847 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 848 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 849 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 850 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 851 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 852 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 853 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 854 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 855 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 856 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 857 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 858 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 859 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 860 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 861 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 862 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 863 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 864 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 865 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 866 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 867 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 868 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 869 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 870 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 871 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 872 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 873 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 874 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 875 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 876 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 877 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 878 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 879 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 880 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 881 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 882 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 883 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 884 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 885 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 886 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 887 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 888 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 889 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 890 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 891 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 892 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 893 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 894 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 895 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 896 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 897 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 898 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 899 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 900 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 901 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 902 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 903 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 904 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 905 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 906 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 907 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 908 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 909 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 910 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 911 + 0x58, 0x44, 0x2D, 0x49, 0x6E, 0x69, 0x74, 0x20, 0x20, 0x20, 0x20, 0x31, 0x30, 0x30, 0x30, 0x31 }; 912 + 913 + BYTE SM_Rdwr[] = { 914 + 0x7B, 0x0C, 0x7C, 0xF0, 0x7D, 0x10, 0x7E, 0xE9, 0x7F, 0xCC, 0x12, 0x2F, 0x71, 0x90, 0xE9, 0xC3, 915 + 0xE0, 0xB4, 0x73, 0x04, 0x74, 0x40, 0x80, 0x09, 0xB4, 0x75, 0x04, 0x74, 0x40, 0x80, 0x02, 0x74, 916 + 0xC0, 0x90, 0xFE, 0x70, 0xF0, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 0xFF, 0x23, 0x74, 917 + 0x80, 0xF0, 0x90, 0xFF, 0x83, 0xE0, 0xA2, 0xE1, 0x92, 0x0A, 0x40, 0x01, 0x22, 0x90, 0xFE, 0x6A, 918 + 0xE4, 0xF0, 0x90, 0xE9, 0xCC, 0xE0, 0xB4, 0x02, 0x05, 0xD2, 0x06, 0x02, 0xE0, 0x78, 0xB4, 0x03, 919 + 0x03, 0x02, 0xE3, 0xD0, 0xB4, 0x04, 0x03, 0x02, 0xE1, 0xC6, 0xB4, 0x05, 0x03, 0x02, 0xE5, 0x20, 920 + 0xB4, 0x06, 0x03, 0x02, 0xE5, 0xE0, 0xB4, 0x07, 0x05, 0x12, 0x2F, 0x5C, 0xD3, 0x22, 0xB4, 0x08, 921 + 0x05, 0xC2, 0x06, 0x02, 0xE6, 0x3B, 0xC3, 0x22, 0xE5, 0x3E, 0xC3, 0x13, 0x90, 0xE9, 0xCA, 0xF0, 922 + 0xC0, 0xE0, 0x75, 0xF0, 0x02, 0xC0, 0xF0, 0x12, 0xE0, 0xD8, 0xEF, 0x70, 0x21, 0x20, 0x37, 0x07, 923 + 0x20, 0x09, 0x04, 0xD0, 0xF0, 0x80, 0x05, 0xD0, 0xF0, 0xD5, 0xF0, 0xE9, 0xD0, 0xE0, 0x90, 0xFF, 924 + 0x28, 0xE0, 0x30, 0xE7, 0xFC, 0x90, 0xFF, 0x28, 0xE0, 0x44, 0x01, 0xF0, 0xC3, 0x22, 0xD0, 0xF0, 925 + 0x90, 0xE9, 0xCF, 0xE0, 0x24, 0x01, 0xF0, 0x90, 0xE9, 0xCE, 0xE0, 0x34, 0x00, 0xF0, 0x90, 0xE9, 926 + 0xCD, 0xE0, 0x34, 0x00, 0xF0, 0xD0, 0xE0, 0x14, 0x70, 0xB6, 0x75, 0x3C, 0x00, 0x75, 0x3D, 0x00, 927 + 0x75, 0x3E, 0x00, 0x75, 0x3F, 0x00, 0xD3, 0x22, 0xC2, 0x08, 0xC2, 0x36, 0xC2, 0x37, 0xE4, 0x90, 928 + 0xEB, 0xC2, 0xF0, 0x90, 0xE9, 0xCD, 0xE0, 0xF8, 0xA3, 0xE0, 0xF9, 0xA3, 0xE0, 0x90, 0xFE, 0x6B, 929 + 0xF0, 0xA3, 0xE9, 0xF0, 0xA3, 0xE8, 0xF0, 0x90, 0xFE, 0x6F, 0x74, 0x0F, 0xF0, 0x90, 0xFE, 0x70, 930 + 0xE0, 0x54, 0xFC, 0x44, 0x02, 0xF0, 0x90, 0xFE, 0xC6, 0x74, 0x02, 0xF0, 0xA3, 0x74, 0x0F, 0xF0, 931 + 0x90, 0xFE, 0xC0, 0x74, 0xF4, 0xF0, 0x74, 0x00, 0xA3, 0xF0, 0x90, 0xFE, 0x68, 0x74, 0x21, 0xF0, 932 + 0x90, 0xFE, 0x64, 0x74, 0x70, 0x45, 0x4E, 0xF0, 0x90, 0xFE, 0x64, 0x74, 0x30, 0x45, 0x4E, 0xF0, 933 + 0x30, 0x06, 0x07, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE5, 0xFC, 0x90, 0xFE, 0x6E, 0x74, 0x51, 0xF0, 934 + 0x90, 0xFE, 0xC4, 0x74, 0x21, 0xF0, 0xC2, 0x09, 0x12, 0xE7, 0xB0, 0x20, 0x08, 0x0E, 0x12, 0xE7, 935 + 0xBC, 0x30, 0x3E, 0xF7, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0xD2, 0x09, 0x30, 0x09, 0x03, 0x7F, 936 + 0x00, 0x22, 0x12, 0xE7, 0xB0, 0x20, 0x36, 0x11, 0x20, 0x37, 0x0E, 0x12, 0xE7, 0xBC, 0x30, 0x3E, 937 + 0xF4, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0xD2, 0x37, 0x30, 0x37, 0x03, 0x7F, 0x00, 0x22, 0x90, 938 + 0xFE, 0x64, 0x74, 0x10, 0x45, 0x4E, 0xF0, 0x90, 0xFE, 0x64, 0x74, 0x00, 0x45, 0x4E, 0xF0, 0x12, 939 + 0x2F, 0x65, 0x12, 0x2F, 0x68, 0xBF, 0x00, 0x09, 0x74, 0x02, 0x90, 0xEB, 0xC2, 0xF0, 0x7F, 0x00, 940 + 0x22, 0x12, 0x2F, 0x6B, 0xBF, 0x00, 0x0F, 0x12, 0x2F, 0x6E, 0xBF, 0x00, 0x09, 0x74, 0x01, 0x90, 941 + 0xEB, 0xC2, 0xF0, 0x7F, 0x00, 0x22, 0x30, 0x06, 0x0A, 0x90, 0xFF, 0x2A, 0x74, 0x02, 0xF0, 0xA3, 942 + 0x74, 0x00, 0xF0, 0x7F, 0x01, 0x22, 0x12, 0xE3, 0xAA, 0x74, 0x01, 0x90, 0xE9, 0xCB, 0xF0, 0xE5, 943 + 0x3E, 0xC3, 0x13, 0x90, 0xE9, 0xCA, 0xF0, 0xC0, 0xE0, 0x75, 0xF0, 0x02, 0xC0, 0xF0, 0x12, 0xE2, 944 + 0x2F, 0xEF, 0x70, 0x21, 0x20, 0x37, 0x07, 0x20, 0x09, 0x04, 0xD0, 0xF0, 0x80, 0x05, 0xD0, 0xF0, 945 + 0xD5, 0xF0, 0xE9, 0xD0, 0xE0, 0x90, 0xFF, 0x28, 0xE0, 0x30, 0xE7, 0xFC, 0x90, 0xFF, 0x28, 0xE0, 946 + 0x44, 0x01, 0xF0, 0xC3, 0x22, 0xD0, 0xF0, 0x90, 0xE9, 0xD2, 0xE0, 0x24, 0x01, 0xF0, 0x90, 0xE9, 947 + 0xD1, 0xE0, 0x34, 0x00, 0xF0, 0x90, 0xE9, 0xD0, 0xE0, 0x34, 0x00, 0xF0, 0xD0, 0xE0, 0x14, 0x70, 948 + 0xB6, 0x75, 0x3C, 0x00, 0x75, 0x3D, 0x00, 0x75, 0x3E, 0x00, 0x75, 0x3F, 0x00, 0xD3, 0x22, 0xC2, 949 + 0x08, 0xC2, 0x36, 0xC2, 0x37, 0x90, 0xFE, 0x68, 0x74, 0x31, 0xF0, 0x90, 0xE9, 0xD0, 0xE0, 0xF8, 950 + 0xA3, 0xE0, 0xF9, 0xA3, 0xE0, 0x90, 0xFE, 0x6B, 0xF0, 0xA3, 0xE9, 0xF0, 0xA3, 0xE8, 0xF0, 0x90, 951 + 0xFE, 0x6F, 0x74, 0x0F, 0xF0, 0x90, 0xFE, 0x70, 0xE0, 0x54, 0xFC, 0x44, 0x22, 0xF0, 0x90, 0xE9, 952 + 0xCB, 0xE0, 0x70, 0x0C, 0x90, 0xFE, 0xC0, 0x74, 0xF4, 0xF0, 0xA3, 0x74, 0x00, 0xF0, 0x80, 0x0A, 953 + 0x90, 0xFE, 0xC0, 0x74, 0xF0, 0xF0, 0xA3, 0x74, 0x00, 0xF0, 0x90, 0xFE, 0x64, 0x74, 0xF0, 0x45, 954 + 0x4E, 0xF0, 0x90, 0xFE, 0x64, 0x74, 0xB0, 0x45, 0x4E, 0xF0, 0x90, 0xFE, 0x6E, 0x74, 0x81, 0xF0, 955 + 0x90, 0xE9, 0xCB, 0xE0, 0x70, 0x0D, 0x90, 0xFE, 0xC6, 0x74, 0x02, 0xF0, 0xA3, 0x74, 0x0F, 0xF0, 956 + 0x02, 0xE3, 0x56, 0x20, 0x2D, 0x03, 0x02, 0xE2, 0xEF, 0x90, 0xFE, 0xC6, 0x74, 0x01, 0xF0, 0xA3, 957 + 0x74, 0xFF, 0xF0, 0x90, 0xFF, 0x09, 0x30, 0x0A, 0x04, 0xE0, 0x30, 0xE1, 0xF9, 0x90, 0xFE, 0xC4, 958 + 0x74, 0x23, 0xF0, 0x12, 0xE7, 0xB0, 0x20, 0x36, 0x11, 0x20, 0x37, 0x0E, 0x12, 0xE7, 0xBC, 0x30, 959 + 0x3E, 0xF4, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0xD2, 0x37, 0x30, 0x37, 0x02, 0x61, 0xA7, 0x90, 960 + 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 0xFF, 0x23, 0x74, 0x80, 0xF0, 0x02, 0xE3, 0x3F, 0x90, 961 + 0xFE, 0xC6, 0xE4, 0xF0, 0xA3, 0x74, 0x3F, 0xF0, 0x78, 0x08, 0xC0, 0x00, 0xC2, 0x36, 0xC2, 0x37, 962 + 0x90, 0xFF, 0x09, 0x30, 0x0A, 0x04, 0xE0, 0x30, 0xE1, 0xF9, 0x90, 0xFE, 0xC4, 0x74, 0x23, 0xF0, 963 + 0x12, 0xE7, 0xB0, 0x20, 0x36, 0x11, 0x20, 0x37, 0x0E, 0x12, 0xE7, 0xBC, 0x30, 0x3E, 0xF4, 0x90, 964 + 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0xD2, 0x37, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 0xFF, 965 + 0x23, 0x74, 0x80, 0xF0, 0x30, 0x37, 0x04, 0xD0, 0x00, 0x80, 0x6C, 0xD0, 0x00, 0xD8, 0xBB, 0xC2, 966 + 0x36, 0xC2, 0x37, 0x90, 0xFE, 0xC6, 0xE4, 0xF0, 0xA3, 0x74, 0x0F, 0xF0, 0x90, 0xFE, 0xC0, 0x74, 967 + 0xF6, 0xF0, 0xA3, 0x74, 0x00, 0xF0, 0x90, 0xFE, 0xC4, 0x74, 0x23, 0xF0, 0x12, 0xE7, 0xB0, 0x20, 968 + 0x36, 0x11, 0x20, 0x37, 0x0E, 0x12, 0xE7, 0xBC, 0x30, 0x3E, 0xF4, 0x90, 0xFE, 0xD8, 0x74, 0x01, 969 + 0xF0, 0xD2, 0x37, 0x30, 0x37, 0x02, 0x80, 0x2F, 0xC2, 0x09, 0x12, 0xE7, 0xB0, 0x20, 0x08, 0x0E, 970 + 0x12, 0xE7, 0xBC, 0x30, 0x3E, 0xF7, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0xD2, 0x09, 0x30, 0x09, 971 + 0x02, 0x80, 0x14, 0x90, 0xFE, 0x64, 0x74, 0x90, 0x45, 0x4E, 0xF0, 0x90, 0xFE, 0x64, 0x74, 0x80, 972 + 0x45, 0x4E, 0xF0, 0x12, 0x2F, 0x59, 0x22, 0x7F, 0x00, 0x22, 0x90, 0xF6, 0x00, 0x7F, 0x06, 0x74, 973 + 0xFF, 0xF0, 0xA3, 0xDF, 0xFC, 0x7B, 0x02, 0x7C, 0xE9, 0x7D, 0xD3, 0x7E, 0xF6, 0x7F, 0x06, 0x12, 974 + 0x2F, 0x71, 0x7B, 0x02, 0x7C, 0xE9, 0x7D, 0xD3, 0x7E, 0xF6, 0x7F, 0x0B, 0x12, 0x2F, 0x71, 0x22, 975 + 0x90, 0xFE, 0xC6, 0xE4, 0xF0, 0xA3, 0x74, 0x0F, 0xF0, 0x90, 0xFE, 0x6F, 0xF0, 0x90, 0xFE, 0x70, 976 + 0xE0, 0x54, 0xFC, 0xF0, 0x90, 0xFE, 0xC0, 0x74, 0xF6, 0xF0, 0xA3, 0x74, 0x00, 0xF0, 0x90, 0xFE, 977 + 0x68, 0x74, 0x21, 0xF0, 0x90, 0xFE, 0x66, 0xE0, 0x54, 0xEF, 0xF0, 0x90, 0xE9, 0xD3, 0xE0, 0xF5, 978 + 0x08, 0xA3, 0xE0, 0xF5, 0x09, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE5, 0xFC, 0xE4, 0xF5, 0x10, 0x7E, 979 + 0xF4, 0x7F, 0x00, 0xC0, 0x06, 0xC0, 0x07, 0xC2, 0x36, 0xC2, 0x37, 0xC2, 0x09, 0x90, 0xE9, 0xCD, 980 + 0xE0, 0xF8, 0xA3, 0xE0, 0xF9, 0xA3, 0xE0, 0x90, 0xFE, 0x6B, 0xF0, 0xA3, 0xE9, 0xF0, 0xA3, 0xE8, 981 + 0xF0, 0x90, 0xFE, 0x6E, 0x74, 0x71, 0xF0, 0x90, 0xFE, 0xC4, 0x74, 0x21, 0xF0, 0x90, 0xFE, 0x65, 982 + 0x12, 0xE7, 0xB0, 0xE0, 0x20, 0xE4, 0x11, 0x12, 0xE7, 0xBC, 0x30, 0x3E, 0xF6, 0x90, 0xFE, 0xD8, 983 + 0x74, 0x01, 0xF0, 0xD2, 0x09, 0x02, 0xE4, 0x72, 0x74, 0x10, 0xF0, 0x12, 0xE7, 0xB0, 0x20, 0x36, 984 + 0x11, 0x20, 0x37, 0x0E, 0x12, 0xE7, 0xBC, 0x30, 0x3E, 0xF4, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 985 + 0xD2, 0x37, 0x20, 0x09, 0x05, 0x20, 0x37, 0x02, 0x80, 0x10, 0x90, 0xFE, 0x66, 0xE0, 0x44, 0x10, 986 + 0xF0, 0x12, 0x2F, 0x5C, 0xD0, 0x07, 0xD0, 0x06, 0xC3, 0x22, 0xD0, 0x07, 0xD0, 0x06, 0x7B, 0x10, 987 + 0x7C, 0xF6, 0x7D, 0x00, 0x12, 0x2F, 0x71, 0x05, 0x10, 0xC3, 0xE5, 0x09, 0x94, 0x01, 0xF5, 0x09, 988 + 0xE5, 0x08, 0x94, 0x00, 0xF5, 0x08, 0x45, 0x09, 0x70, 0x03, 0x02, 0xE4, 0xEF, 0x90, 0xE9, 0xCF, 989 + 0xE0, 0x24, 0x20, 0xF0, 0x90, 0xE9, 0xCE, 0xE0, 0x34, 0x00, 0xF0, 0x90, 0xE9, 0xCD, 0xE0, 0x34, 990 + 0x00, 0xF0, 0xC3, 0xEF, 0x24, 0x10, 0xFF, 0xEE, 0x34, 0x00, 0xFE, 0xE5, 0x10, 0x64, 0x20, 0x60, 991 + 0x03, 0x02, 0xE4, 0x13, 0x90, 0xFF, 0x2A, 0x74, 0x02, 0xF0, 0xA3, 0x74, 0x00, 0xF0, 0x75, 0x10, 992 + 0x00, 0x7E, 0xF4, 0x7F, 0x00, 0x90, 0xFF, 0x09, 0xE0, 0x30, 0xE5, 0xFC, 0x02, 0xE4, 0x13, 0xE5, 993 + 0x10, 0x60, 0x17, 0x7E, 0x00, 0x7F, 0x00, 0x78, 0x04, 0xC3, 0x33, 0xFF, 0xEE, 0x33, 0xFE, 0xEF, 994 + 0xD8, 0xF8, 0x90, 0xFF, 0x2A, 0xEE, 0xF0, 0xA3, 0xEF, 0xF0, 0x90, 0xFE, 0x66, 0xE0, 0x44, 0x10, 995 + 0xF0, 0x12, 0x2F, 0x5C, 0x78, 0x00, 0x88, 0x3C, 0x88, 0x3D, 0x88, 0x3E, 0x88, 0x3F, 0xD3, 0x22, 996 + 0x12, 0x2F, 0x5F, 0x12, 0x2F, 0x62, 0x90, 0xFE, 0xC6, 0xE4, 0xF0, 0xA3, 0x74, 0x0F, 0xF0, 0x90, 997 + 0xFE, 0x6F, 0xF0, 0x90, 0xFE, 0x70, 0xE0, 0x54, 0xFC, 0xF0, 0x90, 0xFE, 0xC0, 0x74, 0xF6, 0xF0, 998 + 0xA3, 0x74, 0x00, 0xF0, 0x90, 0xFE, 0x68, 0x74, 0x31, 0xF0, 0x90, 0xE9, 0xD3, 0xE0, 0xF8, 0xC0, 999 + 0x00, 0xC2, 0x08, 0xC2, 0x36, 0xC2, 0x37, 0x90, 0xE9, 0xD0, 0xE0, 0xF8, 0xA3, 0xE0, 0xF9, 0xA3, 1000 + 0xE0, 0x90, 0xFE, 0x6B, 0xF0, 0xA3, 0xE9, 0xF0, 0xA3, 0xE8, 0xF0, 0x90, 0xFE, 0x6E, 0x74, 0x81, 1001 + 0xF0, 0x90, 0xFE, 0xC4, 0x74, 0x23, 0xF0, 0x12, 0xE7, 0xB0, 0x20, 0x36, 0x11, 0x20, 0x37, 0x0E, 1002 + 0x12, 0xE7, 0xBC, 0x30, 0x3E, 0xF4, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0xD2, 0x37, 0x30, 0x37, 1003 + 0x07, 0xD0, 0x00, 0x12, 0x2F, 0x5C, 0xC3, 0x22, 0xC2, 0x09, 0x12, 0xE7, 0xB0, 0x20, 0x08, 0x0E, 1004 + 0x12, 0xE7, 0xBC, 0x30, 0x3E, 0xF7, 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0xD2, 0x09, 0x20, 0x09, 1005 + 0xE0, 0x90, 0xE9, 0xD2, 0xE0, 0x24, 0x01, 0xF0, 0x90, 0xE9, 0xD1, 0xE0, 0x34, 0x00, 0xF0, 0x90, 1006 + 0xE9, 0xD0, 0xE0, 0x34, 0x00, 0xF0, 0xD0, 0x00, 0x18, 0xE8, 0x60, 0x03, 0x02, 0xE5, 0x4F, 0x12, 1007 + 0x2F, 0x5C, 0x75, 0x3C, 0x00, 0x75, 0x3D, 0x00, 0x75, 0x3E, 0x00, 0x75, 0x3F, 0x00, 0xD3, 0x22, 1008 + 0x90, 0xE9, 0xD0, 0xE0, 0xF8, 0xA3, 0xE0, 0xF9, 0xA3, 0xE0, 0x90, 0xFE, 0x6B, 0xF0, 0xA3, 0xE9, 1009 + 0xF0, 0xA3, 0xE8, 0xF0, 0x90, 0xFE, 0x68, 0x74, 0x00, 0xF0, 0xC2, 0x08, 0x90, 0xFE, 0x6E, 0x74, 1010 + 0xB1, 0xF0, 0xC2, 0x09, 0x12, 0xE7, 0xB0, 0x20, 0x08, 0x0E, 0x12, 0xE7, 0xBC, 0x30, 0x3E, 0xF7, 1011 + 0x90, 0xFE, 0xD8, 0x74, 0x01, 0xF0, 0xD2, 0x09, 0x20, 0x09, 0x1E, 0x90, 0xFE, 0x70, 0xE0, 0x44, 1012 + 0x10, 0xF0, 0x54, 0xEF, 0xF0, 0x12, 0x2F, 0x59, 0xEF, 0x60, 0x0E, 0x75, 0x3C, 0x00, 0x75, 0x3D, 1013 + 0x00, 0x75, 0x3E, 0x00, 0x75, 0x3F, 0x00, 0xD3, 0x22, 0xC3, 0x22, 0x7B, 0x03, 0x7C, 0xE9, 0x7D, 1014 + 0xCD, 0x7E, 0xE9, 0x7F, 0xD7, 0x12, 0x2F, 0x71, 0x12, 0xE3, 0xAA, 0x90, 0xE9, 0xD5, 0xE0, 0x60, 1015 + 0x12, 0xF9, 0x12, 0xE7, 0x17, 0x40, 0x01, 0x22, 0x90, 0xF6, 0x00, 0x78, 0x06, 0x74, 0xFF, 0xF0, 1016 + 0xA3, 0xD8, 0xFC, 0x74, 0x01, 0x90, 0xE9, 0xCB, 0xF0, 0xE5, 0x3E, 0xC3, 0x13, 0x90, 0xE9, 0xCA, 1017 + 0xF0, 0xC0, 0xE0, 0x75, 0xF0, 0x02, 0xC0, 0xF0, 0x12, 0xE2, 0x2F, 0xEF, 0x70, 0x21, 0x20, 0x37, 1018 + 0x07, 0x20, 0x09, 0x04, 0xD0, 0xF0, 0x80, 0x05, 0xD0, 0xF0, 0xD5, 0xF0, 0xE9, 0xD0, 0xE0, 0x90, 1019 + 0xFF, 0x28, 0xE0, 0x30, 0xE7, 0xFC, 0x90, 0xFF, 0x28, 0xE0, 0x44, 0x01, 0xF0, 0xC3, 0x22, 0xD0, 1020 + 0xF0, 0x90, 0xE9, 0xD2, 0xE0, 0x24, 0x01, 0xF0, 0x90, 0xE9, 0xD1, 0xE0, 0x34, 0x00, 0xF0, 0x90, 1021 + 0xE9, 0xD0, 0xE0, 0x34, 0x00, 0xF0, 0xD0, 0xE0, 0x14, 0x70, 0xB6, 0x90, 0xE9, 0xD5, 0xE0, 0xF8, 1022 + 0x90, 0xE9, 0xCA, 0xE0, 0x28, 0xF5, 0xF0, 0xC3, 0x74, 0x20, 0x95, 0xF0, 0x60, 0x22, 0xF9, 0x90, 1023 + 0xE9, 0xCA, 0xE0, 0xF5, 0xF0, 0x90, 0xE9, 0xCF, 0xE0, 0x25, 0xF0, 0xF0, 0x90, 0xE9, 0xCE, 0xE0, 1024 + 0x34, 0x00, 0xF0, 0x90, 0xE9, 0xCD, 0xE0, 0x34, 0x00, 0xF0, 0x12, 0xE7, 0x17, 0x40, 0x01, 0x22, 1025 + 0x90, 0xE9, 0xD6, 0xE0, 0x70, 0x13, 0x7B, 0x03, 0x7C, 0xE9, 0x7D, 0xD7, 0x7E, 0xE9, 0x7F, 0xD0, 1026 + 0x12, 0x2F, 0x71, 0x12, 0xE5, 0xE0, 0x40, 0x01, 0x22, 0x75, 0x3C, 0x00, 0x75, 0x3D, 0x00, 0x75, 1027 + 0x3E, 0x00, 0x75, 0x3F, 0x00, 0xD3, 0x22, 0x90, 0xE9, 0xD6, 0xE0, 0x60, 0x18, 0x74, 0xFF, 0x90, 1028 + 0xF4, 0x00, 0x78, 0xFF, 0xF0, 0xA3, 0x18, 0xB8, 0x00, 0xFA, 0x78, 0xFF, 0xF0, 0xA3, 0x18, 0xB8, 1029 + 0x00, 0xFA, 0xF0, 0xA3, 0xF0, 0xC0, 0x01, 0x12, 0xE7, 0x70, 0x40, 0x04, 0xD0, 0x01, 0xC3, 0x22, 1030 + 0x90, 0xE9, 0xCF, 0xE0, 0x24, 0x01, 0xF0, 0x90, 0xE9, 0xCE, 0xE0, 0x34, 0x00, 0xF0, 0x90, 0xE9, 1031 + 0xCD, 0xE0, 0x34, 0x00, 0xF0, 0x90, 0xE9, 0xD2, 0xE0, 0x24, 0x01, 0xF0, 0x90, 0xE9, 0xD1, 0xE0, 1032 + 0x34, 0x00, 0xF0, 0x90, 0xE9, 0xD0, 0xE0, 0x34, 0x00, 0xF0, 0xD0, 0x01, 0xD9, 0xC7, 0xD3, 0x22, 1033 + 0xC2, 0x06, 0x90, 0xE9, 0xD6, 0xE0, 0x70, 0x28, 0x12, 0xE0, 0xD8, 0xEF, 0x60, 0x03, 0x02, 0xE7, 1034 + 0xA0, 0x90, 0xEB, 0xC2, 0xE0, 0x60, 0x17, 0x64, 0x02, 0x60, 0x15, 0x90, 0xF6, 0x00, 0x78, 0x06, 1035 + 0x74, 0xFF, 0xF0, 0xA3, 0xD8, 0xFC, 0x74, 0xF0, 0x90, 0xF6, 0x04, 0xF0, 0x80, 0x02, 0xC3, 0x22, 1036 + 0xE4, 0x90, 0xE9, 0xCB, 0xF0, 0x12, 0xE2, 0x2F, 0xEF, 0x70, 0x03, 0x02, 0xE7, 0x81, 0xD3, 0x22, 1037 + 0xC2, 0x3E, 0x75, 0x7C, 0x00, 0x75, 0x7D, 0x00, 0x75, 0x7E, 0x00, 0x22, 0x05, 0x7C, 0xE5, 0x7C, 1038 + 0x70, 0x14, 0x05, 0x7D, 0xE5, 0x7D, 0x70, 0x04, 0x05, 0x7E, 0x80, 0x0A, 0xB4, 0x17, 0x07, 0xE5, 1039 + 0x7E, 0xB4, 0x06, 0x02, 0xD2, 0x3E, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 1040 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 1041 + 0x58, 0x44, 0x2D, 0x52, 0x57, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x31, 0x30, 0x30, 0x30, 0x30 }; 1042 +
+956
drivers/staging/keucr/ms.c
··· 1 + #include <linux/slab.h> 2 + #include "usb.h" 3 + #include "scsiglue.h" 4 + #include "transport.h" 5 + #include "ms.h" 6 + 7 + //----- MS_ReaderCopyBlock() ------------------------------------------ 8 + int MS_ReaderCopyBlock(struct us_data *us, WORD oldphy, WORD newphy, WORD PhyBlockAddr, BYTE PageNum, PBYTE buf, WORD len) 9 + { 10 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 11 + int result; 12 + 13 + //printk("MS_ReaderCopyBlock --- PhyBlockAddr = %x, PageNum = %x\n", PhyBlockAddr, PageNum); 14 + result = ENE_LoadBinCode(us, MS_RW_PATTERN); 15 + if (result != USB_STOR_XFER_GOOD) 16 + return USB_STOR_TRANSPORT_ERROR; 17 + 18 + memset(bcb, 0, sizeof(bcb)); 19 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 20 + bcb->DataTransferLength = 0x200*len; 21 + bcb->Flags = 0x00; 22 + bcb->CDB[0] = 0xF0; 23 + bcb->CDB[1] = 0x08; 24 + bcb->CDB[4] = (BYTE)(oldphy); 25 + bcb->CDB[3] = (BYTE)(oldphy>>8); 26 + bcb->CDB[2] = (BYTE)(oldphy>>16); 27 + bcb->CDB[7] = (BYTE)(newphy); 28 + bcb->CDB[6] = (BYTE)(newphy>>8); 29 + bcb->CDB[5] = (BYTE)(newphy>>16); 30 + bcb->CDB[9] = (BYTE)(PhyBlockAddr); 31 + bcb->CDB[8] = (BYTE)(PhyBlockAddr>>8); 32 + bcb->CDB[10] = PageNum; 33 + 34 + result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0); 35 + if (result != USB_STOR_XFER_GOOD) 36 + return USB_STOR_TRANSPORT_ERROR; 37 + 38 + return USB_STOR_TRANSPORT_GOOD; 39 + } 40 + 41 + //----- MS_ReaderReadPage() ------------------------------------------ 42 + int MS_ReaderReadPage(struct us_data *us, DWORD PhyBlockAddr, BYTE PageNum, PDWORD PageBuf, MS_LibTypeExtdat *ExtraDat) 43 + { 44 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 45 + int result; 46 + BYTE ExtBuf[4]; 47 + DWORD bn = PhyBlockAddr * 0x20 + PageNum; 48 + 49 + //printk("MS --- MS_ReaderReadPage, PhyBlockAddr = %x, PageNum = %x\n", PhyBlockAddr, PageNum); 50 + 51 + result = ENE_LoadBinCode(us, MS_RW_PATTERN); 52 + if (result != USB_STOR_XFER_GOOD) 53 + return USB_STOR_TRANSPORT_ERROR; 54 + 55 + // Read Page Data 56 + memset(bcb, 0, sizeof(bcb)); 57 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 58 + bcb->DataTransferLength = 0x200; 59 + bcb->Flags = 0x80; 60 + bcb->CDB[0] = 0xF1; 61 + bcb->CDB[1] = 0x02; 62 + bcb->CDB[5] = (BYTE)(bn); 63 + bcb->CDB[4] = (BYTE)(bn>>8); 64 + bcb->CDB[3] = (BYTE)(bn>>16); 65 + bcb->CDB[2] = (BYTE)(bn>>24); 66 + 67 + result = ENE_SendScsiCmd(us, FDIR_READ, PageBuf, 0); 68 + if (result != USB_STOR_XFER_GOOD) 69 + return USB_STOR_TRANSPORT_ERROR; 70 + 71 + // Read Extra Data 72 + memset(bcb, 0, sizeof(bcb)); 73 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 74 + bcb->DataTransferLength = 0x4; 75 + bcb->Flags = 0x80; 76 + bcb->CDB[0] = 0xF1; 77 + bcb->CDB[1] = 0x03; 78 + bcb->CDB[5] = (BYTE)(PageNum); 79 + bcb->CDB[4] = (BYTE)(PhyBlockAddr); 80 + bcb->CDB[3] = (BYTE)(PhyBlockAddr>>8); 81 + bcb->CDB[2] = (BYTE)(PhyBlockAddr>>16); 82 + bcb->CDB[6] = 0x01; 83 + 84 + result = ENE_SendScsiCmd(us, FDIR_READ, &ExtBuf, 0); 85 + if (result != USB_STOR_XFER_GOOD) 86 + return USB_STOR_TRANSPORT_ERROR; 87 + 88 + ExtraDat->reserved = 0; 89 + ExtraDat->intr = 0x80; // Not yet, �����], �� fireware support 90 + ExtraDat->status0 = 0x10; // Not yet, �����], �� fireware support 91 + ExtraDat->status1 = 0x00; // Not yet, �����], �� fireware support 92 + ExtraDat->ovrflg = ExtBuf[0]; 93 + ExtraDat->mngflg = ExtBuf[1]; 94 + ExtraDat->logadr = MemStickLogAddr(ExtBuf[2], ExtBuf[3]); 95 + 96 + return USB_STOR_TRANSPORT_GOOD; 97 + } 98 + 99 + //----- MS_ReaderEraseBlock() ---------------------------------------- 100 + int MS_ReaderEraseBlock(struct us_data *us, DWORD PhyBlockAddr) 101 + { 102 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 103 + int result; 104 + DWORD bn = PhyBlockAddr; 105 + 106 + //printk("MS --- MS_ReaderEraseBlock, PhyBlockAddr = %x\n", PhyBlockAddr); 107 + result = ENE_LoadBinCode(us, MS_RW_PATTERN); 108 + if (result != USB_STOR_XFER_GOOD) 109 + return USB_STOR_TRANSPORT_ERROR; 110 + 111 + memset(bcb, 0, sizeof(bcb)); 112 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 113 + bcb->DataTransferLength = 0x200; 114 + bcb->Flags = 0x80; 115 + bcb->CDB[0] = 0xF2; 116 + bcb->CDB[1] = 0x06; 117 + bcb->CDB[4] = (BYTE)(bn); 118 + bcb->CDB[3] = (BYTE)(bn>>8); 119 + bcb->CDB[2] = (BYTE)(bn>>16); 120 + 121 + result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0); 122 + if (result != USB_STOR_XFER_GOOD) 123 + return USB_STOR_TRANSPORT_ERROR; 124 + 125 + return USB_STOR_TRANSPORT_GOOD; 126 + } 127 + 128 + //----- MS_CardInit() ------------------------------------------------ 129 + int MS_CardInit(struct us_data *us) 130 + { 131 + DWORD result=0; 132 + WORD TmpBlock; 133 + PBYTE PageBuffer0 = NULL, PageBuffer1 = NULL; 134 + MS_LibTypeExtdat extdat; 135 + WORD btBlk1st, btBlk2nd; 136 + DWORD btBlk1stErred; 137 + 138 + printk("MS_CardInit start\n"); 139 + 140 + MS_LibFreeAllocatedArea(us); 141 + 142 + if (((PageBuffer0 = kmalloc(MS_BYTES_PER_PAGE, GFP_KERNEL)) == NULL) || 143 + ((PageBuffer1 = kmalloc(MS_BYTES_PER_PAGE, GFP_KERNEL)) == NULL)) 144 + { 145 + result = MS_NO_MEMORY_ERROR; 146 + goto exit; 147 + } 148 + 149 + btBlk1st = btBlk2nd = MS_LB_NOT_USED; 150 + btBlk1stErred = 0; 151 + 152 + for (TmpBlock=0; TmpBlock < MS_MAX_INITIAL_ERROR_BLOCKS+2; TmpBlock++) 153 + { 154 + switch (MS_ReaderReadPage(us, TmpBlock, 0, (DWORD *)PageBuffer0, &extdat)) 155 + { 156 + case MS_STATUS_SUCCESS: 157 + break; 158 + case MS_STATUS_INT_ERROR: 159 + break; 160 + case MS_STATUS_ERROR: 161 + default: 162 + continue; 163 + } 164 + 165 + if ((extdat.ovrflg & MS_REG_OVR_BKST) == MS_REG_OVR_BKST_NG) 166 + continue; 167 + 168 + if (((extdat.mngflg & MS_REG_MNG_SYSFLG) == MS_REG_MNG_SYSFLG_USER) || 169 + (BigEndianWORD(((MemStickBootBlockPage0 *)PageBuffer0)->header.wBlockID) != MS_BOOT_BLOCK_ID) || 170 + (BigEndianWORD(((MemStickBootBlockPage0 *)PageBuffer0)->header.wFormatVersion) != MS_BOOT_BLOCK_FORMAT_VERSION) || 171 + (((MemStickBootBlockPage0 *)PageBuffer0)->header.bNumberOfDataEntry != MS_BOOT_BLOCK_DATA_ENTRIES)) 172 + continue; 173 + 174 + if (btBlk1st != MS_LB_NOT_USED) 175 + { 176 + btBlk2nd = TmpBlock; 177 + break; 178 + } 179 + 180 + btBlk1st = TmpBlock; 181 + memcpy(PageBuffer1, PageBuffer0, MS_BYTES_PER_PAGE); 182 + if (extdat.status1 & (MS_REG_ST1_DTER | MS_REG_ST1_EXER | MS_REG_ST1_FGER)) 183 + btBlk1stErred = 1; 184 + } 185 + 186 + if (btBlk1st == MS_LB_NOT_USED) 187 + { 188 + result = MS_STATUS_ERROR; 189 + goto exit; 190 + } 191 + 192 + // write protect 193 + if ((extdat.status0 & MS_REG_ST0_WP) == MS_REG_ST0_WP_ON) 194 + MS_LibCtrlSet(us, MS_LIB_CTRL_WRPROTECT); 195 + 196 + result = MS_STATUS_ERROR; 197 + // 1st Boot Block 198 + if (btBlk1stErred == 0) 199 + result = MS_LibProcessBootBlock(us, btBlk1st, PageBuffer1); // 1st 200 + // 2nd Boot Block 201 + if (result && (btBlk2nd != MS_LB_NOT_USED)) 202 + result = MS_LibProcessBootBlock(us, btBlk2nd, PageBuffer0); 203 + 204 + if (result) 205 + { 206 + result = MS_STATUS_ERROR; 207 + goto exit; 208 + } 209 + 210 + for (TmpBlock = 0; TmpBlock < btBlk1st; TmpBlock++) 211 + us->MS_Lib.Phy2LogMap[TmpBlock] = MS_LB_INITIAL_ERROR; 212 + 213 + us->MS_Lib.Phy2LogMap[btBlk1st] = MS_LB_BOOT_BLOCK; 214 + 215 + if (btBlk2nd != MS_LB_NOT_USED) 216 + { 217 + for (TmpBlock = btBlk1st + 1; TmpBlock < btBlk2nd; TmpBlock++) 218 + us->MS_Lib.Phy2LogMap[TmpBlock] = MS_LB_INITIAL_ERROR; 219 + us->MS_Lib.Phy2LogMap[btBlk2nd] = MS_LB_BOOT_BLOCK; 220 + } 221 + 222 + result = MS_LibScanLogicalBlockNumber(us, btBlk1st); 223 + if (result) 224 + goto exit; 225 + 226 + for (TmpBlock=MS_PHYSICAL_BLOCKS_PER_SEGMENT; TmpBlock<us->MS_Lib.NumberOfPhyBlock; TmpBlock+=MS_PHYSICAL_BLOCKS_PER_SEGMENT) 227 + { 228 + if (MS_CountFreeBlock(us, TmpBlock) == 0) 229 + { 230 + MS_LibCtrlSet(us, MS_LIB_CTRL_WRPROTECT); 231 + break; 232 + } 233 + } 234 + 235 + // write 236 + if (MS_LibAllocWriteBuf(us)) 237 + { 238 + result = MS_NO_MEMORY_ERROR; 239 + goto exit; 240 + } 241 + 242 + result = MS_STATUS_SUCCESS; 243 + 244 + exit: 245 + if (PageBuffer1) kfree(PageBuffer1); 246 + if (PageBuffer0) kfree(PageBuffer0); 247 + 248 + printk("MS_CardInit end\n"); 249 + return result; 250 + } 251 + 252 + //----- MS_LibCheckDisableBlock() ------------------------------------ 253 + int MS_LibCheckDisableBlock(struct us_data *us, WORD PhyBlock) 254 + { 255 + PWORD PageBuf=NULL; 256 + DWORD result=MS_STATUS_SUCCESS; 257 + DWORD blk, index=0; 258 + MS_LibTypeExtdat extdat; 259 + 260 + if (((PageBuf = kmalloc(MS_BYTES_PER_PAGE, GFP_KERNEL)) == NULL)) 261 + { 262 + result = MS_NO_MEMORY_ERROR; 263 + goto exit; 264 + } 265 + 266 + MS_ReaderReadPage(us, PhyBlock, 1, (DWORD *)PageBuf, &extdat); 267 + do 268 + { 269 + blk = BigEndianWORD(PageBuf[index]); 270 + if (blk == MS_LB_NOT_USED) 271 + break; 272 + if (blk == us->MS_Lib.Log2PhyMap[0]) 273 + { 274 + result = MS_ERROR_FLASH_READ; 275 + break; 276 + } 277 + index++; 278 + } while(1); 279 + 280 + exit: 281 + if (PageBuf) kfree(PageBuf); 282 + return result; 283 + } 284 + 285 + //----- MS_LibFreeAllocatedArea() ------------------------------------ 286 + void MS_LibFreeAllocatedArea(struct us_data *us) 287 + { 288 + MS_LibFreeWriteBuf(us); 289 + MS_LibFreeLogicalMap(us); 290 + 291 + us->MS_Lib.flags = 0; 292 + us->MS_Lib.BytesPerSector = 0; 293 + us->MS_Lib.SectorsPerCylinder = 0; 294 + 295 + us->MS_Lib.cardType = 0; 296 + us->MS_Lib.blockSize = 0; 297 + us->MS_Lib.PagesPerBlock = 0; 298 + 299 + us->MS_Lib.NumberOfPhyBlock = 0; 300 + us->MS_Lib.NumberOfLogBlock = 0; 301 + } 302 + 303 + //----- MS_LibFreeWriteBuf() ----------------------------------------- 304 + void MS_LibFreeWriteBuf(struct us_data *us) 305 + { 306 + us->MS_Lib.wrtblk = (WORD)-1; //set to -1 307 + MS_LibClearPageMap(us); // memset((fdoExt)->MS_Lib.pagemap, 0, sizeof((fdoExt)->MS_Lib.pagemap)) 308 + 309 + if (us->MS_Lib.blkpag) 310 + { 311 + kfree((BYTE *)(us->MS_Lib.blkpag)); // Arnold test ... 312 + us->MS_Lib.blkpag = NULL; 313 + } 314 + 315 + if (us->MS_Lib.blkext) 316 + { 317 + kfree((BYTE *)(us->MS_Lib.blkext)); // Arnold test ... 318 + us->MS_Lib.blkext = NULL; 319 + } 320 + } 321 + 322 + //----- MS_LibFreeLogicalMap() --------------------------------------- 323 + int MS_LibFreeLogicalMap(struct us_data *us) 324 + { 325 + if (us->MS_Lib.Phy2LogMap) 326 + { 327 + kfree(us->MS_Lib.Phy2LogMap); 328 + us->MS_Lib.Phy2LogMap = NULL; 329 + } 330 + 331 + if (us->MS_Lib.Log2PhyMap) 332 + { 333 + kfree(us->MS_Lib.Log2PhyMap); 334 + us->MS_Lib.Log2PhyMap = NULL; 335 + } 336 + 337 + return 0; 338 + } 339 + 340 + //----- MS_LibProcessBootBlock() ------------------------------------- 341 + int MS_LibProcessBootBlock(struct us_data *us, WORD PhyBlock, BYTE *PageData) 342 + { 343 + MemStickBootBlockSysEnt *SysEntry; 344 + MemStickBootBlockSysInf *SysInfo; 345 + DWORD i, result; 346 + BYTE PageNumber; 347 + BYTE *PageBuffer; 348 + MS_LibTypeExtdat ExtraData; 349 + 350 + if ((PageBuffer = (BYTE *)kmalloc(MS_BYTES_PER_PAGE, GFP_KERNEL))==NULL) 351 + return (DWORD)-1; 352 + 353 + result = (DWORD)-1; 354 + 355 + SysInfo= &(((MemStickBootBlockPage0 *)PageData)->sysinf); 356 + 357 + if ((SysInfo->bMsClass != MS_SYSINF_MSCLASS_TYPE_1) || 358 + (BigEndianWORD(SysInfo->wPageSize) != MS_SYSINF_PAGE_SIZE) || 359 + ((SysInfo->bSecuritySupport & MS_SYSINF_SECURITY) == MS_SYSINF_SECURITY_SUPPORT) || 360 + (SysInfo->bReserved1 != MS_SYSINF_RESERVED1) || 361 + (SysInfo->bReserved2 != MS_SYSINF_RESERVED2) || 362 + (SysInfo->bFormatType!= MS_SYSINF_FORMAT_FAT) || 363 + (SysInfo->bUsage != MS_SYSINF_USAGE_GENERAL)) 364 + goto exit; 365 + 366 + switch (us->MS_Lib.cardType = SysInfo->bCardType) 367 + { 368 + case MS_SYSINF_CARDTYPE_RDONLY: 369 + MS_LibCtrlSet(us, MS_LIB_CTRL_RDONLY); 370 + break; 371 + case MS_SYSINF_CARDTYPE_RDWR: 372 + MS_LibCtrlReset(us, MS_LIB_CTRL_RDONLY); 373 + break; 374 + case MS_SYSINF_CARDTYPE_HYBRID: 375 + default: 376 + goto exit; 377 + } 378 + 379 + us->MS_Lib.blockSize = BigEndianWORD(SysInfo->wBlockSize); 380 + us->MS_Lib.NumberOfPhyBlock = BigEndianWORD(SysInfo->wBlockNumber); 381 + us->MS_Lib.NumberOfLogBlock = BigEndianWORD(SysInfo->wTotalBlockNumber)- 2; 382 + us->MS_Lib.PagesPerBlock = us->MS_Lib.blockSize * SIZE_OF_KIRO / MS_BYTES_PER_PAGE; 383 + us->MS_Lib.NumberOfSegment = us->MS_Lib.NumberOfPhyBlock / MS_PHYSICAL_BLOCKS_PER_SEGMENT; 384 + us->MS_Model = BigEndianWORD(SysInfo->wMemorySize); 385 + 386 + if (MS_LibAllocLogicalMap(us)) //Allocate to all number of logicalblock and physicalblock 387 + goto exit; 388 + 389 + MS_LibSetBootBlockMark(us, PhyBlock); //Mark the book block 390 + 391 + SysEntry = &(((MemStickBootBlockPage0 *)PageData)->sysent); 392 + 393 + for (i=0; i<MS_NUMBER_OF_SYSTEM_ENTRY; i++) 394 + { 395 + DWORD EntryOffset, EntrySize; 396 + 397 + if ((EntryOffset = BigEndianDWORD(SysEntry->entry[i].dwStart)) == 0xffffff) 398 + continue; 399 + 400 + if ((EntrySize = BigEndianDWORD(SysEntry->entry[i].dwSize)) == 0) 401 + continue; 402 + 403 + if (EntryOffset + MS_BYTES_PER_PAGE + EntrySize > us->MS_Lib.blockSize * (DWORD)SIZE_OF_KIRO) 404 + continue; 405 + 406 + if (i == 0) 407 + { 408 + BYTE PrevPageNumber = 0; 409 + WORD phyblk; 410 + 411 + if (SysEntry->entry[i].bType != MS_SYSENT_TYPE_INVALID_BLOCK) 412 + goto exit; 413 + 414 + while (EntrySize > 0) 415 + { 416 + if ((PageNumber = (BYTE)(EntryOffset / MS_BYTES_PER_PAGE + 1)) != PrevPageNumber) 417 + { 418 + switch (MS_ReaderReadPage(us, PhyBlock, PageNumber, (DWORD *)PageBuffer, &ExtraData)) 419 + { 420 + case MS_STATUS_SUCCESS: 421 + break; 422 + case MS_STATUS_WRITE_PROTECT: 423 + case MS_ERROR_FLASH_READ: 424 + case MS_STATUS_ERROR: 425 + default: 426 + goto exit; 427 + } 428 + 429 + PrevPageNumber = PageNumber; 430 + } 431 + 432 + if ((phyblk = BigEndianWORD(*(WORD *)(PageBuffer + (EntryOffset % MS_BYTES_PER_PAGE)))) < 0x0fff) 433 + MS_LibSetInitialErrorBlock(us, phyblk); 434 + 435 + EntryOffset += 2; 436 + EntrySize -= 2; 437 + } 438 + } 439 + else if (i == 1) 440 + { // CIS/IDI 441 + MemStickBootBlockIDI *idi; 442 + 443 + if (SysEntry->entry[i].bType != MS_SYSENT_TYPE_CIS_IDI) 444 + goto exit; 445 + 446 + switch (MS_ReaderReadPage(us, PhyBlock, (BYTE)(EntryOffset / MS_BYTES_PER_PAGE + 1), (DWORD *)PageBuffer, &ExtraData)) 447 + { 448 + case MS_STATUS_SUCCESS: 449 + break; 450 + case MS_STATUS_WRITE_PROTECT: 451 + case MS_ERROR_FLASH_READ: 452 + case MS_STATUS_ERROR: 453 + default: 454 + goto exit; 455 + } 456 + 457 + idi = &((MemStickBootBlockCIS_IDI *)(PageBuffer + (EntryOffset % MS_BYTES_PER_PAGE)))->idi.idi; 458 + if (LittleEndianWORD(idi->wIDIgeneralConfiguration) != MS_IDI_GENERAL_CONF) 459 + goto exit; 460 + 461 + us->MS_Lib.BytesPerSector = LittleEndianWORD(idi->wIDIbytesPerSector); 462 + if (us->MS_Lib.BytesPerSector != MS_BYTES_PER_PAGE) 463 + goto exit; 464 + } 465 + } // End for .. 466 + 467 + result = 0; 468 + 469 + exit: 470 + if (result) MS_LibFreeLogicalMap(us); 471 + if (PageBuffer) kfree(PageBuffer); 472 + 473 + result = 0; 474 + return result; 475 + } 476 + 477 + //----- MS_LibAllocLogicalMap() -------------------------------------- 478 + int MS_LibAllocLogicalMap(struct us_data *us) 479 + { 480 + DWORD i; 481 + 482 + 483 + us->MS_Lib.Phy2LogMap = (WORD *)kmalloc(us->MS_Lib.NumberOfPhyBlock * sizeof(WORD), GFP_KERNEL); 484 + us->MS_Lib.Log2PhyMap = (WORD *)kmalloc(us->MS_Lib.NumberOfLogBlock * sizeof(WORD), GFP_KERNEL); 485 + 486 + if ((us->MS_Lib.Phy2LogMap == NULL) || (us->MS_Lib.Log2PhyMap == NULL)) 487 + { 488 + MS_LibFreeLogicalMap(us); 489 + return (DWORD)-1; 490 + } 491 + 492 + for (i = 0; i < us->MS_Lib.NumberOfPhyBlock; i++) 493 + us->MS_Lib.Phy2LogMap[i] = MS_LB_NOT_USED; 494 + 495 + for (i = 0; i < us->MS_Lib.NumberOfLogBlock; i++) 496 + us->MS_Lib.Log2PhyMap[i] = MS_LB_NOT_USED; 497 + 498 + return 0; 499 + } 500 + 501 + //----- MS_LibSetBootBlockMark() ------------------------------------- 502 + int MS_LibSetBootBlockMark(struct us_data *us, WORD phyblk) 503 + { 504 + return MS_LibSetLogicalBlockMark(us, phyblk, MS_LB_BOOT_BLOCK); 505 + } 506 + 507 + //----- MS_LibSetLogicalBlockMark() ---------------------------------- 508 + int MS_LibSetLogicalBlockMark(struct us_data *us, WORD phyblk, WORD mark) 509 + { 510 + if (phyblk >= us->MS_Lib.NumberOfPhyBlock) 511 + return (DWORD)-1; 512 + 513 + us->MS_Lib.Phy2LogMap[phyblk] = mark; 514 + 515 + return 0; 516 + } 517 + 518 + //----- MS_LibSetInitialErrorBlock() --------------------------------- 519 + int MS_LibSetInitialErrorBlock(struct us_data *us, WORD phyblk) 520 + { 521 + return MS_LibSetLogicalBlockMark(us, phyblk, MS_LB_INITIAL_ERROR); 522 + } 523 + 524 + //----- MS_LibScanLogicalBlockNumber() ------------------------------- 525 + int MS_LibScanLogicalBlockNumber(struct us_data *us, WORD btBlk1st) 526 + { 527 + WORD PhyBlock, newblk, i; 528 + WORD LogStart, LogEnde; 529 + MS_LibTypeExtdat extdat; 530 + BYTE buf[0x200]; 531 + DWORD count=0, index=0; 532 + 533 + for (PhyBlock = 0; PhyBlock < us->MS_Lib.NumberOfPhyBlock;) 534 + { 535 + MS_LibPhy2LogRange(PhyBlock, &LogStart, &LogEnde); 536 + 537 + for (i=0; i<MS_PHYSICAL_BLOCKS_PER_SEGMENT; i++, PhyBlock++) 538 + { 539 + switch (MS_LibConv2Logical(us, PhyBlock)) 540 + { 541 + case MS_STATUS_ERROR: 542 + continue; 543 + default: 544 + break; 545 + } 546 + 547 + if (count == PhyBlock) 548 + { 549 + MS_LibReadExtraBlock(us, PhyBlock, 0, 0x80, &buf); 550 + count += 0x80; 551 + } 552 + index = (PhyBlock % 0x80) * 4; 553 + 554 + extdat.ovrflg = buf[index]; 555 + extdat.mngflg = buf[index+1]; 556 + extdat.logadr = MemStickLogAddr(buf[index+2], buf[index+3]); 557 + 558 + if ((extdat.ovrflg & MS_REG_OVR_BKST) != MS_REG_OVR_BKST_OK) 559 + { 560 + MS_LibSetAcquiredErrorBlock(us, PhyBlock); 561 + continue; 562 + } 563 + 564 + if ((extdat.mngflg & MS_REG_MNG_ATFLG) == MS_REG_MNG_ATFLG_ATTBL) 565 + { 566 + MS_LibErasePhyBlock(us, PhyBlock); 567 + continue; 568 + } 569 + 570 + if (extdat.logadr != MS_LB_NOT_USED) 571 + { 572 + if ((extdat.logadr < LogStart) || (LogEnde <= extdat.logadr)) 573 + { 574 + MS_LibErasePhyBlock(us, PhyBlock); 575 + continue; 576 + } 577 + 578 + if ((newblk = MS_LibConv2Physical(us, extdat.logadr)) != MS_LB_NOT_USED) 579 + { 580 + if (extdat.logadr==0) 581 + { 582 + MS_LibSetLogicalPair(us, extdat.logadr, PhyBlock); 583 + if ( MS_LibCheckDisableBlock(us, btBlk1st) ) 584 + { 585 + MS_LibSetLogicalPair(us, extdat.logadr, newblk); 586 + continue; 587 + } 588 + } 589 + 590 + MS_LibReadExtra(us, newblk, 0, &extdat); 591 + if ((extdat.ovrflg & MS_REG_OVR_UDST) == MS_REG_OVR_UDST_UPDATING) 592 + { 593 + MS_LibErasePhyBlock(us, PhyBlock); 594 + continue; 595 + } 596 + else 597 + MS_LibErasePhyBlock(us, newblk); 598 + } 599 + 600 + MS_LibSetLogicalPair(us, extdat.logadr, PhyBlock); 601 + } 602 + } 603 + } //End for ... 604 + 605 + return MS_STATUS_SUCCESS; 606 + } 607 + 608 + //----- MS_LibAllocWriteBuf() ---------------------------------------- 609 + int MS_LibAllocWriteBuf(struct us_data *us) 610 + { 611 + us->MS_Lib.wrtblk = (WORD)-1; 612 + 613 + us->MS_Lib.blkpag = (BYTE *)kmalloc(us->MS_Lib.PagesPerBlock * us->MS_Lib.BytesPerSector, GFP_KERNEL); 614 + us->MS_Lib.blkext = (MS_LibTypeExtdat *)kmalloc(us->MS_Lib.PagesPerBlock * sizeof(MS_LibTypeExtdat), GFP_KERNEL); 615 + 616 + if ((us->MS_Lib.blkpag == NULL) || (us->MS_Lib.blkext == NULL)) 617 + { 618 + MS_LibFreeWriteBuf(us); 619 + return (DWORD)-1; 620 + } 621 + 622 + MS_LibClearWriteBuf(us); 623 + 624 + return 0; 625 + } 626 + 627 + //----- MS_LibClearWriteBuf() ---------------------------------------- 628 + void MS_LibClearWriteBuf(struct us_data *us) 629 + { 630 + int i; 631 + 632 + us->MS_Lib.wrtblk = (WORD)-1; 633 + MS_LibClearPageMap(us); 634 + 635 + if (us->MS_Lib.blkpag) 636 + memset(us->MS_Lib.blkpag, 0xff, us->MS_Lib.PagesPerBlock * us->MS_Lib.BytesPerSector); 637 + 638 + if (us->MS_Lib.blkext) 639 + { 640 + for (i = 0; i < us->MS_Lib.PagesPerBlock; i++) 641 + { 642 + us->MS_Lib.blkext[i].status1 = MS_REG_ST1_DEFAULT; 643 + us->MS_Lib.blkext[i].ovrflg = MS_REG_OVR_DEFAULT; 644 + us->MS_Lib.blkext[i].mngflg = MS_REG_MNG_DEFAULT; 645 + us->MS_Lib.blkext[i].logadr = MS_LB_NOT_USED; 646 + } 647 + } 648 + } 649 + 650 + //----- MS_LibPhy2LogRange() ----------------------------------------- 651 + void MS_LibPhy2LogRange(WORD PhyBlock, WORD *LogStart, WORD *LogEnde) 652 + { 653 + PhyBlock /= MS_PHYSICAL_BLOCKS_PER_SEGMENT; 654 + 655 + if (PhyBlock) 656 + { 657 + *LogStart = MS_LOGICAL_BLOCKS_IN_1ST_SEGMENT + (PhyBlock - 1) * MS_LOGICAL_BLOCKS_PER_SEGMENT;//496 658 + *LogEnde = *LogStart + MS_LOGICAL_BLOCKS_PER_SEGMENT;//496 659 + } 660 + else 661 + { 662 + *LogStart = 0; 663 + *LogEnde = MS_LOGICAL_BLOCKS_IN_1ST_SEGMENT;//494 664 + } 665 + } 666 + 667 + //----- MS_LibReadExtraBlock() -------------------------------------------- 668 + int MS_LibReadExtraBlock(struct us_data *us, DWORD PhyBlock, BYTE PageNum, BYTE blen, void *buf) 669 + { 670 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 671 + int result; 672 + 673 + //printk("MS_LibReadExtraBlock --- PhyBlock = %x, PageNum = %x, blen = %x\n", PhyBlock, PageNum, blen); 674 + 675 + // Read Extra Data 676 + memset(bcb, 0, sizeof(bcb)); 677 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 678 + bcb->DataTransferLength = 0x4 * blen; 679 + bcb->Flags = 0x80; 680 + bcb->CDB[0] = 0xF1; 681 + bcb->CDB[1] = 0x03; 682 + bcb->CDB[5] = (BYTE)(PageNum); 683 + bcb->CDB[4] = (BYTE)(PhyBlock); 684 + bcb->CDB[3] = (BYTE)(PhyBlock>>8); 685 + bcb->CDB[2] = (BYTE)(PhyBlock>>16); 686 + bcb->CDB[6] = blen; 687 + 688 + result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0); 689 + if (result != USB_STOR_XFER_GOOD) 690 + return USB_STOR_TRANSPORT_ERROR; 691 + 692 + return USB_STOR_TRANSPORT_GOOD; 693 + } 694 + 695 + //----- MS_LibReadExtra() -------------------------------------------- 696 + int MS_LibReadExtra(struct us_data *us, DWORD PhyBlock, BYTE PageNum, MS_LibTypeExtdat *ExtraDat) 697 + { 698 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 699 + int result; 700 + BYTE ExtBuf[4]; 701 + 702 + //printk("MS_LibReadExtra --- PhyBlock = %x, PageNum = %x\n", PhyBlock, PageNum); 703 + memset(bcb, 0, sizeof(bcb)); 704 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 705 + bcb->DataTransferLength = 0x4; 706 + bcb->Flags = 0x80; 707 + bcb->CDB[0] = 0xF1; 708 + bcb->CDB[1] = 0x03; 709 + bcb->CDB[5] = (BYTE)(PageNum); 710 + bcb->CDB[4] = (BYTE)(PhyBlock); 711 + bcb->CDB[3] = (BYTE)(PhyBlock>>8); 712 + bcb->CDB[2] = (BYTE)(PhyBlock>>16); 713 + bcb->CDB[6] = 0x01; 714 + 715 + result = ENE_SendScsiCmd(us, FDIR_READ, &ExtBuf, 0); 716 + if (result != USB_STOR_XFER_GOOD) 717 + return USB_STOR_TRANSPORT_ERROR; 718 + 719 + ExtraDat->reserved = 0; 720 + ExtraDat->intr = 0x80; // Not yet, waiting for fireware support 721 + ExtraDat->status0 = 0x10; // Not yet, waiting for fireware support 722 + ExtraDat->status1 = 0x00; // Not yet, waiting for fireware support 723 + ExtraDat->ovrflg = ExtBuf[0]; 724 + ExtraDat->mngflg = ExtBuf[1]; 725 + ExtraDat->logadr = MemStickLogAddr(ExtBuf[2], ExtBuf[3]); 726 + 727 + return USB_STOR_TRANSPORT_GOOD; 728 + } 729 + 730 + //----- MS_LibSetAcquiredErrorBlock() -------------------------------- 731 + int MS_LibSetAcquiredErrorBlock(struct us_data *us, WORD phyblk) 732 + { 733 + WORD log; 734 + 735 + if (phyblk >= us->MS_Lib.NumberOfPhyBlock) 736 + return (DWORD)-1; 737 + 738 + if ((log = us->MS_Lib.Phy2LogMap[phyblk]) < us->MS_Lib.NumberOfLogBlock) 739 + us->MS_Lib.Log2PhyMap[log] = MS_LB_NOT_USED; 740 + 741 + if (us->MS_Lib.Phy2LogMap[phyblk] != MS_LB_INITIAL_ERROR) 742 + us->MS_Lib.Phy2LogMap[phyblk] = MS_LB_ACQUIRED_ERROR; 743 + 744 + return 0; 745 + } 746 + 747 + //----- MS_LibErasePhyBlock() ---------------------------------------- 748 + int MS_LibErasePhyBlock(struct us_data *us, WORD phyblk) 749 + { 750 + WORD log; 751 + 752 + if (phyblk >= us->MS_Lib.NumberOfPhyBlock) 753 + return MS_STATUS_ERROR; 754 + 755 + if ((log = us->MS_Lib.Phy2LogMap[phyblk]) < us->MS_Lib.NumberOfLogBlock) 756 + us->MS_Lib.Log2PhyMap[log] = MS_LB_NOT_USED; 757 + 758 + us->MS_Lib.Phy2LogMap[phyblk] = MS_LB_NOT_USED; 759 + 760 + if (MS_LibIsWritable(us)) 761 + { 762 + switch (MS_ReaderEraseBlock(us, phyblk)) 763 + { 764 + case MS_STATUS_SUCCESS: 765 + us->MS_Lib.Phy2LogMap[phyblk] = MS_LB_NOT_USED_ERASED; 766 + return MS_STATUS_SUCCESS; 767 + case MS_ERROR_FLASH_ERASE: 768 + case MS_STATUS_INT_ERROR : 769 + MS_LibErrorPhyBlock(us, phyblk); 770 + return MS_ERROR_FLASH_ERASE; 771 + case MS_STATUS_ERROR: 772 + default: 773 + MS_LibCtrlSet(us, MS_LIB_CTRL_RDONLY); 774 + MS_LibSetAcquiredErrorBlock(us, phyblk); 775 + return MS_STATUS_ERROR; 776 + } 777 + } 778 + 779 + MS_LibSetAcquiredErrorBlock(us, phyblk); 780 + 781 + return MS_STATUS_SUCCESS; 782 + } 783 + 784 + //----- MS_LibErrorPhyBlock() ---------------------------------------- 785 + int MS_LibErrorPhyBlock(struct us_data *us, WORD phyblk) 786 + { 787 + if (phyblk >= us->MS_Lib.NumberOfPhyBlock) 788 + return MS_STATUS_ERROR; 789 + 790 + MS_LibSetAcquiredErrorBlock(us, phyblk); 791 + 792 + if (MS_LibIsWritable(us)) 793 + return MS_LibOverwriteExtra(us, phyblk, 0, (BYTE)(~MS_REG_OVR_BKST)); 794 + 795 + 796 + return MS_STATUS_SUCCESS; 797 + } 798 + 799 + //----- MS_LibOverwriteExtra() --------------------------------------- 800 + int MS_LibOverwriteExtra(struct us_data *us, DWORD PhyBlockAddr, BYTE PageNum, BYTE OverwriteFlag) 801 + { 802 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 803 + int result; 804 + 805 + //printk("MS --- MS_LibOverwriteExtra, PhyBlockAddr = %x, PageNum = %x\n", PhyBlockAddr, PageNum); 806 + result = ENE_LoadBinCode(us, MS_RW_PATTERN); 807 + if (result != USB_STOR_XFER_GOOD) 808 + return USB_STOR_TRANSPORT_ERROR; 809 + 810 + memset(bcb, 0, sizeof(bcb)); 811 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 812 + bcb->DataTransferLength = 0x4; 813 + bcb->Flags = 0x80; 814 + bcb->CDB[0] = 0xF2; 815 + bcb->CDB[1] = 0x05; 816 + bcb->CDB[5] = (BYTE)(PageNum); 817 + bcb->CDB[4] = (BYTE)(PhyBlockAddr); 818 + bcb->CDB[3] = (BYTE)(PhyBlockAddr>>8); 819 + bcb->CDB[2] = (BYTE)(PhyBlockAddr>>16); 820 + bcb->CDB[6] = OverwriteFlag; 821 + bcb->CDB[7] = 0xFF; 822 + bcb->CDB[8] = 0xFF; 823 + bcb->CDB[9] = 0xFF; 824 + 825 + result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0); 826 + if (result != USB_STOR_XFER_GOOD) 827 + return USB_STOR_TRANSPORT_ERROR; 828 + 829 + return USB_STOR_TRANSPORT_GOOD; 830 + } 831 + 832 + //----- MS_LibForceSetLogicalPair() ---------------------------------- 833 + int MS_LibForceSetLogicalPair(struct us_data *us, WORD logblk, WORD phyblk) 834 + { 835 + if (logblk == MS_LB_NOT_USED) 836 + return 0; 837 + 838 + if ((logblk >= us->MS_Lib.NumberOfLogBlock) || (phyblk >= us->MS_Lib.NumberOfPhyBlock)) 839 + return (DWORD)-1; 840 + 841 + us->MS_Lib.Phy2LogMap[phyblk] = logblk; 842 + us->MS_Lib.Log2PhyMap[logblk] = phyblk; 843 + 844 + return 0; 845 + } 846 + 847 + //----- MS_LibSetLogicalPair() --------------------------------------- 848 + int MS_LibSetLogicalPair(struct us_data *us, WORD logblk, WORD phyblk) 849 + { 850 + if ((logblk >= us->MS_Lib.NumberOfLogBlock) || (phyblk >= us->MS_Lib.NumberOfPhyBlock)) 851 + return (DWORD)-1; 852 + 853 + us->MS_Lib.Phy2LogMap[phyblk] = logblk; 854 + us->MS_Lib.Log2PhyMap[logblk] = phyblk; 855 + 856 + return 0; 857 + } 858 + 859 + //----- MS_CountFreeBlock() ------------------------------------------ 860 + int MS_CountFreeBlock(struct us_data *us, WORD PhyBlock) 861 + { 862 + DWORD Ende, Count; 863 + 864 + Ende = PhyBlock + MS_PHYSICAL_BLOCKS_PER_SEGMENT; 865 + for (Count = 0; PhyBlock < Ende; PhyBlock++) 866 + { 867 + switch (us->MS_Lib.Phy2LogMap[PhyBlock]) 868 + { 869 + case MS_LB_NOT_USED: 870 + case MS_LB_NOT_USED_ERASED: 871 + Count++; 872 + default: 873 + break; 874 + } 875 + } 876 + 877 + return Count; 878 + } 879 + 880 + //----- MS_LibSearchBlockFromPhysical() ------------------------------ 881 + int MS_LibSearchBlockFromPhysical(struct us_data *us, WORD phyblk) 882 + { 883 + WORD Newblk; 884 + WORD blk; 885 + MS_LibTypeExtdat extdat; 886 + 887 + if (phyblk >= us->MS_Lib.NumberOfPhyBlock) 888 + return MS_LB_ERROR; 889 + 890 + for (blk = phyblk + 1; blk != phyblk; blk++) 891 + { 892 + if ((blk & MS_PHYSICAL_BLOCKS_PER_SEGMENT_MASK) == 0) 893 + blk -= MS_PHYSICAL_BLOCKS_PER_SEGMENT; 894 + 895 + Newblk = us->MS_Lib.Phy2LogMap[blk]; 896 + if (us->MS_Lib.Phy2LogMap[blk] == MS_LB_NOT_USED_ERASED) 897 + return blk; 898 + else if (us->MS_Lib.Phy2LogMap[blk] == MS_LB_NOT_USED) 899 + { 900 + switch (MS_LibReadExtra(us, blk, 0, &extdat)) 901 + { 902 + case MS_STATUS_SUCCESS : 903 + case MS_STATUS_SUCCESS_WITH_ECC: 904 + break; 905 + case MS_NOCARD_ERROR: 906 + return MS_NOCARD_ERROR; 907 + case MS_STATUS_INT_ERROR: 908 + return MS_LB_ERROR; 909 + case MS_ERROR_FLASH_READ: 910 + default: 911 + MS_LibSetAcquiredErrorBlock(us, blk); // MS_LibErrorPhyBlock(fdoExt, blk); 912 + continue; 913 + } // End switch 914 + 915 + if ((extdat.ovrflg & MS_REG_OVR_BKST) != MS_REG_OVR_BKST_OK) 916 + { 917 + MS_LibSetAcquiredErrorBlock(us, blk); 918 + continue; 919 + } 920 + 921 + switch (MS_LibErasePhyBlock(us, blk)) 922 + { 923 + case MS_STATUS_SUCCESS: 924 + return blk; 925 + case MS_STATUS_ERROR: 926 + return MS_LB_ERROR; 927 + case MS_ERROR_FLASH_ERASE: 928 + default: 929 + MS_LibErrorPhyBlock(us, blk); 930 + break; 931 + } 932 + } 933 + } // End for 934 + 935 + return MS_LB_ERROR; 936 + } 937 + 938 + //----- MS_LibSearchBlockFromLogical() ------------------------------- 939 + int MS_LibSearchBlockFromLogical(struct us_data *us, WORD logblk) 940 + { 941 + WORD phyblk; 942 + 943 + if ((phyblk=MS_LibConv2Physical(us, logblk)) >= MS_LB_ERROR) 944 + { 945 + if (logblk >= us->MS_Lib.NumberOfLogBlock) 946 + return MS_LB_ERROR; 947 + 948 + phyblk = (logblk + MS_NUMBER_OF_BOOT_BLOCK) / MS_LOGICAL_BLOCKS_PER_SEGMENT; 949 + phyblk *= MS_PHYSICAL_BLOCKS_PER_SEGMENT; 950 + phyblk += MS_PHYSICAL_BLOCKS_PER_SEGMENT - 1; 951 + } 952 + 953 + return MS_LibSearchBlockFromPhysical(us, phyblk); 954 + } 955 + 956 +
+383
drivers/staging/keucr/ms.h
··· 1 + #ifndef MS_INCD 2 + #define MS_INCD 3 + 4 + #include <linux/blkdev.h> 5 + #include "common.h" 6 + 7 + // MemoryStick Register 8 + // Status Register 0 9 + #define MS_REG_ST0_MB 0x80 // media busy 10 + #define MS_REG_ST0_FB0 0x40 // flush busy 0 11 + #define MS_REG_ST0_BE 0x20 // buffer empty 12 + #define MS_REG_ST0_BF 0x10 // buffer full 13 + #define MS_REG_ST0_SL 0x02 // sleep 14 + #define MS_REG_ST0_WP 0x01 // write protected 15 + #define MS_REG_ST0_WP_ON MS_REG_ST0_WP 16 + #define MS_REG_ST0_WP_OFF 0x00 17 + 18 + // Status Register 1 19 + #define MS_REG_ST1_MB 0x80 // media busy 20 + #define MS_REG_ST1_FB1 0x40 // flush busy 1 21 + #define MS_REG_ST1_DTER 0x20 // error on data(corrected) 22 + #define MS_REG_ST1_UCDT 0x10 // unable to correct data 23 + #define MS_REG_ST1_EXER 0x08 // error on extra(corrected) 24 + #define MS_REG_ST1_UCEX 0x04 // unable to correct extra 25 + #define MS_REG_ST1_FGER 0x02 // error on overwrite flag(corrected) 26 + #define MS_REG_ST1_UCFG 0x01 // unable to correct overwrite flag 27 + #define MS_REG_ST1_DEFAULT (MS_REG_ST1_MB | MS_REG_ST1_FB1 | \ 28 + MS_REG_ST1_DTER | MS_REG_ST1_UCDT | \ 29 + MS_REG_ST1_EXER | MS_REG_ST1_UCEX | \ 30 + MS_REG_ST1_FGER | MS_REG_ST1_UCFG) 31 + 32 + // System Parameter 33 + #define MS_REG_SYSPAR_BAMD 0x80 // block address mode 34 + #define MS_REG_SYSPAR_BAND_LINEAR MS_REG_SYSPAR_BAMD // linear mode 35 + #define MS_REG_SYSPAR_BAND_CHIP 0x00 // chip mode 36 + #define MS_REG_SYSPAR_ATEN 0x40 // attribute ROM enable 37 + #define MS_REG_SYSPAR_ATEN_ENABLE MS_REG_SYSPAR_ATEN // enable 38 + #define MS_REG_SYSPAR_ATEN_DISABLE 0x00 // disable 39 + #define MS_REG_SYSPAR_RESERVED 0x2f 40 + 41 + // Command Parameter 42 + #define MS_REG_CMDPAR_CP2 0x80 43 + #define MS_REG_CMDPAR_CP1 0x40 44 + #define MS_REG_CMDPAR_CP0 0x20 45 + #define MS_REG_CMDPAR_BLOCK_ACCESS 0 46 + #define MS_REG_CMDPAR_PAGE_ACCESS MS_REG_CMDPAR_CP0 47 + #define MS_REG_CMDPAR_EXTRA_DATA MS_REG_CMDPAR_CP1 48 + #define MS_REG_CMDPAR_OVERWRITE MS_REG_CMDPAR_CP2 49 + #define MS_REG_CMDPAR_RESERVED 0x1f 50 + 51 + // Overwrite Area 52 + #define MS_REG_OVR_BKST 0x80 // block status 53 + #define MS_REG_OVR_BKST_OK MS_REG_OVR_BKST // OK 54 + #define MS_REG_OVR_BKST_NG 0x00 // NG 55 + #define MS_REG_OVR_PGST0 0x40 // page status 56 + #define MS_REG_OVR_PGST1 0x20 57 + #define MS_REG_OVR_PGST_MASK (MS_REG_OVR_PGST0 | MS_REG_OVR_PGST1) 58 + #define MS_REG_OVR_PGST_OK (MS_REG_OVR_PGST0 | MS_REG_OVR_PGST1) // OK 59 + #define MS_REG_OVR_PGST_NG MS_REG_OVR_PGST1 // NG 60 + #define MS_REG_OVR_PGST_DATA_ERROR 0x00 // data error 61 + #define MS_REG_OVR_UDST 0x10 // update status 62 + #define MS_REG_OVR_UDST_UPDATING 0x00 // updating 63 + #define MS_REG_OVR_UDST_NO_UPDATE MS_REG_OVR_UDST 64 + #define MS_REG_OVR_RESERVED 0x08 65 + #define MS_REG_OVR_DEFAULT (MS_REG_OVR_BKST_OK | \ 66 + MS_REG_OVR_PGST_OK | \ 67 + MS_REG_OVR_UDST_NO_UPDATE | \ 68 + MS_REG_OVR_RESERVED) 69 + // Management Flag 70 + #define MS_REG_MNG_SCMS0 0x20 // serial copy management system 71 + #define MS_REG_MNG_SCMS1 0x10 72 + #define MS_REG_MNG_SCMS_MASK (MS_REG_MNG_SCMS0 | MS_REG_MNG_SCMS1) 73 + #define MS_REG_MNG_SCMS_COPY_OK (MS_REG_MNG_SCMS0 | MS_REG_MNG_SCMS1) 74 + #define MS_REG_MNG_SCMS_ONE_COPY MS_REG_MNG_SCMS1 75 + #define MS_REG_MNG_SCMS_NO_COPY 0x00 76 + #define MS_REG_MNG_ATFLG 0x08 // address transfer table flag 77 + #define MS_REG_MNG_ATFLG_OTHER MS_REG_MNG_ATFLG // other 78 + #define MS_REG_MNG_ATFLG_ATTBL 0x00 // address transfer table 79 + #define MS_REG_MNG_SYSFLG 0x04 // system flag 80 + #define MS_REG_MNG_SYSFLG_USER MS_REG_MNG_SYSFLG // user block 81 + #define MS_REG_MNG_SYSFLG_BOOT 0x00 // system block 82 + #define MS_REG_MNG_RESERVED 0xc3 83 + #define MS_REG_MNG_DEFAULT (MS_REG_MNG_SCMS_COPY_OK | \ 84 + MS_REG_MNG_ATFLG_OTHER | \ 85 + MS_REG_MNG_SYSFLG_USER | \ 86 + MS_REG_MNG_RESERVED) 87 + 88 + // Error codes 89 + #define MS_STATUS_SUCCESS 0x0000 90 + #define MS_ERROR_OUT_OF_SPACE 0x0103 91 + #define MS_STATUS_WRITE_PROTECT 0x0106 92 + #define MS_ERROR_READ_DATA 0x8002 93 + #define MS_ERROR_FLASH_READ 0x8003 94 + #define MS_ERROR_FLASH_WRITE 0x8004 95 + #define MS_ERROR_FLASH_ERASE 0x8005 96 + #define MS_ERROR_FLASH_COPY 0x8006 97 + 98 + #define MS_STATUS_ERROR 0xfffe 99 + #define MS_FIFO_ERROR 0xfffd 100 + #define MS_UNDEFINED_ERROR 0xfffc 101 + #define MS_KETIMEOUT_ERROR 0xfffb 102 + #define MS_STATUS_INT_ERROR 0xfffa 103 + #define MS_NO_MEMORY_ERROR 0xfff9 104 + #define MS_NOCARD_ERROR 0xfff8 105 + #define MS_LB_NOT_USED 0xffff 106 + #define MS_LB_ERROR 0xfff0 107 + #define MS_LB_BOOT_BLOCK 0xfff1 108 + #define MS_LB_INITIAL_ERROR 0xfff2 109 + #define MS_STATUS_SUCCESS_WITH_ECC 0xfff3 110 + #define MS_LB_ACQUIRED_ERROR 0xfff4 111 + #define MS_LB_NOT_USED_ERASED 0xfff5 112 + 113 + #define MS_LibConv2Physical(pdx, LogBlock) (((LogBlock) >= (pdx)->MS_Lib.NumberOfLogBlock) ? MS_STATUS_ERROR : (pdx)->MS_Lib.Log2PhyMap[LogBlock]) 114 + #define MS_LibConv2Logical(pdx, PhyBlock) (((PhyBlock) >= (pdx)->MS_Lib.NumberOfPhyBlock) ? MS_STATUS_ERROR : (pdx)->MS_Lib.Phy2LogMap[PhyBlock]) //�dphy->log table 115 + 116 + #define MS_LIB_CTRL_RDONLY 0 117 + #define MS_LIB_CTRL_WRPROTECT 1 118 + #define MS_LibCtrlCheck(pdx, Flag) ((pdx)->MS_Lib.flags & (1 << (Flag))) 119 + 120 + #define MS_LibCtrlSet(pdx, Flag) (pdx)->MS_Lib.flags |= (1 << (Flag)) 121 + #define MS_LibCtrlReset(pdx, Flag) (pdx)->MS_Lib.flags &= ~(1 << (Flag)) 122 + #define MS_LibIsWritable(pdx) ((MS_LibCtrlCheck((pdx), MS_LIB_CTRL_RDONLY) == 0) && (MS_LibCtrlCheck(pdx, MS_LIB_CTRL_WRPROTECT) == 0)) 123 + 124 + #define MS_MAX_PAGES_PER_BLOCK 32 125 + #define MS_LIB_BITS_PER_BYTE 8 126 + 127 + #define MS_LibPageMapIdx(n) ((n) / MS_LIB_BITS_PER_BYTE) 128 + #define MS_LibPageMapBit(n) (1 << ((n) % MS_LIB_BITS_PER_BYTE)) 129 + #define MS_LibCheckPageMapBit(pdx, n) ((pdx)->MS_Lib.pagemap[MS_LibPageMapIdx(n)] & MS_LibPageMapBit(n)) 130 + #define MS_LibSetPageMapBit(pdx, n) ((pdx)->MS_Lib.pagemap[MS_LibPageMapIdx(n)] |= MS_LibPageMapBit(n)) 131 + #define MS_LibResetPageMapBit(pdx, n) ((pdx)->MS_Lib.pagemap[MS_LibPageMapIdx(n)] &= ~MS_LibPageMapBit(n)) 132 + #define MS_LibClearPageMap(pdx) memset((pdx)->MS_Lib.pagemap, 0, sizeof((pdx)->MS_Lib.pagemap)) 133 + 134 + 135 + #define MemStickLogAddr(logadr1, logadr0) ((((WORD)(logadr1)) << 8) | (logadr0)) 136 + 137 + #define MS_BYTES_PER_PAGE 512 138 + 139 + #define MS_MAX_INITIAL_ERROR_BLOCKS 10 140 + #define MS_NUMBER_OF_PAGES_FOR_BOOT_BLOCK 3 141 + #define MS_NUMBER_OF_PAGES_FOR_LPCTBL 2 142 + 143 + #define MS_NUMBER_OF_BOOT_BLOCK 2 144 + #define MS_NUMBER_OF_SYSTEM_BLOCK 4 145 + #define MS_LOGICAL_BLOCKS_PER_SEGMENT 496 146 + #define MS_LOGICAL_BLOCKS_IN_1ST_SEGMENT 494 147 + #define MS_PHYSICAL_BLOCKS_PER_SEGMENT 0x200 // 512 148 + #define MS_PHYSICAL_BLOCKS_PER_SEGMENT_MASK 0x1ff 149 + 150 + #define MS_SECTOR_SIZE 512 151 + #define MBR_SIGNATURE 0xAA55 152 + #define PBR_SIGNATURE 0xAA55 153 + 154 + #define PARTITION_FAT_12 1 155 + #define PARTITION_FAT_16 2 156 + 157 + #define MS_BOOT_BLOCK_ID 0x0001 158 + #define MS_BOOT_BLOCK_FORMAT_VERSION 0x0100 159 + #define MS_BOOT_BLOCK_DATA_ENTRIES 2 160 + 161 + #define MS_SYSINF_MSCLASS_TYPE_1 1 162 + #define MS_SYSINF_CARDTYPE_RDONLY 1 163 + #define MS_SYSINF_CARDTYPE_RDWR 2 164 + #define MS_SYSINF_CARDTYPE_HYBRID 3 165 + #define MS_SYSINF_SECURITY 0x01 166 + #define MS_SYSINF_SECURITY_NO_SUPPORT MS_SYSINF_SECURITY 167 + #define MS_SYSINF_SECURITY_SUPPORT 0 168 + #define MS_SYSINF_FORMAT_MAT 0 // ? 169 + #define MS_SYSINF_FORMAT_FAT 1 170 + #define MS_SYSINF_USAGE_GENERAL 0 171 + #define MS_SYSINF_PAGE_SIZE MS_BYTES_PER_PAGE // fixed 172 + #define MS_SYSINF_RESERVED1 1 173 + #define MS_SYSINF_RESERVED2 1 174 + 175 + #define MS_SYSENT_TYPE_INVALID_BLOCK 0x01 176 + #define MS_SYSENT_TYPE_CIS_IDI 0x0a // CIS/IDI 177 + 178 + #define SIZE_OF_KIRO 1024 179 + 180 + // BOOT BLOCK 181 + #define MS_NUMBER_OF_SYSTEM_ENTRY 4 182 + 183 + //----- MemStickRegisters -------------------------------------------- 184 + // Status registers (16 bytes) 185 + typedef struct { 186 + BYTE Reserved0; // 00 187 + BYTE INTRegister; // 01 188 + BYTE StatusRegister0; // 02 189 + BYTE StatusRegister1; // 03 190 + BYTE Reserved1[12]; // 04-0F 191 + } MemStickStatusRegisters; 192 + 193 + // Parameter registers (6 bytes) 194 + typedef struct { 195 + BYTE SystemParameter; // 10 196 + BYTE BlockAddress2; // 11 197 + BYTE BlockAddress1; // 12 198 + BYTE BlockAddress0; // 13 199 + BYTE CMDParameter; // 14 200 + BYTE PageAddress; // 15 201 + } MemStickParameterRegisters; 202 + 203 + // Extra registers (9 bytes) 204 + typedef struct { 205 + BYTE OverwriteFlag; // 16 206 + BYTE ManagementFlag; // 17 207 + BYTE LogicalAddress1; // 18 208 + BYTE LogicalAddress0; // 19 209 + BYTE ReservedArea[5]; // 1A-1E 210 + } MemStickExtraDataRegisters; 211 + 212 + // All registers in Memory Stick (32 bytes, includes 1 byte padding) 213 + typedef struct { 214 + MemStickStatusRegisters status; 215 + MemStickParameterRegisters param; 216 + MemStickExtraDataRegisters extra; 217 + BYTE padding; 218 + } MemStickRegisters, *PMemStickRegisters; 219 + 220 + //----- MemStickBootBlockPage0 --------------------------------------- 221 + typedef struct { 222 + WORD wBlockID; 223 + WORD wFormatVersion; 224 + BYTE bReserved1[184]; 225 + BYTE bNumberOfDataEntry; 226 + BYTE bReserved2[179]; 227 + } MemStickBootBlockHeader; 228 + 229 + typedef struct { 230 + DWORD dwStart; 231 + DWORD dwSize; 232 + BYTE bType; 233 + BYTE bReserved[3]; 234 + } MemStickBootBlockSysEntRec; 235 + 236 + typedef struct { 237 + MemStickBootBlockSysEntRec entry[MS_NUMBER_OF_SYSTEM_ENTRY]; 238 + } MemStickBootBlockSysEnt; 239 + 240 + typedef struct { 241 + BYTE bMsClass; // must be 1 242 + BYTE bCardType; // see below 243 + WORD wBlockSize; // n KB 244 + WORD wBlockNumber; // number of physical block 245 + WORD wTotalBlockNumber; // number of logical block 246 + WORD wPageSize; // must be 0x200 247 + BYTE bExtraSize; // 0x10 248 + BYTE bSecuritySupport; 249 + BYTE bAssemblyDate[8]; 250 + BYTE bFactoryArea[4]; 251 + BYTE bAssemblyMakerCode; 252 + BYTE bAssemblyMachineCode[3]; 253 + WORD wMemoryMakerCode; 254 + WORD wMemoryDeviceCode; 255 + WORD wMemorySize; 256 + BYTE bReserved1; 257 + BYTE bReserved2; 258 + BYTE bVCC; 259 + BYTE bVPP; 260 + WORD wControllerChipNumber; 261 + WORD wControllerFunction; // New MS 262 + BYTE bReserved3[9]; // New MS 263 + BYTE bParallelSupport; // New MS 264 + WORD wFormatValue; // New MS 265 + BYTE bFormatType; 266 + BYTE bUsage; 267 + BYTE bDeviceType; 268 + BYTE bReserved4[22]; 269 + BYTE bFUValue3; 270 + BYTE bFUValue4; 271 + BYTE bReserved5[15]; 272 + } MemStickBootBlockSysInf; 273 + 274 + typedef struct { 275 + MemStickBootBlockHeader header; 276 + MemStickBootBlockSysEnt sysent; 277 + MemStickBootBlockSysInf sysinf; 278 + } MemStickBootBlockPage0; 279 + 280 + //----- MemStickBootBlockCIS_IDI ------------------------------------- 281 + typedef struct { 282 + BYTE bCistplDEVICE[6]; // 0 283 + BYTE bCistplDEVICE0C[6]; // 6 284 + BYTE bCistplJEDECC[4]; // 12 285 + BYTE bCistplMANFID[6]; // 16 286 + BYTE bCistplVER1[32]; // 22 287 + BYTE bCistplFUNCID[4]; // 54 288 + BYTE bCistplFUNCE0[4]; // 58 289 + BYTE bCistplFUNCE1[5]; // 62 290 + BYTE bCistplCONF[7]; // 67 291 + BYTE bCistplCFTBLENT0[10]; // 74 292 + BYTE bCistplCFTBLENT1[8]; // 84 293 + BYTE bCistplCFTBLENT2[12]; // 92 294 + BYTE bCistplCFTBLENT3[8]; // 104 295 + BYTE bCistplCFTBLENT4[17]; // 112 296 + BYTE bCistplCFTBLENT5[8]; // 129 297 + BYTE bCistplCFTBLENT6[17]; // 137 298 + BYTE bCistplCFTBLENT7[8]; // 154 299 + BYTE bCistplNOLINK[3]; // 162 300 + } MemStickBootBlockCIS; 301 + 302 + typedef struct { 303 + #define MS_IDI_GENERAL_CONF 0x848A 304 + WORD wIDIgeneralConfiguration; // 0 305 + WORD wIDInumberOfCylinder; // 1 306 + WORD wIDIreserved0; // 2 307 + WORD wIDInumberOfHead; // 3 308 + WORD wIDIbytesPerTrack; // 4 309 + WORD wIDIbytesPerSector; // 5 310 + WORD wIDIsectorsPerTrack; // 6 311 + WORD wIDItotalSectors[2]; // 7-8 high,low 312 + WORD wIDIreserved1[11]; // 9-19 313 + WORD wIDIbufferType; // 20 314 + WORD wIDIbufferSize; // 21 315 + WORD wIDIlongCmdECC; // 22 316 + WORD wIDIfirmVersion[4]; // 23-26 317 + WORD wIDImodelName[20]; // 27-46 318 + WORD wIDIreserved2; // 47 319 + WORD wIDIlongWordSupported; // 48 320 + WORD wIDIdmaSupported; // 49 321 + WORD wIDIreserved3; // 50 322 + WORD wIDIpioTiming; // 51 323 + WORD wIDIdmaTiming; // 52 324 + WORD wIDItransferParameter; // 53 325 + WORD wIDIformattedCylinder; // 54 326 + WORD wIDIformattedHead; // 55 327 + WORD wIDIformattedSectorsPerTrack; // 56 328 + WORD wIDIformattedTotalSectors[2]; // 57-58 329 + WORD wIDImultiSector; // 59 330 + WORD wIDIlbaSectors[2]; // 60-61 331 + WORD wIDIsingleWordDMA; // 62 332 + WORD wIDImultiWordDMA; // 63 333 + WORD wIDIreserved4[192]; // 64-255 334 + } MemStickBootBlockIDI; 335 + 336 + typedef struct { 337 + 338 + union 339 + { 340 + MemStickBootBlockCIS cis; 341 + BYTE dmy[256]; 342 + } cis; 343 + 344 + union 345 + { 346 + MemStickBootBlockIDI idi; 347 + BYTE dmy[256]; 348 + } idi; 349 + 350 + } MemStickBootBlockCIS_IDI; 351 + 352 + //----- MS_LibControl ------------------------------------------------ 353 + typedef struct { 354 + BYTE reserved; 355 + BYTE intr; 356 + BYTE status0; 357 + BYTE status1; 358 + BYTE ovrflg; 359 + BYTE mngflg; 360 + WORD logadr; 361 + } MS_LibTypeExtdat; 362 + 363 + typedef struct { 364 + DWORD flags; 365 + DWORD BytesPerSector; 366 + DWORD NumberOfCylinder; 367 + DWORD SectorsPerCylinder; 368 + WORD cardType; // R/W, RO, Hybrid 369 + WORD blockSize; 370 + WORD PagesPerBlock; 371 + WORD NumberOfPhyBlock; 372 + WORD NumberOfLogBlock; 373 + WORD NumberOfSegment; 374 + WORD *Phy2LogMap; //phy2log table 375 + WORD *Log2PhyMap; //log2phy table 376 + WORD wrtblk; 377 + BYTE pagemap[(MS_MAX_PAGES_PER_BLOCK+(MS_LIB_BITS_PER_BYTE-1))/MS_LIB_BITS_PER_BYTE]; 378 + BYTE *blkpag; 379 + MS_LibTypeExtdat *blkext; 380 + BYTE copybuf[512]; 381 + } MS_LibControl; 382 + 383 + #endif
+320
drivers/staging/keucr/msscsi.c
··· 1 + #include <linux/sched.h> 2 + #include <linux/errno.h> 3 + #include <linux/slab.h> 4 + 5 + #include <scsi/scsi.h> 6 + #include <scsi/scsi_eh.h> 7 + #include <scsi/scsi_device.h> 8 + 9 + #include "usb.h" 10 + #include "scsiglue.h" 11 + #include "transport.h" 12 + 13 + int MS_SCSI_Test_Unit_Ready (struct us_data *us, struct scsi_cmnd *srb); 14 + int MS_SCSI_Inquiry (struct us_data *us, struct scsi_cmnd *srb); 15 + int MS_SCSI_Mode_Sense (struct us_data *us, struct scsi_cmnd *srb); 16 + int MS_SCSI_Start_Stop (struct us_data *us, struct scsi_cmnd *srb); 17 + int MS_SCSI_Read_Capacity (struct us_data *us, struct scsi_cmnd *srb); 18 + int MS_SCSI_Read (struct us_data *us, struct scsi_cmnd *srb); 19 + int MS_SCSI_Write (struct us_data *us, struct scsi_cmnd *srb); 20 + 21 + //----- MS_SCSIIrp() -------------------------------------------------- 22 + int MS_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb) 23 + { 24 + int result; 25 + 26 + us->SrbStatus = SS_SUCCESS; 27 + switch (srb->cmnd[0]) 28 + { 29 + case TEST_UNIT_READY : result = MS_SCSI_Test_Unit_Ready (us, srb); break; //0x00 30 + case INQUIRY : result = MS_SCSI_Inquiry (us, srb); break; //0x12 31 + case MODE_SENSE : result = MS_SCSI_Mode_Sense (us, srb); break; //0x1A 32 + case READ_CAPACITY : result = MS_SCSI_Read_Capacity (us, srb); break; //0x25 33 + case READ_10 : result = MS_SCSI_Read (us, srb); break; //0x28 34 + case WRITE_10 : result = MS_SCSI_Write (us, srb); break; //0x2A 35 + 36 + default: 37 + us->SrbStatus = SS_ILLEGAL_REQUEST; 38 + result = USB_STOR_TRANSPORT_FAILED; 39 + break; 40 + } 41 + return result; 42 + } 43 + 44 + //----- MS_SCSI_Test_Unit_Ready() -------------------------------------------------- 45 + int MS_SCSI_Test_Unit_Ready(struct us_data *us, struct scsi_cmnd *srb) 46 + { 47 + //printk("MS_SCSI_Test_Unit_Ready\n"); 48 + if (us->MS_Status.Insert && us->MS_Status.Ready) 49 + return USB_STOR_TRANSPORT_GOOD; 50 + else 51 + { 52 + ENE_MSInit(us); 53 + return USB_STOR_TRANSPORT_GOOD; 54 + } 55 + 56 + return USB_STOR_TRANSPORT_GOOD; 57 + } 58 + 59 + //----- MS_SCSI_Inquiry() -------------------------------------------------- 60 + int MS_SCSI_Inquiry(struct us_data *us, struct scsi_cmnd *srb) 61 + { 62 + //printk("MS_SCSI_Inquiry\n"); 63 + BYTE data_ptr[36] = {0x00, 0x80, 0x02, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x55, 0x53, 0x42, 0x32, 0x2E, 0x30, 0x20, 0x20, 0x43, 0x61, 0x72, 0x64, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x30, 0x30}; 64 + 65 + usb_stor_set_xfer_buf(us, data_ptr, 36, srb, TO_XFER_BUF); 66 + return USB_STOR_TRANSPORT_GOOD; 67 + } 68 + 69 + 70 + //----- MS_SCSI_Mode_Sense() -------------------------------------------------- 71 + int MS_SCSI_Mode_Sense(struct us_data *us, struct scsi_cmnd *srb) 72 + { 73 + BYTE mediaNoWP[12] = {0x0b,0x00,0x00,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00}; 74 + BYTE mediaWP[12] = {0x0b,0x00,0x80,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00}; 75 + 76 + if (us->MS_Status.WtP) 77 + usb_stor_set_xfer_buf(us, mediaWP, 12, srb, TO_XFER_BUF); 78 + else 79 + usb_stor_set_xfer_buf(us, mediaNoWP, 12, srb, TO_XFER_BUF); 80 + 81 + 82 + return USB_STOR_TRANSPORT_GOOD; 83 + } 84 + 85 + //----- MS_SCSI_Read_Capacity() -------------------------------------------------- 86 + int MS_SCSI_Read_Capacity(struct us_data *us, struct scsi_cmnd *srb) 87 + { 88 + unsigned int offset = 0; 89 + struct scatterlist *sg = NULL; 90 + DWORD bl_num; 91 + WORD bl_len; 92 + BYTE buf[8]; 93 + 94 + printk("MS_SCSI_Read_Capacity\n"); 95 + 96 + bl_len = 0x200; 97 + if ( us->MS_Status.IsMSPro ) 98 + bl_num = us->MSP_TotalBlock - 1; 99 + else 100 + bl_num = us->MS_Lib.NumberOfLogBlock * us->MS_Lib.blockSize * 2 - 1; 101 + 102 + us->bl_num = bl_num; 103 + printk("bl_len = %x\n", bl_len); 104 + printk("bl_num = %x\n", bl_num); 105 + 106 + //srb->request_bufflen = 8; 107 + buf[0] = (bl_num>>24) & 0xff; 108 + buf[1] = (bl_num>>16) & 0xff; 109 + buf[2] = (bl_num>> 8) & 0xff; 110 + buf[3] = (bl_num>> 0) & 0xff; 111 + buf[4] = (bl_len>>24) & 0xff; 112 + buf[5] = (bl_len>>16) & 0xff; 113 + buf[6] = (bl_len>> 8) & 0xff; 114 + buf[7] = (bl_len>> 0) & 0xff; 115 + 116 + usb_stor_access_xfer_buf(us, buf, 8, srb, &sg, &offset, TO_XFER_BUF); 117 + //usb_stor_set_xfer_buf(us, buf, srb->request_bufflen, srb, TO_XFER_BUF); 118 + 119 + return USB_STOR_TRANSPORT_GOOD; 120 + } 121 + 122 + //----- MS_SCSI_Read() -------------------------------------------------- 123 + int MS_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb) 124 + { 125 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 126 + int result=0; 127 + PBYTE Cdb = srb->cmnd; 128 + DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) | 129 + ((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff); 130 + WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff); 131 + DWORD blenByte = blen * 0x200; 132 + 133 + //printk("SCSIOP_READ --- bn = %X, blen = %X, srb->use_sg = %X\n", bn, blen, srb->use_sg); 134 + 135 + if (bn > us->bl_num) 136 + return USB_STOR_TRANSPORT_ERROR; 137 + 138 + if (us->MS_Status.IsMSPro) 139 + { 140 + result = ENE_LoadBinCode(us, MSP_RW_PATTERN); 141 + if (result != USB_STOR_XFER_GOOD) 142 + { 143 + printk("Load MSP RW pattern Fail !!\n"); 144 + return USB_STOR_TRANSPORT_ERROR; 145 + } 146 + 147 + // set up the command wrapper 148 + memset(bcb, 0, sizeof(bcb)); 149 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 150 + bcb->DataTransferLength = blenByte; 151 + bcb->Flags = 0x80; 152 + bcb->CDB[0] = 0xF1; 153 + bcb->CDB[1] = 0x02; 154 + bcb->CDB[5] = (BYTE)(bn); 155 + bcb->CDB[4] = (BYTE)(bn>>8); 156 + bcb->CDB[3] = (BYTE)(bn>>16); 157 + bcb->CDB[2] = (BYTE)(bn>>24); 158 + 159 + result = ENE_SendScsiCmd(us, FDIR_READ, scsi_sglist(srb), 1); 160 + } 161 + else 162 + { 163 + void *buf; 164 + int offset=0; 165 + WORD phyblk, logblk; 166 + BYTE PageNum; 167 + WORD len; 168 + DWORD blkno; 169 + 170 + buf = kmalloc(blenByte, GFP_KERNEL); 171 + 172 + result = ENE_LoadBinCode(us, MS_RW_PATTERN); 173 + if (result != USB_STOR_XFER_GOOD) 174 + { 175 + printk("Load MS RW pattern Fail !!\n"); 176 + result = USB_STOR_TRANSPORT_ERROR; 177 + goto exit; 178 + } 179 + 180 + logblk = (WORD)(bn / us->MS_Lib.PagesPerBlock); 181 + PageNum = (BYTE)(bn % us->MS_Lib.PagesPerBlock); 182 + 183 + while(1) 184 + { 185 + if (blen > (us->MS_Lib.PagesPerBlock-PageNum) ) 186 + len = us->MS_Lib.PagesPerBlock-PageNum; 187 + else 188 + len = blen; 189 + 190 + phyblk = MS_LibConv2Physical(us, logblk); 191 + blkno = phyblk * 0x20 + PageNum; 192 + 193 + // set up the command wrapper 194 + memset(bcb, 0, sizeof(bcb)); 195 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 196 + bcb->DataTransferLength = 0x200 * len; 197 + bcb->Flags = 0x80; 198 + bcb->CDB[0] = 0xF1; 199 + bcb->CDB[1] = 0x02; 200 + bcb->CDB[5] = (BYTE)(blkno); 201 + bcb->CDB[4] = (BYTE)(blkno>>8); 202 + bcb->CDB[3] = (BYTE)(blkno>>16); 203 + bcb->CDB[2] = (BYTE)(blkno>>24); 204 + 205 + result = ENE_SendScsiCmd(us, FDIR_READ, buf+offset, 0); 206 + if (result != USB_STOR_XFER_GOOD) 207 + { 208 + printk("MS_SCSI_Read --- result = %x\n", result); 209 + result = USB_STOR_TRANSPORT_ERROR; 210 + goto exit; 211 + } 212 + 213 + blen -= len; 214 + if (blen<=0) 215 + break; 216 + logblk++; 217 + PageNum = 0; 218 + offset += MS_BYTES_PER_PAGE*len; 219 + } 220 + usb_stor_set_xfer_buf(us, buf, blenByte, srb, TO_XFER_BUF); 221 + exit: 222 + kfree(buf); 223 + } 224 + return result; 225 + } 226 + 227 + //----- MS_SCSI_Write() -------------------------------------------------- 228 + int MS_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb) 229 + { 230 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 231 + int result=0; 232 + PBYTE Cdb = srb->cmnd; 233 + DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) | 234 + ((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff); 235 + WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff); 236 + DWORD blenByte = blen * 0x200; 237 + 238 + if (bn > us->bl_num) 239 + return USB_STOR_TRANSPORT_ERROR; 240 + 241 + if (us->MS_Status.IsMSPro) 242 + { 243 + result = ENE_LoadBinCode(us, MSP_RW_PATTERN); 244 + if (result != USB_STOR_XFER_GOOD) 245 + { 246 + printk("Load MSP RW pattern Fail !!\n"); 247 + return USB_STOR_TRANSPORT_ERROR; 248 + } 249 + 250 + // set up the command wrapper 251 + memset(bcb, 0, sizeof(bcb)); 252 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 253 + bcb->DataTransferLength = blenByte; 254 + bcb->Flags = 0x00; 255 + bcb->CDB[0] = 0xF0; 256 + bcb->CDB[1] = 0x04; 257 + bcb->CDB[5] = (BYTE)(bn); 258 + bcb->CDB[4] = (BYTE)(bn>>8); 259 + bcb->CDB[3] = (BYTE)(bn>>16); 260 + bcb->CDB[2] = (BYTE)(bn>>24); 261 + 262 + result = ENE_SendScsiCmd(us, FDIR_WRITE, scsi_sglist(srb), 1); 263 + } 264 + else 265 + { 266 + void *buf; 267 + int offset=0; 268 + WORD PhyBlockAddr; 269 + BYTE PageNum; 270 + DWORD result; 271 + WORD len, oldphy, newphy; 272 + 273 + buf = kmalloc(blenByte, GFP_KERNEL); 274 + usb_stor_set_xfer_buf(us, buf, blenByte, srb, FROM_XFER_BUF); 275 + 276 + result = ENE_LoadBinCode(us, MS_RW_PATTERN); 277 + if (result != USB_STOR_XFER_GOOD) 278 + { 279 + printk("Load MS RW pattern Fail !!\n"); 280 + result = USB_STOR_TRANSPORT_ERROR; 281 + goto exit; 282 + } 283 + 284 + PhyBlockAddr = (WORD)(bn / us->MS_Lib.PagesPerBlock); 285 + PageNum = (BYTE)(bn % us->MS_Lib.PagesPerBlock); 286 + 287 + while(1) 288 + { 289 + if (blen > (us->MS_Lib.PagesPerBlock-PageNum) ) 290 + len = us->MS_Lib.PagesPerBlock-PageNum; 291 + else 292 + len = blen; 293 + 294 + oldphy = MS_LibConv2Physical(us, PhyBlockAddr); 295 + newphy = MS_LibSearchBlockFromLogical(us, PhyBlockAddr); 296 + 297 + result = MS_ReaderCopyBlock(us, oldphy, newphy, PhyBlockAddr, PageNum, buf+offset, len); 298 + if (result != USB_STOR_XFER_GOOD) 299 + { 300 + printk("MS_SCSI_Write --- result = %x\n", result); 301 + result = USB_STOR_TRANSPORT_ERROR; 302 + goto exit; 303 + } 304 + 305 + us->MS_Lib.Phy2LogMap[oldphy] = MS_LB_NOT_USED_ERASED; 306 + MS_LibForceSetLogicalPair(us, PhyBlockAddr, newphy); 307 + 308 + blen -= len; 309 + if (blen<=0) 310 + break; 311 + PhyBlockAddr++; 312 + PageNum = 0; 313 + offset += MS_BYTES_PER_PAGE*len; 314 + } 315 + exit: 316 + kfree(buf); 317 + } 318 + return result; 319 + } 320 +
+448
drivers/staging/keucr/scsiglue.c
··· 1 + #include <linux/slab.h> 2 + #include <linux/module.h> 3 + #include <linux/mutex.h> 4 + 5 + #include <scsi/scsi.h> 6 + #include <scsi/scsi_cmnd.h> 7 + #include <scsi/scsi_devinfo.h> 8 + #include <scsi/scsi_device.h> 9 + #include <scsi/scsi_eh.h> 10 + 11 + #include "usb.h" 12 + #include "scsiglue.h" 13 + #include "transport.h" 14 + 15 + /* Host functions */ 16 + //----- host_info() --------------------- 17 + static const char* host_info(struct Scsi_Host *host) 18 + { 19 + //printk("scsiglue --- host_info\n"); 20 + return "SCSI emulation for USB Mass Storage devices"; 21 + } 22 + 23 + //----- slave_alloc() --------------------- 24 + static int slave_alloc(struct scsi_device *sdev) 25 + { 26 + struct us_data *us = host_to_us(sdev->host); 27 + 28 + //printk("scsiglue --- slave_alloc\n"); 29 + sdev->inquiry_len = 36; 30 + 31 + blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1)); 32 + 33 + if (us->subclass == US_SC_UFI) 34 + sdev->sdev_target->pdt_1f_for_no_lun = 1; 35 + 36 + return 0; 37 + } 38 + 39 + //----- slave_configure() --------------------- 40 + static int slave_configure(struct scsi_device *sdev) 41 + { 42 + struct us_data *us = host_to_us(sdev->host); 43 + 44 + //printk("scsiglue --- slave_configure\n"); 45 + if (us->fflags & (US_FL_MAX_SECTORS_64 | US_FL_MAX_SECTORS_MIN)) 46 + { 47 + unsigned int max_sectors = 64; 48 + 49 + if (us->fflags & US_FL_MAX_SECTORS_MIN) 50 + max_sectors = PAGE_CACHE_SIZE >> 9; 51 + if (queue_max_sectors(sdev->request_queue) > max_sectors) 52 + blk_queue_max_hw_sectors(sdev->request_queue, 53 + max_sectors); 54 + } 55 + 56 + if (sdev->type == TYPE_DISK) 57 + { 58 + if (us->subclass != US_SC_SCSI && us->subclass != US_SC_CYP_ATACB) 59 + sdev->use_10_for_ms = 1; 60 + sdev->use_192_bytes_for_3f = 1; 61 + if (us->fflags & US_FL_NO_WP_DETECT) 62 + sdev->skip_ms_page_3f = 1; 63 + sdev->skip_ms_page_8 = 1; 64 + if (us->fflags & US_FL_FIX_CAPACITY) 65 + sdev->fix_capacity = 1; 66 + if (us->fflags & US_FL_CAPACITY_HEURISTICS) 67 + sdev->guess_capacity = 1; 68 + if (sdev->scsi_level > SCSI_2) 69 + sdev->sdev_target->scsi_level = sdev->scsi_level = SCSI_2; 70 + sdev->retry_hwerror = 1; 71 + sdev->allow_restart = 1; 72 + sdev->last_sector_bug = 1; 73 + } 74 + else 75 + { 76 + sdev->use_10_for_ms = 1; 77 + } 78 + 79 + if ((us->protocol == US_PR_CB || us->protocol == US_PR_CBI) && sdev->scsi_level == SCSI_UNKNOWN) 80 + us->max_lun = 0; 81 + 82 + if (us->fflags & US_FL_NOT_LOCKABLE) 83 + sdev->lockable = 0; 84 + 85 + return 0; 86 + } 87 + 88 + /* This is always called with scsi_lock(host) held */ 89 + //----- queuecommand() --------------------- 90 + static int queuecommand(struct scsi_cmnd *srb, void (*done)(struct scsi_cmnd *)) 91 + { 92 + struct us_data *us = host_to_us(srb->device->host); 93 + 94 + //printk("scsiglue --- queuecommand\n"); 95 + 96 + /* check for state-transition errors */ 97 + if (us->srb != NULL) 98 + { 99 + printk("Error in %s: us->srb = %p\n", __FUNCTION__, us->srb); 100 + return SCSI_MLQUEUE_HOST_BUSY; 101 + } 102 + 103 + /* fail the command if we are disconnecting */ 104 + if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) 105 + { 106 + printk("Fail command during disconnect\n"); 107 + srb->result = DID_NO_CONNECT << 16; 108 + done(srb); 109 + return 0; 110 + } 111 + 112 + /* enqueue the command and wake up the control thread */ 113 + srb->scsi_done = done; 114 + us->srb = srb; 115 + complete(&us->cmnd_ready); 116 + 117 + return 0; 118 + } 119 + 120 + /*********************************************************************** 121 + * Error handling functions 122 + ***********************************************************************/ 123 + 124 + /* Command timeout and abort */ 125 + //----- command_abort() --------------------- 126 + static int command_abort(struct scsi_cmnd *srb) 127 + { 128 + struct us_data *us = host_to_us(srb->device->host); 129 + 130 + //printk("scsiglue --- command_abort\n"); 131 + 132 + scsi_lock(us_to_host(us)); 133 + if (us->srb != srb) 134 + { 135 + scsi_unlock(us_to_host(us)); 136 + printk ("-- nothing to abort\n"); 137 + return FAILED; 138 + } 139 + 140 + set_bit(US_FLIDX_TIMED_OUT, &us->dflags); 141 + if (!test_bit(US_FLIDX_RESETTING, &us->dflags)) 142 + { 143 + set_bit(US_FLIDX_ABORTING, &us->dflags); 144 + usb_stor_stop_transport(us); 145 + } 146 + scsi_unlock(us_to_host(us)); 147 + 148 + /* Wait for the aborted command to finish */ 149 + wait_for_completion(&us->notify); 150 + return SUCCESS; 151 + } 152 + 153 + /* This invokes the transport reset mechanism to reset the state of the device */ 154 + //----- device_reset() --------------------- 155 + static int device_reset(struct scsi_cmnd *srb) 156 + { 157 + struct us_data *us = host_to_us(srb->device->host); 158 + int result; 159 + 160 + //printk("scsiglue --- device_reset\n"); 161 + 162 + /* lock the device pointers and do the reset */ 163 + mutex_lock(&(us->dev_mutex)); 164 + result = us->transport_reset(us); 165 + mutex_unlock(&us->dev_mutex); 166 + 167 + return result < 0 ? FAILED : SUCCESS; 168 + } 169 + 170 + //----- bus_reset() --------------------- 171 + static int bus_reset(struct scsi_cmnd *srb) 172 + { 173 + struct us_data *us = host_to_us(srb->device->host); 174 + int result; 175 + 176 + //printk("scsiglue --- bus_reset\n"); 177 + result = usb_stor_port_reset(us); 178 + return result < 0 ? FAILED : SUCCESS; 179 + } 180 + 181 + //----- usb_stor_report_device_reset() --------------------- 182 + void usb_stor_report_device_reset(struct us_data *us) 183 + { 184 + int i; 185 + struct Scsi_Host *host = us_to_host(us); 186 + 187 + //printk("scsiglue --- usb_stor_report_device_reset\n"); 188 + scsi_report_device_reset(host, 0, 0); 189 + if (us->fflags & US_FL_SCM_MULT_TARG) 190 + { 191 + for (i = 1; i < host->max_id; ++i) 192 + scsi_report_device_reset(host, 0, i); 193 + } 194 + } 195 + 196 + //----- usb_stor_report_bus_reset() --------------------- 197 + void usb_stor_report_bus_reset(struct us_data *us) 198 + { 199 + struct Scsi_Host *host = us_to_host(us); 200 + 201 + //printk("scsiglue --- usb_stor_report_bus_reset\n"); 202 + scsi_lock(host); 203 + scsi_report_bus_reset(host, 0); 204 + scsi_unlock(host); 205 + } 206 + 207 + /*********************************************************************** 208 + * /proc/scsi/ functions 209 + ***********************************************************************/ 210 + 211 + /* we use this macro to help us write into the buffer */ 212 + #undef SPRINTF 213 + #define SPRINTF(args...) \ 214 + do { if (pos < buffer+length) pos += sprintf(pos, ## args); } while (0) 215 + 216 + //----- proc_info() --------------------- 217 + static int proc_info (struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length, int inout) 218 + { 219 + struct us_data *us = host_to_us(host); 220 + char *pos = buffer; 221 + const char *string; 222 + 223 + //printk("scsiglue --- proc_info\n"); 224 + if (inout) 225 + return length; 226 + 227 + /* print the controller name */ 228 + SPRINTF(" Host scsi%d: usb-storage\n", host->host_no); 229 + 230 + /* print product, vendor, and serial number strings */ 231 + if (us->pusb_dev->manufacturer) 232 + string = us->pusb_dev->manufacturer; 233 + else if (us->unusual_dev->vendorName) 234 + string = us->unusual_dev->vendorName; 235 + else 236 + string = "Unknown"; 237 + SPRINTF(" Vendor: %s\n", string); 238 + if (us->pusb_dev->product) 239 + string = us->pusb_dev->product; 240 + else if (us->unusual_dev->productName) 241 + string = us->unusual_dev->productName; 242 + else 243 + string = "Unknown"; 244 + SPRINTF(" Product: %s\n", string); 245 + if (us->pusb_dev->serial) 246 + string = us->pusb_dev->serial; 247 + else 248 + string = "None"; 249 + SPRINTF("Serial Number: %s\n", string); 250 + 251 + /* show the protocol and transport */ 252 + SPRINTF(" Protocol: %s\n", us->protocol_name); 253 + SPRINTF(" Transport: %s\n", us->transport_name); 254 + 255 + /* show the device flags */ 256 + if (pos < buffer + length) 257 + { 258 + pos += sprintf(pos, " Quirks:"); 259 + 260 + #define US_FLAG(name, value) \ 261 + if (us->fflags & value) pos += sprintf(pos, " " #name); 262 + US_DO_ALL_FLAGS 263 + #undef US_FLAG 264 + 265 + *(pos++) = '\n'; 266 + } 267 + 268 + /* Calculate start of next buffer, and return value. */ 269 + *start = buffer + offset; 270 + 271 + if ((pos - buffer) < offset) 272 + return (0); 273 + else if ((pos - buffer - offset) < length) 274 + return (pos - buffer - offset); 275 + else 276 + return (length); 277 + } 278 + 279 + /*********************************************************************** 280 + * Sysfs interface 281 + ***********************************************************************/ 282 + 283 + /* Output routine for the sysfs max_sectors file */ 284 + //----- show_max_sectors() --------------------- 285 + static ssize_t show_max_sectors(struct device *dev, struct device_attribute *attr, char *buf) 286 + { 287 + struct scsi_device *sdev = to_scsi_device(dev); 288 + 289 + //printk("scsiglue --- ssize_t show_max_sectors\n"); 290 + return sprintf(buf, "%u\n", queue_max_sectors(sdev->request_queue)); 291 + } 292 + 293 + /* Input routine for the sysfs max_sectors file */ 294 + //----- store_max_sectors() --------------------- 295 + static ssize_t store_max_sectors(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 296 + { 297 + struct scsi_device *sdev = to_scsi_device(dev); 298 + unsigned short ms; 299 + 300 + //printk("scsiglue --- ssize_t store_max_sectors\n"); 301 + if (sscanf(buf, "%hu", &ms) > 0 && ms <= SCSI_DEFAULT_MAX_SECTORS) 302 + { 303 + blk_queue_max_hw_sectors(sdev->request_queue, ms); 304 + return strlen(buf); 305 + } 306 + return -EINVAL; 307 + } 308 + 309 + static DEVICE_ATTR(max_sectors, S_IRUGO | S_IWUSR, show_max_sectors, store_max_sectors); 310 + static struct device_attribute *sysfs_device_attr_list[] = {&dev_attr_max_sectors, NULL, }; 311 + 312 + /* this defines our host template, with which we'll allocate hosts */ 313 + 314 + //----- usb_stor_host_template() --------------------- 315 + struct scsi_host_template usb_stor_host_template = { 316 + /* basic userland interface stuff */ 317 + .name = "eucr-storage", 318 + .proc_name = "eucr-storage", 319 + .proc_info = proc_info, 320 + .info = host_info, 321 + 322 + /* command interface -- queued only */ 323 + .queuecommand = queuecommand, 324 + 325 + /* error and abort handlers */ 326 + .eh_abort_handler = command_abort, 327 + .eh_device_reset_handler = device_reset, 328 + .eh_bus_reset_handler = bus_reset, 329 + 330 + /* queue commands only, only one command per LUN */ 331 + .can_queue = 1, 332 + .cmd_per_lun = 1, 333 + 334 + /* unknown initiator id */ 335 + .this_id = -1, 336 + 337 + .slave_alloc = slave_alloc, 338 + .slave_configure = slave_configure, 339 + 340 + /* lots of sg segments can be handled */ 341 + .sg_tablesize = SG_ALL, 342 + 343 + /* limit the total size of a transfer to 120 KB */ 344 + .max_sectors = 240, 345 + 346 + /* merge commands... this seems to help performance, but 347 + * periodically someone should test to see which setting is more 348 + * optimal. 349 + */ 350 + .use_clustering = 1, 351 + 352 + /* emulated HBA */ 353 + .emulated = 1, 354 + 355 + /* we do our own delay after a device or bus reset */ 356 + .skip_settle_delay = 1, 357 + 358 + /* sysfs device attributes */ 359 + .sdev_attrs = sysfs_device_attr_list, 360 + 361 + /* module management */ 362 + .module = THIS_MODULE 363 + }; 364 + 365 + /* To Report "Illegal Request: Invalid Field in CDB */ 366 + unsigned char usb_stor_sense_invalidCDB[18] = { 367 + [0] = 0x70, /* current error */ 368 + [2] = ILLEGAL_REQUEST, /* Illegal Request = 0x05 */ 369 + [7] = 0x0a, /* additional length */ 370 + [12] = 0x24 /* Invalid Field in CDB */ 371 + }; 372 + 373 + /*********************************************************************** 374 + * Scatter-gather transfer buffer access routines 375 + ***********************************************************************/ 376 + 377 + //----- usb_stor_access_xfer_buf() --------------------- 378 + unsigned int usb_stor_access_xfer_buf(struct us_data *us, unsigned char *buffer, 379 + unsigned int buflen, struct scsi_cmnd *srb, struct scatterlist **sgptr, 380 + unsigned int *offset, enum xfer_buf_dir dir) 381 + { 382 + unsigned int cnt; 383 + 384 + //printk("transport --- usb_stor_access_xfer_buf\n"); 385 + struct scatterlist *sg = *sgptr; 386 + 387 + if (!sg) 388 + sg = scsi_sglist(srb); 389 + 390 + cnt = 0; 391 + while (cnt < buflen && sg) 392 + { 393 + struct page *page = sg_page(sg) + ((sg->offset + *offset) >> PAGE_SHIFT); 394 + unsigned int poff = (sg->offset + *offset) & (PAGE_SIZE-1); 395 + unsigned int sglen = sg->length - *offset; 396 + 397 + if (sglen > buflen - cnt) 398 + { 399 + /* Transfer ends within this s-g entry */ 400 + sglen = buflen - cnt; 401 + *offset += sglen; 402 + } 403 + else 404 + { 405 + /* Transfer continues to next s-g entry */ 406 + *offset = 0; 407 + sg = sg_next(sg); 408 + } 409 + 410 + while (sglen > 0) 411 + { 412 + unsigned int plen = min(sglen, (unsigned int)PAGE_SIZE - poff); 413 + unsigned char *ptr = kmap(page); 414 + 415 + if (dir == TO_XFER_BUF) 416 + memcpy(ptr + poff, buffer + cnt, plen); 417 + else 418 + memcpy(buffer + cnt, ptr + poff, plen); 419 + kunmap(page); 420 + 421 + /* Start at the beginning of the next page */ 422 + poff = 0; 423 + ++page; 424 + cnt += plen; 425 + sglen -= plen; 426 + } 427 + } 428 + *sgptr = sg; 429 + 430 + /* Return the amount actually transferred */ 431 + return cnt; 432 + } 433 + 434 + /* Store the contents of buffer into srb's transfer buffer and set the SCSI residue. */ 435 + //----- usb_stor_set_xfer_buf() --------------------- 436 + void usb_stor_set_xfer_buf(struct us_data *us, unsigned char *buffer, unsigned int buflen, struct scsi_cmnd *srb, 437 + unsigned int dir) 438 + { 439 + unsigned int offset = 0; 440 + struct scatterlist *sg = NULL; 441 + 442 + //printk("transport --- usb_stor_set_xfer_buf\n"); 443 + // TO_XFER_BUF = 0, FROM_XFER_BUF = 1 444 + buflen = min(buflen, scsi_bufflen(srb)); 445 + buflen = usb_stor_access_xfer_buf(us, buffer, buflen, srb, &sg, &offset, dir); 446 + if (buflen < scsi_bufflen(srb)) 447 + scsi_set_resid(srb, scsi_bufflen(srb) - buflen); 448 + }
+10
drivers/staging/keucr/scsiglue.h
··· 1 + #ifndef _SCSIGLUE_H_ 2 + #define _SCSIGLUE_H_ 3 + 4 + extern void usb_stor_report_device_reset(struct us_data *us); 5 + extern void usb_stor_report_bus_reset(struct us_data *us); 6 + 7 + extern unsigned char usb_stor_sense_invalidCDB[18]; 8 + extern struct scsi_host_template usb_stor_host_template; 9 + 10 + #endif
+210
drivers/staging/keucr/sdscsi.c
··· 1 + #include <linux/sched.h> 2 + #include <linux/errno.h> 3 + #include <linux/slab.h> 4 + 5 + #include <scsi/scsi.h> 6 + #include <scsi/scsi_eh.h> 7 + #include <scsi/scsi_device.h> 8 + 9 + #include "usb.h" 10 + #include "scsiglue.h" 11 + #include "transport.h" 12 + 13 + int SD_SCSI_Test_Unit_Ready (struct us_data *us, struct scsi_cmnd *srb); 14 + int SD_SCSI_Inquiry (struct us_data *us, struct scsi_cmnd *srb); 15 + int SD_SCSI_Mode_Sense (struct us_data *us, struct scsi_cmnd *srb); 16 + int SD_SCSI_Start_Stop (struct us_data *us, struct scsi_cmnd *srb); 17 + int SD_SCSI_Read_Capacity (struct us_data *us, struct scsi_cmnd *srb); 18 + int SD_SCSI_Read (struct us_data *us, struct scsi_cmnd *srb); 19 + int SD_SCSI_Write (struct us_data *us, struct scsi_cmnd *srb); 20 + 21 + //----- SD_SCSIIrp() -------------------------------------------------- 22 + int SD_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb) 23 + { 24 + int result; 25 + 26 + us->SrbStatus = SS_SUCCESS; 27 + switch (srb->cmnd[0]) 28 + { 29 + case TEST_UNIT_READY : result = SD_SCSI_Test_Unit_Ready (us, srb); break; //0x00 30 + case INQUIRY : result = SD_SCSI_Inquiry (us, srb); break; //0x12 31 + case MODE_SENSE : result = SD_SCSI_Mode_Sense (us, srb); break; //0x1A 32 + // case START_STOP : result = SD_SCSI_Start_Stop (us, srb); break; //0x1B 33 + case READ_CAPACITY : result = SD_SCSI_Read_Capacity (us, srb); break; //0x25 34 + case READ_10 : result = SD_SCSI_Read (us, srb); break; //0x28 35 + case WRITE_10 : result = SD_SCSI_Write (us, srb); break; //0x2A 36 + 37 + default: 38 + us->SrbStatus = SS_ILLEGAL_REQUEST; 39 + result = USB_STOR_TRANSPORT_FAILED; 40 + break; 41 + } 42 + return result; 43 + } 44 + 45 + //----- SD_SCSI_Test_Unit_Ready() -------------------------------------------------- 46 + int SD_SCSI_Test_Unit_Ready(struct us_data *us, struct scsi_cmnd *srb) 47 + { 48 + //printk("SD_SCSI_Test_Unit_Ready\n"); 49 + if (us->SD_Status.Insert && us->SD_Status.Ready) 50 + return USB_STOR_TRANSPORT_GOOD; 51 + else 52 + { 53 + ENE_SDInit(us); 54 + return USB_STOR_TRANSPORT_GOOD; 55 + } 56 + 57 + return USB_STOR_TRANSPORT_GOOD; 58 + } 59 + 60 + //----- SD_SCSI_Inquiry() -------------------------------------------------- 61 + int SD_SCSI_Inquiry(struct us_data *us, struct scsi_cmnd *srb) 62 + { 63 + //printk("SD_SCSI_Inquiry\n"); 64 + BYTE data_ptr[36] = {0x00, 0x80, 0x02, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x55, 0x53, 0x42, 0x32, 0x2E, 0x30, 0x20, 0x20, 0x43, 0x61, 0x72, 0x64, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x30, 0x30}; 65 + 66 + usb_stor_set_xfer_buf(us, data_ptr, 36, srb, TO_XFER_BUF); 67 + return USB_STOR_TRANSPORT_GOOD; 68 + } 69 + 70 + 71 + //----- SD_SCSI_Mode_Sense() -------------------------------------------------- 72 + int SD_SCSI_Mode_Sense(struct us_data *us, struct scsi_cmnd *srb) 73 + { 74 + BYTE mediaNoWP[12] = {0x0b,0x00,0x00,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00}; 75 + BYTE mediaWP[12] = {0x0b,0x00,0x80,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00}; 76 + 77 + if (us->SD_Status.WtP) 78 + usb_stor_set_xfer_buf(us, mediaWP, 12, srb, TO_XFER_BUF); 79 + else 80 + usb_stor_set_xfer_buf(us, mediaNoWP, 12, srb, TO_XFER_BUF); 81 + 82 + 83 + return USB_STOR_TRANSPORT_GOOD; 84 + } 85 + 86 + //----- SD_SCSI_Read_Capacity() -------------------------------------------------- 87 + int SD_SCSI_Read_Capacity(struct us_data *us, struct scsi_cmnd *srb) 88 + { 89 + unsigned int offset = 0; 90 + struct scatterlist *sg = NULL; 91 + DWORD bl_num; 92 + WORD bl_len; 93 + BYTE buf[8]; 94 + 95 + printk("SD_SCSI_Read_Capacity\n"); 96 + if ( us->SD_Status.HiCapacity ) 97 + { 98 + bl_len = 0x200; 99 + if (us->SD_Status.IsMMC) 100 + bl_num = us->HC_C_SIZE-1; 101 + else 102 + bl_num = (us->HC_C_SIZE + 1) * 1024 - 1; 103 + } 104 + else 105 + { 106 + bl_len = 1<<(us->SD_READ_BL_LEN); 107 + bl_num = us->SD_Block_Mult*(us->SD_C_SIZE+1)*(1<<(us->SD_C_SIZE_MULT+2)) - 1; 108 + } 109 + us->bl_num = bl_num; 110 + printk("bl_len = %x\n", bl_len); 111 + printk("bl_num = %x\n", bl_num); 112 + 113 + //srb->request_bufflen = 8; 114 + buf[0] = (bl_num>>24) & 0xff; 115 + buf[1] = (bl_num>>16) & 0xff; 116 + buf[2] = (bl_num>> 8) & 0xff; 117 + buf[3] = (bl_num>> 0) & 0xff; 118 + buf[4] = (bl_len>>24) & 0xff; 119 + buf[5] = (bl_len>>16) & 0xff; 120 + buf[6] = (bl_len>> 8) & 0xff; 121 + buf[7] = (bl_len>> 0) & 0xff; 122 + 123 + usb_stor_access_xfer_buf(us, buf, 8, srb, &sg, &offset, TO_XFER_BUF); 124 + //usb_stor_set_xfer_buf(us, buf, srb->request_bufflen, srb, TO_XFER_BUF); 125 + 126 + return USB_STOR_TRANSPORT_GOOD; 127 + } 128 + 129 + //----- SD_SCSI_Read() -------------------------------------------------- 130 + int SD_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb) 131 + { 132 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 133 + int result; 134 + PBYTE Cdb = srb->cmnd; 135 + DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) | 136 + ((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff); 137 + WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff); 138 + DWORD bnByte = bn * 0x200; 139 + DWORD blenByte = blen * 0x200; 140 + 141 + if (bn > us->bl_num) 142 + return USB_STOR_TRANSPORT_ERROR; 143 + 144 + result = ENE_LoadBinCode(us, SD_RW_PATTERN); 145 + if (result != USB_STOR_XFER_GOOD) 146 + { 147 + printk("Load SD RW pattern Fail !!\n"); 148 + return USB_STOR_TRANSPORT_ERROR; 149 + } 150 + 151 + if ( us->SD_Status.HiCapacity ) 152 + bnByte = bn; 153 + 154 + // set up the command wrapper 155 + memset(bcb, 0, sizeof(bcb)); 156 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 157 + bcb->DataTransferLength = blenByte; 158 + bcb->Flags = 0x80; 159 + bcb->CDB[0] = 0xF1; 160 + bcb->CDB[5] = (BYTE)(bnByte); 161 + bcb->CDB[4] = (BYTE)(bnByte>>8); 162 + bcb->CDB[3] = (BYTE)(bnByte>>16); 163 + bcb->CDB[2] = (BYTE)(bnByte>>24); 164 + 165 + result = ENE_SendScsiCmd(us, FDIR_READ, scsi_sglist(srb), 1); 166 + return result; 167 + } 168 + 169 + //----- SD_SCSI_Write() -------------------------------------------------- 170 + int SD_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb) 171 + { 172 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 173 + int result; 174 + PBYTE Cdb = srb->cmnd; 175 + DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) | 176 + ((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff); 177 + WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff); 178 + DWORD bnByte = bn * 0x200; 179 + DWORD blenByte = blen * 0x200; 180 + 181 + if (bn > us->bl_num) 182 + return USB_STOR_TRANSPORT_ERROR; 183 + 184 + result = ENE_LoadBinCode(us, SD_RW_PATTERN); 185 + if (result != USB_STOR_XFER_GOOD) 186 + { 187 + printk("Load SD RW pattern Fail !!\n"); 188 + return USB_STOR_TRANSPORT_ERROR; 189 + } 190 + 191 + if ( us->SD_Status.HiCapacity ) 192 + bnByte = bn; 193 + 194 + // set up the command wrapper 195 + memset(bcb, 0, sizeof(bcb)); 196 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 197 + bcb->DataTransferLength = blenByte; 198 + bcb->Flags = 0x00; 199 + bcb->CDB[0] = 0xF0; 200 + bcb->CDB[5] = (BYTE)(bnByte); 201 + bcb->CDB[4] = (BYTE)(bnByte>>8); 202 + bcb->CDB[3] = (BYTE)(bnByte>>16); 203 + bcb->CDB[2] = (BYTE)(bnByte>>24); 204 + 205 + result = ENE_SendScsiCmd(us, FDIR_WRITE, scsi_sglist(srb), 1); 206 + return result; 207 + } 208 + 209 + 210 +
+40
drivers/staging/keucr/smcommon.h
··· 1 + //----- < SMCommon.h> -------------------------------------------------- 2 + #ifndef SMCOMMON_INCD 3 + #define SMCOMMON_INCD 4 + 5 + 6 + /*************************************************************************** 7 + Define Difinetion 8 + ***************************************************************************/ 9 + #define SUCCESS 0x0000 /* SUCCESS */ 10 + #define ERROR 0xFFFF /* ERROR */ 11 + #define CORRECT 0x0001 /* CORRECTABLE */ 12 + 13 + /***************************************************************************/ 14 + #define NO_ERROR 0x0000 /* NO ERROR */ 15 + #define ERR_WriteFault 0x0003 /* Peripheral Device Write Fault */ 16 + #define ERR_HwError 0x0004 /* Hardware Error */ 17 + #define ERR_DataStatus 0x0010 /* DataStatus Error */ 18 + #define ERR_EccReadErr 0x0011 /* Unrecovered Read Error */ 19 + #define ERR_CorReadErr 0x0018 /* Recovered Read Data with ECC */ 20 + #define ERR_OutOfLBA 0x0021 /* Illegal Logical Block Address */ 21 + #define ERR_WrtProtect 0x0027 /* Write Protected */ 22 + #define ERR_ChangedMedia 0x0028 /* Medium Changed */ 23 + #define ERR_UnknownMedia 0x0030 /* Incompatible Medium Installed */ 24 + #define ERR_IllegalFmt 0x0031 /* Medium Format Corrupted */ 25 + #define ERR_NoSmartMedia 0x003A /* Medium Not Present */ 26 + 27 + 28 + 29 + /***************************************************************************/ 30 + //#define SUCCESS 0 /* SUCCESS */ 31 + //#define ERROR -1 /* ERROR */ 32 + 33 + /***************************************************************************/ 34 + char Bit_D_Count (BYTE); 35 + char Bit_D_CountWord (WORD); 36 + void StringCopy (char *, char *, int); 37 + int StringCmp (char *, char *, int); 38 + 39 + 40 + #endif // already included
+289
drivers/staging/keucr/smil.h
··· 1 + //----- < smil.h> ---------------------------------------------------- 2 + #ifndef SMIL_INCD 3 + #define SMIL_INCD 4 + 5 + /*************************************************************************** 6 + Define Definition 7 + ***************************************************************************/ 8 + #define K_BYTE 1024 /* Kilo Byte */ 9 + #define SECTSIZE 512 /* Sector buffer size */ 10 + #define REDTSIZE 16 /* Redundant buffer size */ 11 + 12 + /***************************************************************************/ 13 + #define DUMMY_DATA 0xFF /* No Assign Sector Read Data */ 14 + 15 + /*************************************************************************** 16 + Max Zone/Block/Sectors Data Definition 17 + ***************************************************************************/ 18 + #define MAX_ZONENUM 128 /* Max Zone Numbers in a SmartMedia */ 19 + #define MAX_BLOCKNUM 0x0400 /* Max Block Numbers in a Zone */ 20 + #define MAX_SECTNUM 0x20 /* Max Sector Numbers in a Block */ 21 + #define MAX_LOGBLOCK 1000 /* Max Logical Block Numbers in a Zone */ 22 + 23 + /***************************************************************************/ 24 + #define CIS_SEARCH_SECT 0x08 /* Max CIS Search Sector Number */ 25 + 26 + /*************************************************************************** 27 + Logical to Physical Block Table Data Definition 28 + ***************************************************************************/ 29 + #define NO_ASSIGN 0xFFFF /* No Assign Logical Block Address */ 30 + 31 + /*************************************************************************** 32 + 'SectCopyMode' Data 33 + ***************************************************************************/ 34 + #define COMPLETED 0 /* Sector Copy Completed */ 35 + #define REQ_ERASE 1 /* Request Read Block Erase */ 36 + #define REQ_FAIL 2 /* Request Read Block Failed */ 37 + 38 + /*************************************************************************** 39 + Retry Counter Definition 40 + ***************************************************************************/ 41 + #define RDERR_REASSIGN 1 /* Reassign with Read Error */ 42 + #define L2P_ERR_ERASE 1 /* BlockErase for Contradicted L2P Table */ 43 + 44 + /*************************************************************************** 45 + Hardware ECC Definition 46 + ***************************************************************************/ 47 + #define HW_ECC_SUPPORTED 1 /* Hardware ECC Supported */ /* No difinition for Software ECC */ 48 + 49 + /*************************************************************************** 50 + SmartMedia Command & Status Definition 51 + ***************************************************************************/ 52 + /* SmartMedia Command */ 53 + #define WRDATA 0x80 54 + //#define READ 0x00 55 + #define READ_REDT 0x50 56 + //#define WRITE 0x10 57 + #define RDSTATUS 0x70 58 + 59 + #define READ1 0x00 //NO 60 + #define READ2 0x01 //NO 61 + #define READ3 0x50 //NO 62 + #define RST_CHIP 0xFF 63 + #define ERASE1 0x60 64 + #define ERASE2 0xD0 65 + #define READ_ID_1 0x90 66 + #define READ_ID_2 0x91 67 + #define READ_ID_3 0x9A 68 + 69 + /* 712 SmartMedia Command */ 70 + #define SM_CMD_RESET 0x00 // 0xFF 71 + #define SM_CMD_READ_ID_1 0x10 // 0x90 72 + #define SM_CMD_READ_ID_2 0x20 // 0x91 73 + #define SM_CMD_READ_STAT 0x30 // 0x70 74 + #define SM_CMD_RDMULTPL_STAT 0x40 // 0x71 75 + #define SM_CMD_READ_1 0x50 // 0x00 76 + #define SM_CMD_READ_2 0x60 // 0x01 77 + #define SM_CMD_READ_3 0x70 // 0x50 78 + #define SM_CMD_PAGPRGM_TRUE 0x80 // {0x80, 0x10} 79 + #define SM_CMD_PAGPRGM_DUMY 0x90 // {0x80, 0x11} 80 + #define SM_CMD_PAGPRGM_MBLK 0xA0 // {0x80, 0x15} 81 + #define SM_CMD_BLKERASE 0xB0 // {0x60, 0xD0} 82 + #define SM_CMD_BLKERASE_MULTPL 0xC0 // {0x60-0x60, 0xD0} 83 + 84 + #define SM_CRADDTCT_DEBNCETIMER_EN 0x02 85 + #define SM_CMD_START_BIT 0x01 86 + 87 + #define SM_WaitCmdDone { while (!SM_CmdDone); } 88 + #define SM_WaitDmaDone { while (!SM_DmaDone); } 89 + 90 + // SmartMedia Status 91 + #define WR_FAIL 0x01 // 0:Pass, 1:Fail 92 + #define SUSPENDED 0x20 // 0:Not Suspended, 1:Suspended 93 + #define READY 0x40 // 0:Busy, 1:Ready 94 + #define WR_PRTCT 0x80 // 0:Protect, 1:Not Protect 95 + 96 + // SmartMedia Busy Time (1bit:0.1ms) 97 + #define BUSY_PROG 200 // tPROG : 20ms ----- Program Time old : 200 98 + #define BUSY_ERASE 4000 // tBERASE : 400ms ----- Block Erase Time old : 4000 99 + //for 712 Test 100 + //#define BUSY_READ 1 // tR : 100us ----- Data transfer Time old : 1 101 + //#define BUSY_READ 10 // tR : 100us ----- Data transfer Time old : 1 102 + #define BUSY_READ 200 // tR : 20ms ----- Data transfer Time old : 1 103 + //#define BUSY_RESET 60 // tRST : 6ms ----- Device Resetting Time old : 60 104 + #define BUSY_RESET 600 // tRST : 60ms ----- Device Resetting Time old : 60 105 + 106 + // Hardware Timer (1bit:0.1ms) 107 + #define TIME_PON 3000 // 300ms ------ Power On Wait Time 108 + #define TIME_CDCHK 200 // 20ms ------ Card Check Interval Timer 109 + #define TIME_WPCHK 50 // 5ms ------ WP Check Interval Timer 110 + #define TIME_5VCHK 10 // 1ms ------ 5V Check Interval Timer 111 + 112 + /*************************************************************************** 113 + Redundant Data 114 + ***************************************************************************/ 115 + #define REDT_DATA 0x04 116 + #define REDT_BLOCK 0x05 117 + #define REDT_ADDR1H 0x06 118 + #define REDT_ADDR1L 0x07 119 + #define REDT_ADDR2H 0x0B 120 + #define REDT_ADDR2L 0x0C 121 + #define REDT_ECC10 0x0D 122 + #define REDT_ECC11 0x0E 123 + #define REDT_ECC12 0x0F 124 + #define REDT_ECC20 0x08 125 + #define REDT_ECC21 0x09 126 + #define REDT_ECC22 0x0A 127 + 128 + /*************************************************************************** 129 + SmartMedia Model & Attribute 130 + ***************************************************************************/ 131 + /* SmartMedia Attribute */ 132 + #define NOWP 0x00 // 0... .... No Write Protect 133 + #define WP 0x80 // 1... .... Write Protected 134 + #define MASK 0x00 // .00. .... NAND MASK ROM Model 135 + #define FLASH 0x20 // .01. .... NAND Flash ROM Model 136 + #define AD3CYC 0x00 // ...0 .... Address 3-cycle 137 + #define AD4CYC 0x10 // ...1 .... Address 4-cycle 138 + #define BS16 0x00 // .... 00.. 16page/block 139 + #define BS32 0x04 // .... 01.. 32page/block 140 + #define PS256 0x00 // .... ..00 256byte/page 141 + #define PS512 0x01 // .... ..01 512byte/page 142 + #define MWP 0x80 // WriteProtect mask 143 + #define MFLASH 0x60 // Flash Rom mask 144 + #define MADC 0x10 // Address Cycle 145 + #define MBS 0x0C // BlockSize mask 146 + #define MPS 0x03 // PageSize mask 147 + 148 + /* SmartMedia Model */ 149 + #define NOSSFDC 0x00 // NO SmartMedia 150 + #define SSFDC1MB 0x01 // 1MB SmartMedia 151 + #define SSFDC2MB 0x02 // 2MB SmartMedia 152 + #define SSFDC4MB 0x03 // 4MB SmartMedia 153 + #define SSFDC8MB 0x04 // 8MB SmartMedia 154 + #define SSFDC16MB 0x05 // 16MB SmartMedia 155 + #define SSFDC32MB 0x06 // 32MB SmartMedia 156 + #define SSFDC64MB 0x07 // 64MB SmartMedia 157 + #define SSFDC128MB 0x08 //128MB SmartMedia 158 + #define SSFDC256MB 0x09 159 + #define SSFDC512MB 0x0A 160 + #define SSFDC1GB 0x0B 161 + #define SSFDC2GB 0x0C 162 + 163 + /*************************************************************************** 164 + Struct Definition 165 + ***************************************************************************/ 166 + struct SSFDCTYPE 167 + { 168 + BYTE Model; 169 + BYTE Attribute; 170 + BYTE MaxZones; 171 + BYTE MaxSectors; 172 + WORD MaxBlocks; 173 + WORD MaxLogBlocks; 174 + }; 175 + 176 + typedef struct SSFDCTYPE_T 177 + { 178 + BYTE Model; 179 + BYTE Attribute; 180 + BYTE MaxZones; 181 + BYTE MaxSectors; 182 + WORD MaxBlocks; 183 + WORD MaxLogBlocks; 184 + } *SSFDCTYPE_T; 185 + 186 + struct ADDRESS 187 + { 188 + BYTE Zone; /* Zone Number */ 189 + BYTE Sector; /* Sector(512byte) Number on Block */ 190 + WORD PhyBlock; /* Physical Block Number on Zone */ 191 + WORD LogBlock; /* Logical Block Number of Zone */ 192 + }; 193 + typedef struct ADDRESS_T 194 + { 195 + BYTE Zone; /* Zone Number */ 196 + BYTE Sector; /* Sector(512byte) Number on Block */ 197 + WORD PhyBlock; /* Physical Block Number on Zone */ 198 + WORD LogBlock; /* Logical Block Number of Zone */ 199 + }*ADDRESS_T; 200 + 201 + struct CIS_AREA 202 + { 203 + BYTE Sector; /* Sector(512byte) Number on Block */ 204 + WORD PhyBlock; /* Physical Block Number on Zone 0 */ 205 + }; 206 + 207 + 208 + //----- SMILMain.c --------------------------------------------------- 209 + /******************************************/ 210 + int Init_D_SmartMedia (void); 211 + int Pwoff_D_SmartMedia (void); 212 + int Check_D_SmartMedia (void); 213 + int Check_D_Parameter (struct us_data *,WORD *,BYTE *,BYTE *); 214 + int Media_D_ReadSector (struct us_data *,DWORD,WORD,BYTE *); 215 + int Media_D_WriteSector (struct us_data *,DWORD,WORD,BYTE *); 216 + int Media_D_CopySector (struct us_data *,DWORD,WORD,BYTE *); 217 + int Media_D_EraseBlock (struct us_data *,DWORD,WORD); 218 + int Media_D_EraseAll (struct us_data *); 219 + /******************************************/ 220 + int Media_D_OneSectWriteStart (struct us_data *,DWORD,BYTE *); 221 + int Media_D_OneSectWriteNext (struct us_data *,BYTE *); 222 + int Media_D_OneSectWriteFlush (struct us_data *); 223 + 224 + /******************************************/ 225 + void SM_EnableLED (struct us_data *,BOOLEAN); 226 + void Led_D_TernOn (void); 227 + void Led_D_TernOff (void); 228 + 229 + int Media_D_EraseAllRedtData (DWORD Index, BOOLEAN CheckBlock); 230 + //DWORD Media_D_GetMediaInfo (struct us_data * fdoExt, PIOCTL_MEDIA_INFO_IN pParamIn, PIOCTL_MEDIA_INFO_OUT pParamOut); 231 + 232 + //----- SMILSub.c ---------------------------------------------------- 233 + /******************************************/ 234 + int Check_D_DataBlank (BYTE *); 235 + int Check_D_FailBlock (BYTE *); 236 + int Check_D_DataStatus (BYTE *); 237 + int Load_D_LogBlockAddr (BYTE *); 238 + void Clr_D_RedundantData (BYTE *); 239 + void Set_D_LogBlockAddr (BYTE *); 240 + void Set_D_FailBlock (BYTE *); 241 + void Set_D_DataStaus (BYTE *); 242 + 243 + /******************************************/ 244 + void Ssfdc_D_Reset (struct us_data *); 245 + int Ssfdc_D_ReadCisSect (struct us_data *, BYTE *,BYTE *); 246 + void Ssfdc_D_WriteRedtMode (void); 247 + void Ssfdc_D_ReadID (BYTE *, BYTE); 248 + int Ssfdc_D_ReadSect (struct us_data *, BYTE *,BYTE *); 249 + int Ssfdc_D_ReadBlock (struct us_data *, WORD, BYTE *,BYTE *); 250 + int Ssfdc_D_WriteSect (struct us_data *, BYTE *,BYTE *); 251 + int Ssfdc_D_WriteBlock (struct us_data *, WORD, BYTE *,BYTE *); 252 + int Ssfdc_D_CopyBlock (struct us_data *, WORD, BYTE *,BYTE *); 253 + int Ssfdc_D_WriteSectForCopy (struct us_data *, BYTE *,BYTE *); 254 + int Ssfdc_D_EraseBlock (struct us_data *); 255 + int Ssfdc_D_ReadRedtData (struct us_data *, BYTE *); 256 + int Ssfdc_D_WriteRedtData (struct us_data *, BYTE *); 257 + int Ssfdc_D_CheckStatus (void); 258 + int Set_D_SsfdcModel (BYTE); 259 + void Cnt_D_Reset (void); 260 + int Cnt_D_PowerOn (void); 261 + void Cnt_D_PowerOff (void); 262 + void Cnt_D_LedOn (void); 263 + void Cnt_D_LedOff (void); 264 + int Check_D_CntPower (void); 265 + int Check_D_CardExist (void); 266 + int Check_D_CardStsChg (void); 267 + int Check_D_SsfdcWP (void); 268 + int SM_ReadBlock (struct us_data *, BYTE *,BYTE *); 269 + 270 + int Ssfdc_D_ReadSect_DMA (struct us_data *, BYTE *,BYTE *); 271 + int Ssfdc_D_ReadSect_PIO (struct us_data *, BYTE *,BYTE *); 272 + int Ssfdc_D_WriteSect_DMA (struct us_data *, BYTE *,BYTE *); 273 + int Ssfdc_D_WriteSect_PIO (struct us_data *, BYTE *,BYTE *); 274 + 275 + /******************************************/ 276 + int Check_D_ReadError (BYTE *); 277 + int Check_D_Correct (BYTE *,BYTE *); 278 + int Check_D_CISdata (BYTE *,BYTE *); 279 + void Set_D_RightECC (BYTE *); 280 + 281 + //----- SMILECC.c ---------------------------------------------------- 282 + void calculate_ecc (BYTE *, BYTE *, BYTE *, BYTE *, BYTE *); 283 + BYTE correct_data (BYTE *, BYTE *, BYTE, BYTE, BYTE); 284 + int _Correct_D_SwECC (BYTE *,BYTE *,BYTE *); 285 + void _Calculate_D_SwECC (BYTE *,BYTE *); 286 + 287 + void SM_Init (void); 288 + 289 + #endif // already included
+201
drivers/staging/keucr/smilecc.c
··· 1 + #include "usb.h" 2 + #include "scsiglue.h" 3 + #include "transport.h" 4 + //#include "stdlib.h" 5 + //#include "EUCR6SK.h" 6 + #include "smcommon.h" 7 + #include "smil.h" 8 + 9 + //#include <stdio.h> 10 + //#include <stdlib.h> 11 + //#include <string.h> 12 + //#include <dos.h> 13 + // 14 + //#include "EMCRIOS.h" 15 + 16 + // CP0-CP5 code table 17 + static BYTE ecctable[256] = { 18 + 0x00,0x55,0x56,0x03,0x59,0x0C,0x0F,0x5A,0x5A,0x0F,0x0C,0x59,0x03,0x56,0x55,0x00, 19 + 0x65,0x30,0x33,0x66,0x3C,0x69,0x6A,0x3F,0x3F,0x6A,0x69,0x3C,0x66,0x33,0x30,0x65, 20 + 0x66,0x33,0x30,0x65,0x3F,0x6A,0x69,0x3C,0x3C,0x69,0x6A,0x3F,0x65,0x30,0x33,0x66, 21 + 0x03,0x56,0x55,0x00,0x5A,0x0F,0x0C,0x59,0x59,0x0C,0x0F,0x5A,0x00,0x55,0x56,0x03, 22 + 0x69,0x3C,0x3F,0x6A,0x30,0x65,0x66,0x33,0x33,0x66,0x65,0x30,0x6A,0x3F,0x3C,0x69, 23 + 0x0C,0x59,0x5A,0x0F,0x55,0x00,0x03,0x56,0x56,0x03,0x00,0x55,0x0F,0x5A,0x59,0x0C, 24 + 0x0F,0x5A,0x59,0x0C,0x56,0x03,0x00,0x55,0x55,0x00,0x03,0x56,0x0C,0x59,0x5A,0x0F, 25 + 0x6A,0x3F,0x3C,0x69,0x33,0x66,0x65,0x30,0x30,0x65,0x66,0x33,0x69,0x3C,0x3F,0x6A, 26 + 0x6A,0x3F,0x3C,0x69,0x33,0x66,0x65,0x30,0x30,0x65,0x66,0x33,0x69,0x3C,0x3F,0x6A, 27 + 0x0F,0x5A,0x59,0x0C,0x56,0x03,0x00,0x55,0x55,0x00,0x03,0x56,0x0C,0x59,0x5A,0x0F, 28 + 0x0C,0x59,0x5A,0x0F,0x55,0x00,0x03,0x56,0x56,0x03,0x00,0x55,0x0F,0x5A,0x59,0x0C, 29 + 0x69,0x3C,0x3F,0x6A,0x30,0x65,0x66,0x33,0x33,0x66,0x65,0x30,0x6A,0x3F,0x3C,0x69, 30 + 0x03,0x56,0x55,0x00,0x5A,0x0F,0x0C,0x59,0x59,0x0C,0x0F,0x5A,0x00,0x55,0x56,0x03, 31 + 0x66,0x33,0x30,0x65,0x3F,0x6A,0x69,0x3C,0x3C,0x69,0x6A,0x3F,0x65,0x30,0x33,0x66, 32 + 0x65,0x30,0x33,0x66,0x3C,0x69,0x6A,0x3F,0x3F,0x6A,0x69,0x3C,0x66,0x33,0x30,0x65, 33 + 0x00,0x55,0x56,0x03,0x59,0x0C,0x0F,0x5A,0x5A,0x0F,0x0C,0x59,0x03,0x56,0x55,0x00 34 + }; 35 + 36 + static void trans_result (BYTE, BYTE, BYTE *, BYTE *); 37 + 38 + #define BIT7 0x80 39 + #define BIT6 0x40 40 + #define BIT5 0x20 41 + #define BIT4 0x10 42 + #define BIT3 0x08 43 + #define BIT2 0x04 44 + #define BIT1 0x02 45 + #define BIT0 0x01 46 + #define BIT1BIT0 0x03 47 + #define BIT23 0x00800000L 48 + #define MASK_CPS 0x3f 49 + #define CORRECTABLE 0x00555554L 50 + 51 + static void trans_result(reg2,reg3,ecc1,ecc2) 52 + BYTE reg2; // LP14,LP12,LP10,... 53 + BYTE reg3; // LP15,LP13,LP11,... 54 + BYTE *ecc1; // LP15,LP14,LP13,... 55 + BYTE *ecc2; // LP07,LP06,LP05,... 56 + { 57 + BYTE a; // Working for reg2,reg3 58 + BYTE b; // Working for ecc1,ecc2 59 + BYTE i; // For counting 60 + 61 + a=BIT7; b=BIT7; // 80h=10000000b 62 + *ecc1=*ecc2=0; // Clear ecc1,ecc2 63 + for(i=0; i<4; ++i) { 64 + if ((reg3&a)!=0) 65 + *ecc1|=b; // LP15,13,11,9 -> ecc1 66 + b=b>>1; // Right shift 67 + if ((reg2&a)!=0) 68 + *ecc1|=b; // LP14,12,10,8 -> ecc1 69 + b=b>>1; // Right shift 70 + a=a>>1; // Right shift 71 + } 72 + 73 + b=BIT7; // 80h=10000000b 74 + for(i=0; i<4; ++i) { 75 + if ((reg3&a)!=0) 76 + *ecc2|=b; // LP7,5,3,1 -> ecc2 77 + b=b>>1; // Right shift 78 + if ((reg2&a)!=0) 79 + *ecc2|=b; // LP6,4,2,0 -> ecc2 80 + b=b>>1; // Right shift 81 + a=a>>1; // Right shift 82 + } 83 + } 84 + 85 + //static void calculate_ecc(table,data,ecc1,ecc2,ecc3) 86 + void calculate_ecc(table,data,ecc1,ecc2,ecc3) 87 + BYTE *table; // CP0-CP5 code table 88 + BYTE *data; // DATA 89 + BYTE *ecc1; // LP15,LP14,LP13,... 90 + BYTE *ecc2; // LP07,LP06,LP05,... 91 + BYTE *ecc3; // CP5,CP4,CP3,...,"1","1" 92 + { 93 + DWORD i; // For counting 94 + BYTE a; // Working for table 95 + BYTE reg1; // D-all,CP5,CP4,CP3,... 96 + BYTE reg2; // LP14,LP12,L10,... 97 + BYTE reg3; // LP15,LP13,L11,... 98 + 99 + reg1=reg2=reg3=0; // Clear parameter 100 + for(i=0; i<256; ++i) { 101 + a=table[data[i]]; // Get CP0-CP5 code from table 102 + reg1^=(a&MASK_CPS); // XOR with a 103 + if ((a&BIT6)!=0) 104 + { // If D_all(all bit XOR) = 1 105 + reg3^=(BYTE)i; // XOR with counter 106 + reg2^=~((BYTE)i); // XOR with inv. of counter 107 + } 108 + } 109 + 110 + // Trans LP14,12,10,... & LP15,13,11,... -> LP15,14,13,... & LP7,6,5,.. 111 + trans_result(reg2,reg3,ecc1,ecc2); 112 + *ecc1=~(*ecc1); *ecc2=~(*ecc2); // Inv. ecc2 & ecc3 113 + *ecc3=((~reg1)<<2)|BIT1BIT0; // Make TEL format 114 + } 115 + 116 + BYTE correct_data(data,eccdata,ecc1,ecc2,ecc3) 117 + BYTE *data; // DATA 118 + BYTE *eccdata; // ECC DATA 119 + BYTE ecc1; // LP15,LP14,LP13,... 120 + BYTE ecc2; // LP07,LP06,LP05,... 121 + BYTE ecc3; // CP5,CP4,CP3,...,"1","1" 122 + { 123 + DWORD l; // Working to check d 124 + DWORD d; // Result of comparison 125 + DWORD i; // For counting 126 + BYTE d1,d2,d3; // Result of comparison 127 + BYTE a; // Working for add 128 + BYTE add; // Byte address of cor. DATA 129 + BYTE b; // Working for bit 130 + BYTE bit; // Bit address of cor. DATA 131 + 132 + d1=ecc1^eccdata[1]; d2=ecc2^eccdata[0]; // Compare LP's 133 + d3=ecc3^eccdata[2]; // Comapre CP's 134 + d=((DWORD)d1<<16) // Result of comparison 135 + +((DWORD)d2<<8) 136 + +(DWORD)d3; 137 + 138 + if (d==0) return(0); // If No error, return 139 + 140 + if (((d^(d>>1))&CORRECTABLE)==CORRECTABLE) 141 + { // If correctable 142 + l=BIT23; 143 + add=0; // Clear parameter 144 + a=BIT7; 145 + 146 + for(i=0; i<8; ++i) { // Checking 8 bit 147 + if ((d&l)!=0) add|=a; // Make byte address from LP's 148 + l>>=2; a>>=1; // Right Shift 149 + } 150 + 151 + bit=0; // Clear parameter 152 + b=BIT2; 153 + for(i=0; i<3; ++i) { // Checking 3 bit 154 + if ((d&l)!=0) bit|=b; // Make bit address from CP's 155 + l>>=2; b>>=1; // Right shift 156 + } 157 + 158 + b=BIT0; 159 + data[add]^=(b<<bit); // Put corrected data 160 + return(1); 161 + } 162 + 163 + i=0; // Clear count 164 + d&=0x00ffffffL; // Masking 165 + 166 + while(d) { // If d=0 finish counting 167 + if (d&BIT0) ++i; // Count number of 1 bit 168 + d>>=1; // Right shift 169 + } 170 + 171 + if (i==1) 172 + { // If ECC error 173 + eccdata[1]=ecc1; eccdata[0]=ecc2; // Put right ECC code 174 + eccdata[2]=ecc3; 175 + return(2); 176 + } 177 + return(3); // Uncorrectable error 178 + } 179 + 180 + int _Correct_D_SwECC(buf,redundant_ecc,calculate_ecc) 181 + BYTE *buf; 182 + BYTE *redundant_ecc; 183 + BYTE *calculate_ecc; 184 + { 185 + DWORD err; 186 + 187 + err=correct_data(buf,redundant_ecc,*(calculate_ecc+1),*(calculate_ecc),*(calculate_ecc+2)); 188 + if (err==1) StringCopy(calculate_ecc,redundant_ecc,3); 189 + if (err==0 || err==1 || err==2) 190 + return(0); 191 + return(-1); 192 + } 193 + 194 + void _Calculate_D_SwECC(buf,ecc) 195 + BYTE *buf; 196 + BYTE *ecc; 197 + { 198 + calculate_ecc(ecctable,buf,ecc+1,ecc+0,ecc+2); 199 + } 200 + 201 +
+1852
drivers/staging/keucr/smilmain.c
··· 1 + #include <linux/slab.h> 2 + #include "usb.h" 3 + #include "scsiglue.h" 4 + #include "smcommon.h" 5 + #include "smil.h" 6 + 7 + int Check_D_LogCHS (WORD *,BYTE *,BYTE *); 8 + void Initialize_D_Media (void); 9 + void PowerOff_D_Media (void); 10 + int Check_D_MediaPower (void); 11 + int Check_D_MediaExist (void); 12 + int Check_D_MediaWP (void); 13 + int Check_D_MediaFmt (struct us_data *); 14 + int Check_D_MediaFmtForEraseAll (struct us_data *); 15 + int Conv_D_MediaAddr (struct us_data *, DWORD); 16 + int Inc_D_MediaAddr (struct us_data *); 17 + int Check_D_FirstSect (void); 18 + int Check_D_LastSect (void); 19 + int Media_D_ReadOneSect (struct us_data *, WORD, BYTE *); 20 + int Media_D_WriteOneSect (struct us_data *, WORD, BYTE *); 21 + int Media_D_CopyBlockHead (struct us_data *); 22 + int Media_D_CopyBlockTail (struct us_data *); 23 + int Media_D_EraseOneBlock (void); 24 + int Media_D_EraseAllBlock (void); 25 + 26 + int Copy_D_BlockAll (struct us_data *, DWORD); 27 + int Copy_D_BlockHead (struct us_data *); 28 + int Copy_D_BlockTail (struct us_data *); 29 + int Reassign_D_BlockHead (struct us_data *); 30 + 31 + int Assign_D_WriteBlock (void); 32 + int Release_D_ReadBlock (struct us_data *); 33 + int Release_D_WriteBlock (struct us_data *); 34 + int Release_D_CopySector (struct us_data *); 35 + 36 + int Copy_D_PhyOneSect (struct us_data *); 37 + int Read_D_PhyOneSect (struct us_data *, WORD, BYTE *); 38 + int Write_D_PhyOneSect (struct us_data *, WORD, BYTE *); 39 + int Erase_D_PhyOneBlock (struct us_data *); 40 + 41 + int Set_D_PhyFmtValue (struct us_data *); 42 + int Search_D_CIS (struct us_data *); 43 + int Make_D_LogTable (struct us_data *); 44 + void Check_D_BlockIsFull (void); 45 + 46 + int MarkFail_D_PhyOneBlock (struct us_data *); 47 + 48 + DWORD ErrXDCode; 49 + DWORD ErrCode; 50 + //BYTE SectBuf[SECTSIZE]; 51 + BYTE WorkBuf[SECTSIZE]; 52 + BYTE Redundant[REDTSIZE]; 53 + BYTE WorkRedund[REDTSIZE]; 54 + //WORD Log2Phy[MAX_ZONENUM][MAX_LOGBLOCK]; 55 + WORD *Log2Phy[MAX_ZONENUM]; // 128 x 1000, Log2Phy[MAX_ZONENUM][MAX_LOGBLOCK]; 56 + BYTE Assign[MAX_ZONENUM][MAX_BLOCKNUM/8]; 57 + WORD AssignStart[MAX_ZONENUM]; 58 + WORD ReadBlock; 59 + WORD WriteBlock; 60 + DWORD MediaChange; 61 + DWORD SectCopyMode; 62 + 63 + extern struct SSFDCTYPE Ssfdc; 64 + extern struct ADDRESS Media; 65 + extern struct CIS_AREA CisArea; 66 + 67 + //BIT Controll Macro 68 + BYTE BitData[] = { 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80 } ; 69 + #define Set_D_Bit(a,b) (a[(BYTE)((b)/8)]|= BitData[(b)%8]) 70 + #define Clr_D_Bit(a,b) (a[(BYTE)((b)/8)]&=~BitData[(b)%8]) 71 + #define Chk_D_Bit(a,b) (a[(BYTE)((b)/8)] & BitData[(b)%8]) 72 + 73 + //extern PBYTE SMHostAddr; 74 + extern BYTE IsSSFDCCompliance; 75 + extern BYTE IsXDCompliance; 76 + 77 + 78 + // 79 + ////Power Controll & Media Exist Check Function 80 + ////----- Init_D_SmartMedia() -------------------------------------------- 81 + //int Init_D_SmartMedia(void) 82 + //{ 83 + // int i; 84 + // 85 + // EMCR_Print("Init_D_SmartMedia start\n"); 86 + // for (i=0; i<MAX_ZONENUM; i++) 87 + // { 88 + // if (Log2Phy[i]!=NULL) 89 + // { 90 + // EMCR_Print("ExFreePool Zone = %x, Addr = %x\n", i, Log2Phy[i]); 91 + // ExFreePool(Log2Phy[i]); 92 + // Log2Phy[i] = NULL; 93 + // } 94 + // } 95 + // 96 + // Initialize_D_Media(); 97 + // return(NO_ERROR); 98 + //} 99 + 100 + //----- SM_FreeMem() ------------------------------------------------- 101 + int SM_FreeMem(void) 102 + { 103 + int i; 104 + 105 + printk("SM_FreeMem start\n"); 106 + for (i=0; i<MAX_ZONENUM; i++) 107 + { 108 + if (Log2Phy[i]!=NULL) 109 + { 110 + printk("Free Zone = %x, Addr = %p\n", i, Log2Phy[i]); 111 + kfree(Log2Phy[i]); 112 + Log2Phy[i] = NULL; 113 + } 114 + } 115 + return(NO_ERROR); 116 + } 117 + 118 + ////----- Pwoff_D_SmartMedia() ------------------------------------------- 119 + //int Pwoff_D_SmartMedia(void) 120 + //{ 121 + // PowerOff_D_Media(); 122 + // return(NO_ERROR); 123 + //} 124 + // 125 + ////----- Check_D_SmartMedia() ------------------------------------------- 126 + //int Check_D_SmartMedia(void) 127 + //{ 128 + // if (Check_D_MediaExist()) 129 + // return(ErrCode); 130 + // 131 + // return(NO_ERROR); 132 + //} 133 + // 134 + ////----- Check_D_Parameter() -------------------------------------------- 135 + //int Check_D_Parameter(PFDO_DEVICE_EXTENSION fdoExt,WORD *pcyl,BYTE *phead,BYTE *psect) 136 + //{ 137 + // if (Check_D_MediaPower()) 138 + // return(ErrCode); 139 + // 140 + // if (Check_D_MediaFmt(fdoExt)) 141 + // return(ErrCode); 142 + // 143 + // if (Check_D_LogCHS(pcyl,phead,psect)) 144 + // return(ErrCode); 145 + // 146 + // return(NO_ERROR); 147 + //} 148 + 149 + //SmartMedia Read/Write/Erase Function 150 + //----- Media_D_ReadSector() ------------------------------------------- 151 + int Media_D_ReadSector(struct us_data *us, DWORD start,WORD count,BYTE *buf) 152 + { 153 + WORD len, bn; 154 + 155 + //if (Check_D_MediaPower()) ; �b 6250 don't care 156 + // return(ErrCode); ; 157 + //if (Check_D_MediaFmt(fdoExt)) ; 158 + // return(ErrCode); ; 159 + if (Conv_D_MediaAddr(us, start)) 160 + return(ErrCode); 161 + 162 + while(1) 163 + { 164 + len = Ssfdc.MaxSectors - Media.Sector; 165 + if (count > len) 166 + bn = len; 167 + else 168 + bn = count; 169 + //if (Media_D_ReadOneSect(fdoExt, SectBuf)) 170 + //if (Media_D_ReadOneSect(fdoExt, count, buf)) 171 + if (Media_D_ReadOneSect(us, bn, buf)) 172 + { 173 + ErrCode = ERR_EccReadErr; 174 + return(ErrCode); 175 + } 176 + 177 + Media.Sector += bn; 178 + count -= bn; 179 + 180 + if (count<=0) 181 + break; 182 + 183 + buf += bn * SECTSIZE; 184 + 185 + if (Inc_D_MediaAddr(us)) 186 + return(ErrCode); 187 + } 188 + 189 + return(NO_ERROR); 190 + } 191 + // here 192 + //----- Media_D_CopySector() ------------------------------------------ 193 + int Media_D_CopySector(struct us_data *us, DWORD start,WORD count,BYTE *buf) 194 + { 195 + //DWORD mode; 196 + //int i; 197 + WORD len, bn; 198 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 199 + //ADDRESS_T bb = (ADDRESS_T) &Media; 200 + 201 + //printk("Media_D_CopySector !!!\n"); 202 + if (Conv_D_MediaAddr(us, start)) 203 + return(ErrCode); 204 + 205 + while(1) 206 + { 207 + if (Assign_D_WriteBlock()) 208 + return(ERROR); 209 + 210 + len = Ssfdc.MaxSectors - Media.Sector; 211 + if (count > len) 212 + bn = len; 213 + else 214 + bn = count; 215 + 216 + //if (Ssfdc_D_CopyBlock(fdoExt,count,buf,Redundant)) 217 + if (Ssfdc_D_CopyBlock(us,bn,buf,Redundant)) 218 + { 219 + ErrCode = ERR_WriteFault; 220 + return(ErrCode); 221 + } 222 + 223 + Media.Sector = 0x1F; 224 + //if (Release_D_ReadBlock(fdoExt)) 225 + if (Release_D_CopySector(us)) 226 + { 227 + if (ErrCode==ERR_HwError) 228 + { 229 + ErrCode = ERR_WriteFault; 230 + return(ErrCode); 231 + } 232 + } 233 + count -= bn; 234 + 235 + if (count<=0) 236 + break; 237 + 238 + buf += bn * SECTSIZE; 239 + 240 + if (Inc_D_MediaAddr(us)) 241 + return(ErrCode); 242 + 243 + } 244 + return(NO_ERROR); 245 + } 246 + 247 + //----- Release_D_CopySector() ------------------------------------------ 248 + int Release_D_CopySector(struct us_data *us) 249 + { 250 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 251 + //ADDRESS_T bb = (ADDRESS_T) &Media; 252 + 253 + Log2Phy[Media.Zone][Media.LogBlock]=WriteBlock; 254 + Media.PhyBlock=ReadBlock; 255 + 256 + if (Media.PhyBlock==NO_ASSIGN) 257 + { 258 + Media.PhyBlock=WriteBlock; 259 + return(SUCCESS); 260 + } 261 + 262 + Clr_D_Bit(Assign[Media.Zone],Media.PhyBlock); 263 + Media.PhyBlock=WriteBlock; 264 + 265 + return(SUCCESS); 266 + } 267 + /* 268 + //----- Media_D_WriteSector() ------------------------------------------ 269 + int Media_D_WriteSector(PFDO_DEVICE_EXTENSION fdoExt, DWORD start,WORD count,BYTE *buf) 270 + { 271 + int i; 272 + WORD len, bn; 273 + SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 274 + ADDRESS_T bb = (ADDRESS_T) &Media; 275 + 276 + //if (Check_D_MediaPower()) 277 + // return(ErrCode); 278 + // 279 + //if (Check_D_MediaFmt(fdoExt)) 280 + // return(ErrCode); 281 + // 282 + //if (Check_D_MediaWP()) 283 + // return(ErrCode); 284 + 285 + if (Conv_D_MediaAddr(fdoExt, start)) 286 + return(ErrCode); 287 + 288 + //ENE_Print("Media_D_WriteSector --- Sector = %x\n", Media.Sector); 289 + if (Check_D_FirstSect()) 290 + { 291 + if (Media_D_CopyBlockHead(fdoExt)) 292 + { 293 + ErrCode = ERR_WriteFault; 294 + return(ErrCode); 295 + } 296 + } 297 + 298 + while(1) 299 + { 300 + if (!Check_D_FirstSect()) 301 + { 302 + if (Assign_D_WriteBlock()) 303 + return(ErrCode); 304 + } 305 + 306 + len = Ssfdc.MaxSectors - Media.Sector; 307 + if (count > len) 308 + bn = len; 309 + else 310 + bn = count; 311 + //for(i=0;i<SECTSIZE;i++) 312 + // SectBuf[i]=*buf++; 313 + 314 + //if (Media_D_WriteOneSect(fdoExt, SectBuf)) 315 + if (Media_D_WriteOneSect(fdoExt, bn, buf)) 316 + { 317 + ErrCode = ERR_WriteFault; 318 + return(ErrCode); 319 + } 320 + 321 + Media.Sector += bn - 1; 322 + 323 + if (!Check_D_LastSect()) 324 + { 325 + if (Release_D_ReadBlock(fdoExt)) 326 + 327 + { if (ErrCode==ERR_HwError) 328 + { 329 + ErrCode = ERR_WriteFault; 330 + return(ErrCode); 331 + } 332 + } 333 + } 334 + 335 + count -= bn; 336 + 337 + if (count<=0) 338 + break; 339 + 340 + buf += bn * SECTSIZE; 341 + 342 + //if (--count<=0) 343 + // break; 344 + 345 + if (Inc_D_MediaAddr(fdoExt)) 346 + return(ErrCode); 347 + } 348 + 349 + if (!Check_D_LastSect()) 350 + return(NO_ERROR); 351 + 352 + if (Inc_D_MediaAddr(fdoExt)) 353 + return(ErrCode); 354 + 355 + if (Media_D_CopyBlockTail(fdoExt)) 356 + { 357 + ErrCode = ERR_WriteFault; 358 + return(ErrCode); 359 + } 360 + 361 + return(NO_ERROR); 362 + } 363 + // 364 + ////----- Media_D_EraseBlock() ------------------------------------------- 365 + //int Media_D_EraseBlock(PFDO_DEVICE_EXTENSION fdoExt, DWORD start,WORD count) 366 + //{ 367 + // if (Check_D_MediaPower()) 368 + // return(ErrCode); 369 + // 370 + // if (Check_D_MediaFmt(fdoExt)) 371 + // return(ErrCode); 372 + // 373 + // if (Check_D_MediaWP()) 374 + // return(ErrCode); 375 + // 376 + // if (Conv_D_MediaAddr(start)) 377 + // return(ErrCode); 378 + // 379 + // while(Check_D_FirstSect()) { 380 + // if (Inc_D_MediaAddr(fdoExt)) 381 + // return(ErrCode); 382 + // 383 + // if (--count<=0) 384 + // return(NO_ERROR); 385 + // } 386 + // 387 + // while(1) { 388 + // if (!Check_D_LastSect()) 389 + // if (Media_D_EraseOneBlock()) 390 + // if (ErrCode==ERR_HwError) 391 + // { 392 + // ErrCode = ERR_WriteFault; 393 + // return(ErrCode); 394 + // } 395 + // 396 + // if (Inc_D_MediaAddr(fdoExt)) 397 + // return(ErrCode); 398 + // 399 + // if (--count<=0) 400 + // return(NO_ERROR); 401 + // } 402 + //} 403 + // 404 + ////----- Media_D_EraseAll() --------------------------------------------- 405 + //int Media_D_EraseAll(PFDO_DEVICE_EXTENSION fdoExt) 406 + //{ 407 + // if (Check_D_MediaPower()) 408 + // return(ErrCode); 409 + // 410 + // if (Check_D_MediaFmtForEraseAll(fdoExt)) 411 + // return(ErrCode); 412 + // 413 + // if (Check_D_MediaWP()) 414 + // return(ErrCode); 415 + // 416 + // if (Media_D_EraseAllBlock()) 417 + // return(ErrCode); 418 + // 419 + // return(NO_ERROR); 420 + //} 421 + 422 + //SmartMedia Write Function for One Sector Write Mode 423 + //----- Media_D_OneSectWriteStart() ------------------------------------ 424 + int Media_D_OneSectWriteStart(PFDO_DEVICE_EXTENSION fdoExt,DWORD start,BYTE *buf) 425 + { 426 + // int i; 427 + // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 428 + // ADDRESS_T bb = (ADDRESS_T) &Media; 429 + // 430 + // //if (Check_D_MediaPower()) 431 + // // return(ErrCode); 432 + // //if (Check_D_MediaFmt(fdoExt)) 433 + // // return(ErrCode); 434 + // //if (Check_D_MediaWP()) 435 + // // return(ErrCode); 436 + // if (Conv_D_MediaAddr(fdoExt, start)) 437 + // return(ErrCode); 438 + // 439 + // if (Check_D_FirstSect()) 440 + // if (Media_D_CopyBlockHead(fdoExt)) 441 + // { 442 + // ErrCode = ERR_WriteFault; 443 + // return(ErrCode); 444 + // } 445 + // 446 + // if (!Check_D_FirstSect()) 447 + // if (Assign_D_WriteBlock()) 448 + // return(ErrCode); 449 + // 450 + // //for(i=0;i<SECTSIZE;i++) 451 + // // SectBuf[i]=*buf++; 452 + // 453 + // //if (Media_D_WriteOneSect(fdoExt, SectBuf)) 454 + // if (Media_D_WriteOneSect(fdoExt, buf)) 455 + // { 456 + // ErrCode = ERR_WriteFault; 457 + // return(ErrCode); 458 + // } 459 + // 460 + // if (!Check_D_LastSect()) 461 + // { 462 + // if (Release_D_ReadBlock(fdoExt)) 463 + // if (ErrCode==ERR_HwError) 464 + // { 465 + // ErrCode = ERR_WriteFault; 466 + // return(ErrCode); 467 + // } 468 + // } 469 + 470 + return(NO_ERROR); 471 + } 472 + 473 + //----- Media_D_OneSectWriteNext() ------------------------------------- 474 + int Media_D_OneSectWriteNext(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf) 475 + { 476 + // int i; 477 + // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 478 + // ADDRESS_T bb = (ADDRESS_T) &Media; 479 + // 480 + // if (Inc_D_MediaAddr(fdoExt)) 481 + // return(ErrCode); 482 + // 483 + // if (!Check_D_FirstSect()) 484 + // if (Assign_D_WriteBlock()) 485 + // return(ErrCode); 486 + // 487 + // //for(i=0;i<SECTSIZE;i++) 488 + // // SectBuf[i]=*buf++; 489 + // 490 + // //if (Media_D_WriteOneSect(fdoExt, SectBuf)) 491 + // if (Media_D_WriteOneSect(fdoExt, buf)) 492 + // { 493 + // ErrCode = ERR_WriteFault; 494 + // return(ErrCode); 495 + // } 496 + // 497 + // if (!Check_D_LastSect()) 498 + // { 499 + // if (Release_D_ReadBlock(fdoExt)) 500 + // if (ErrCode==ERR_HwError) 501 + // { 502 + // ErrCode = ERR_WriteFault; 503 + // return(ErrCode); 504 + // } 505 + // } 506 + 507 + return(NO_ERROR); 508 + } 509 + 510 + //----- Media_D_OneSectWriteFlush() ------------------------------------ 511 + int Media_D_OneSectWriteFlush(PFDO_DEVICE_EXTENSION fdoExt) 512 + { 513 + if (!Check_D_LastSect()) 514 + return(NO_ERROR); 515 + 516 + if (Inc_D_MediaAddr(fdoExt)) 517 + return(ErrCode); 518 + 519 + if (Media_D_CopyBlockTail(fdoExt)) 520 + { 521 + ErrCode = ERR_WriteFault; 522 + return(ErrCode); 523 + } 524 + 525 + return(NO_ERROR); 526 + } 527 + // 528 + ////LED Tern On/Off Subroutine 529 + ////----- SM_EnableLED() ----------------------------------------------- 530 + //void SM_EnableLED(PFDO_DEVICE_EXTENSION fdoExt, BOOLEAN enable) 531 + //{ 532 + // if (fdoExt->Drive_IsSWLED) 533 + // { 534 + // if (enable) 535 + // Led_D_TernOn(); 536 + // else 537 + // Led_D_TernOff(); 538 + // } 539 + //} 540 + // 541 + ////----- Led_D_TernOn() ------------------------------------------------- 542 + //void Led_D_TernOn(void) 543 + //{ 544 + // if (Check_D_CardStsChg()) 545 + // MediaChange=ERROR; 546 + // 547 + // Cnt_D_LedOn(); 548 + //} 549 + // 550 + ////----- Led_D_TernOff() ------------------------------------------------ 551 + //void Led_D_TernOff(void) 552 + //{ 553 + // if (Check_D_CardStsChg()) 554 + // MediaChange=ERROR; 555 + // 556 + // Cnt_D_LedOff(); 557 + //} 558 + // 559 + ////SmartMedia Logical Format Subroutine 560 + ////----- Check_D_LogCHS() ----------------------------------------------- 561 + //int Check_D_LogCHS(WORD *c,BYTE *h,BYTE *s) 562 + //{ 563 + // switch(Ssfdc.Model) { 564 + // case SSFDC1MB: *c=125; *h= 4; *s= 4; break; 565 + // case SSFDC2MB: *c=125; *h= 4; *s= 8; break; 566 + // case SSFDC4MB: *c=250; *h= 4; *s= 8; break; 567 + // case SSFDC8MB: *c=250; *h= 4; *s=16; break; 568 + // case SSFDC16MB: *c=500; *h= 4; *s=16; break; 569 + // case SSFDC32MB: *c=500; *h= 8; *s=16; break; 570 + // case SSFDC64MB: *c=500; *h= 8; *s=32; break; 571 + // case SSFDC128MB: *c=500; *h=16; *s=32; break; 572 + // default: *c= 0; *h= 0; *s= 0; ErrCode = ERR_NoSmartMedia; return(ERROR); 573 + // } 574 + // 575 + // return(SUCCESS); 576 + //} 577 + // 578 + ////Power Controll & Media Exist Check Subroutine 579 + ////----- Initialize_D_Media() ------------------------------------------- 580 + //void Initialize_D_Media(void) 581 + //{ 582 + // ErrCode = NO_ERROR; 583 + // MediaChange = ERROR; 584 + // SectCopyMode = COMPLETED; 585 + // Cnt_D_Reset(); 586 + //} 587 + // 588 + ////----- PowerOff_D_Media() --------------------------------------------- 589 + //void PowerOff_D_Media(void) 590 + //{ 591 + // Cnt_D_PowerOff(); 592 + //} 593 + // 594 + ////----- Check_D_MediaPower() ------------------------------------------- 595 + //int Check_D_MediaPower(void) 596 + //{ 597 + // //usleep(56*1024); 598 + // if (Check_D_CardStsChg()) 599 + // MediaChange = ERROR; 600 + // //usleep(56*1024); 601 + // if ((!Check_D_CntPower())&&(!MediaChange)) // �� power & Media �S�Q change, �h return success 602 + // return(SUCCESS); 603 + // //usleep(56*1024); 604 + // 605 + // if (Check_D_CardExist()) // Check if card is not exist, return err 606 + // { 607 + // ErrCode = ERR_NoSmartMedia; 608 + // MediaChange = ERROR; 609 + // return(ERROR); 610 + // } 611 + // //usleep(56*1024); 612 + // if (Cnt_D_PowerOn()) 613 + // { 614 + // ErrCode = ERR_NoSmartMedia; 615 + // MediaChange = ERROR; 616 + // return(ERROR); 617 + // } 618 + // //usleep(56*1024); 619 + // Ssfdc_D_Reset(fdoExt); 620 + // //usleep(56*1024); 621 + // return(SUCCESS); 622 + //} 623 + // 624 + ////-----Check_D_MediaExist() -------------------------------------------- 625 + //int Check_D_MediaExist(void) 626 + //{ 627 + // if (Check_D_CardStsChg()) 628 + // MediaChange = ERROR; 629 + // 630 + // if (!Check_D_CardExist()) 631 + // { 632 + // if (!MediaChange) 633 + // return(SUCCESS); 634 + // 635 + // ErrCode = ERR_ChangedMedia; 636 + // return(ERROR); 637 + // } 638 + // 639 + // ErrCode = ERR_NoSmartMedia; 640 + // 641 + // return(ERROR); 642 + //} 643 + // 644 + ////----- Check_D_MediaWP() ---------------------------------------------- 645 + //int Check_D_MediaWP(void) 646 + //{ 647 + // if (Ssfdc.Attribute &MWP) 648 + // { 649 + // ErrCode = ERR_WrtProtect; 650 + // return(ERROR); 651 + // } 652 + // 653 + // return(SUCCESS); 654 + //} 655 + */ 656 + //SmartMedia Physical Format Test Subroutine 657 + //----- Check_D_MediaFmt() --------------------------------------------- 658 + int Check_D_MediaFmt(struct us_data *us) 659 + { 660 + printk("Check_D_MediaFmt\n"); 661 + //ULONG i,j, result=FALSE, zone,block; 662 + 663 + //usleep(56*1024); 664 + if (!MediaChange) 665 + return(SUCCESS); 666 + 667 + MediaChange = ERROR; 668 + SectCopyMode = COMPLETED; 669 + 670 + //usleep(56*1024); 671 + if (Set_D_PhyFmtValue(us)) 672 + { 673 + ErrCode = ERR_UnknownMedia; 674 + return(ERROR); 675 + } 676 + 677 + //usleep(56*1024); 678 + if (Search_D_CIS(us)) 679 + { 680 + ErrCode = ERR_IllegalFmt; 681 + return(ERROR); 682 + } 683 + 684 + 685 + MediaChange = SUCCESS; 686 + return(SUCCESS); 687 + } 688 + /* 689 + ////----- Check_D_BlockIsFull() ---------------------------------- 690 + //void Check_D_BlockIsFull() 691 + //{ 692 + // ULONG i, block; 693 + // 694 + // if (IsXDCompliance || IsSSFDCCompliance) 695 + // { 696 + // // If the blocks are full then return write-protect. 697 + // block = Ssfdc.MaxBlocks/8; 698 + // for (Media.Zone=0; Media.Zone<Ssfdc.MaxZones; Media.Zone++) 699 + // { 700 + // if (Log2Phy[Media.Zone]==NULL) 701 + // { 702 + // if (Make_D_LogTable()) 703 + // { 704 + // ErrCode = ERR_IllegalFmt; 705 + // return; 706 + // } 707 + // } 708 + // 709 + // for (i=0; i<block; i++) 710 + // { 711 + // if (Assign[Media.Zone][i] != 0xFF) 712 + // return; 713 + // } 714 + // } 715 + // Ssfdc.Attribute |= WP; 716 + // } 717 + //} 718 + // 719 + // 720 + ////----- Check_D_MediaFmtForEraseAll() ---------------------------------- 721 + //int Check_D_MediaFmtForEraseAll(PFDO_DEVICE_EXTENSION fdoExt) 722 + //{ 723 + // MediaChange = ERROR; 724 + // SectCopyMode = COMPLETED; 725 + // 726 + // if (Set_D_PhyFmtValue(fdoExt)) 727 + // { 728 + // ErrCode = ERR_UnknownMedia; 729 + // return(ERROR); 730 + // } 731 + // 732 + // if (Search_D_CIS(fdoExt)) 733 + // { 734 + // ErrCode = ERR_IllegalFmt; 735 + // return(ERROR); 736 + // } 737 + // 738 + // return(SUCCESS); 739 + //} 740 + */ 741 + //SmartMedia Physical Address Controll Subroutine 742 + //----- Conv_D_MediaAddr() --------------------------------------------- 743 + int Conv_D_MediaAddr(struct us_data *us, DWORD addr) 744 + { 745 + DWORD temp; 746 + //ULONG zz; 747 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 748 + //ADDRESS_T bb = (ADDRESS_T) &Media; 749 + 750 + temp = addr/Ssfdc.MaxSectors; 751 + Media.Zone = (BYTE) (temp/Ssfdc.MaxLogBlocks); 752 + 753 + if (Log2Phy[Media.Zone]==NULL) 754 + { 755 + if (Make_D_LogTable(us)) 756 + { 757 + ErrCode = ERR_IllegalFmt; 758 + return(ERROR); 759 + } 760 + } 761 + 762 + Media.Sector = (BYTE) (addr%Ssfdc.MaxSectors); 763 + Media.LogBlock = (WORD) (temp%Ssfdc.MaxLogBlocks); 764 + 765 + if (Media.Zone<Ssfdc.MaxZones) 766 + { 767 + Clr_D_RedundantData(Redundant); 768 + Set_D_LogBlockAddr(Redundant); 769 + Media.PhyBlock = Log2Phy[Media.Zone][Media.LogBlock]; 770 + return(SUCCESS); 771 + } 772 + 773 + ErrCode = ERR_OutOfLBA; 774 + return(ERROR); 775 + } 776 + 777 + //----- Inc_D_MediaAddr() ---------------------------------------------- 778 + int Inc_D_MediaAddr(struct us_data *us) 779 + { 780 + WORD LogBlock = Media.LogBlock; 781 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 782 + //ADDRESS_T bb = (ADDRESS_T) &Media; 783 + 784 + if (++Media.Sector<Ssfdc.MaxSectors) 785 + return(SUCCESS); 786 + 787 + if (Log2Phy[Media.Zone]==NULL) 788 + { 789 + if (Make_D_LogTable(us)) 790 + { 791 + ErrCode = ERR_IllegalFmt; 792 + return(ERROR); 793 + } 794 + } 795 + 796 + Media.Sector=0; 797 + Media.LogBlock = LogBlock; 798 + 799 + if (++Media.LogBlock<Ssfdc.MaxLogBlocks) 800 + { 801 + Clr_D_RedundantData(Redundant); 802 + Set_D_LogBlockAddr(Redundant); 803 + Media.PhyBlock=Log2Phy[Media.Zone][Media.LogBlock]; 804 + return(SUCCESS); 805 + } 806 + 807 + Media.LogBlock=0; 808 + 809 + if (++Media.Zone<Ssfdc.MaxZones) 810 + { 811 + if (Log2Phy[Media.Zone]==NULL) 812 + { 813 + if (Make_D_LogTable(us)) 814 + { 815 + ErrCode = ERR_IllegalFmt; 816 + return(ERROR); 817 + } 818 + } 819 + 820 + Media.LogBlock = 0; 821 + 822 + Clr_D_RedundantData(Redundant); 823 + Set_D_LogBlockAddr(Redundant); 824 + Media.PhyBlock=Log2Phy[Media.Zone][Media.LogBlock]; 825 + return(SUCCESS); 826 + } 827 + 828 + Media.Zone=0; 829 + ErrCode = ERR_OutOfLBA; 830 + 831 + return(ERROR); 832 + } 833 + /* 834 + //----- Check_D_FirstSect() -------------------------------------------- 835 + int Check_D_FirstSect(void) 836 + { 837 + SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 838 + ADDRESS_T bb = (ADDRESS_T) &Media; 839 + 840 + if (!Media.Sector) 841 + return(SUCCESS); 842 + 843 + return(ERROR); 844 + } 845 + 846 + //----- Check_D_LastSect() --------------------------------------------- 847 + int Check_D_LastSect(void) 848 + { 849 + SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 850 + ADDRESS_T bb = (ADDRESS_T) &Media; 851 + 852 + if (Media.Sector<(Ssfdc.MaxSectors-1)) 853 + return(ERROR); 854 + 855 + return(SUCCESS); 856 + } 857 + */ 858 + //SmartMedia Read/Write Subroutine with Retry 859 + //----- Media_D_ReadOneSect() ------------------------------------------ 860 + int Media_D_ReadOneSect(struct us_data *us, WORD count, BYTE *buf) 861 + { 862 + DWORD err, retry; 863 + 864 + if (!Read_D_PhyOneSect(us, count, buf)) 865 + return(SUCCESS); 866 + if (ErrCode==ERR_HwError) 867 + return(ERROR); 868 + if (ErrCode==ERR_DataStatus) 869 + return(ERROR); 870 + 871 + #ifdef RDERR_REASSIGN 872 + if (Ssfdc.Attribute &MWP) 873 + { 874 + if (ErrCode==ERR_CorReadErr) 875 + return(SUCCESS); 876 + return(ERROR); 877 + } 878 + 879 + err=ErrCode; 880 + for(retry=0; retry<2; retry++) 881 + { 882 + if (Copy_D_BlockAll(us, (err==ERR_EccReadErr)?REQ_FAIL:REQ_ERASE)) 883 + { 884 + if (ErrCode==ERR_HwError) 885 + return(ERROR); 886 + continue; 887 + } 888 + 889 + ErrCode = err; 890 + if (ErrCode==ERR_CorReadErr) 891 + return(SUCCESS); 892 + return(ERROR); 893 + } 894 + 895 + MediaChange = ERROR; 896 + #else 897 + if (ErrCode==ERR_CorReadErr) return(SUCCESS); 898 + #endif 899 + 900 + return(ERROR); 901 + } 902 + /* 903 + //----- Media_D_WriteOneSect() ----------------------------------------- 904 + int Media_D_WriteOneSect(PFDO_DEVICE_EXTENSION fdoExt, WORD count, BYTE *buf) 905 + { 906 + DWORD retry; 907 + SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 908 + ADDRESS_T bb = (ADDRESS_T) &Media; 909 + 910 + if (!Write_D_PhyOneSect(fdoExt, count, buf)) 911 + return(SUCCESS); 912 + if (ErrCode==ERR_HwError) 913 + return(ERROR); 914 + 915 + for(retry=1; retry<2; retry++) 916 + { 917 + if (Reassign_D_BlockHead(fdoExt)) 918 + { 919 + if (ErrCode==ERR_HwError) 920 + return(ERROR); 921 + continue; 922 + } 923 + 924 + if (!Write_D_PhyOneSect(fdoExt, count, buf)) 925 + return(SUCCESS); 926 + if (ErrCode==ERR_HwError) 927 + return(ERROR); 928 + } 929 + 930 + if (Release_D_WriteBlock(fdoExt)) 931 + return(ERROR); 932 + 933 + ErrCode = ERR_WriteFault; 934 + MediaChange = ERROR; 935 + return(ERROR); 936 + } 937 + 938 + //SmartMedia Data Copy Subroutine with Retry 939 + //----- Media_D_CopyBlockHead() ---------------------------------------- 940 + int Media_D_CopyBlockHead(PFDO_DEVICE_EXTENSION fdoExt) 941 + { 942 + DWORD retry; 943 + 944 + for(retry=0; retry<2; retry++) 945 + { 946 + if (!Copy_D_BlockHead(fdoExt)) 947 + return(SUCCESS); 948 + if (ErrCode==ERR_HwError) 949 + return(ERROR); 950 + } 951 + 952 + MediaChange = ERROR; 953 + return(ERROR); 954 + } 955 + 956 + //----- Media_D_CopyBlockTail() ---------------------------------------- 957 + int Media_D_CopyBlockTail(PFDO_DEVICE_EXTENSION fdoExt) 958 + { 959 + DWORD retry; 960 + 961 + if (!Copy_D_BlockTail(fdoExt)) 962 + return(SUCCESS); 963 + if (ErrCode==ERR_HwError) 964 + return(ERROR); 965 + 966 + for(retry=1; retry<2; retry++) 967 + { 968 + if (Reassign_D_BlockHead(fdoExt)) 969 + { 970 + if (ErrCode==ERR_HwError) 971 + return(ERROR); 972 + continue; 973 + } 974 + 975 + if (!Copy_D_BlockTail(fdoExt)) 976 + return(SUCCESS); 977 + if (ErrCode==ERR_HwError) 978 + return(ERROR); 979 + } 980 + 981 + if (Release_D_WriteBlock(fdoExt)) 982 + return(ERROR); 983 + 984 + ErrCode = ERR_WriteFault; 985 + MediaChange = ERROR; 986 + return(ERROR); 987 + } 988 + // 989 + ////----- Media_D_EraseOneBlock() ---------------------------------------- 990 + //int Media_D_EraseOneBlock(void) 991 + //{ 992 + // WORD LogBlock = Media.LogBlock; 993 + // WORD PhyBlock = Media.PhyBlock; 994 + // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 995 + // ADDRESS_T bb = (ADDRESS_T) &Media; 996 + // 997 + // if (Media.PhyBlock==NO_ASSIGN) 998 + // return(SUCCESS); 999 + // 1000 + // if (Log2Phy[Media.Zone]==NULL) 1001 + // { 1002 + // if (Make_D_LogTable()) 1003 + // { 1004 + // ErrCode = ERR_IllegalFmt; 1005 + // return(ERROR); 1006 + // } 1007 + // } 1008 + // Media.LogBlock = LogBlock; 1009 + // Media.PhyBlock = PhyBlock; 1010 + // 1011 + // Log2Phy[Media.Zone][Media.LogBlock]=NO_ASSIGN; 1012 + // 1013 + // if (Erase_D_PhyOneBlock(fdoExt)) 1014 + // { 1015 + // if (ErrCode==ERR_HwError) 1016 + // return(ERROR); 1017 + // if (MarkFail_D_PhyOneBlock()) 1018 + // return(ERROR); 1019 + // 1020 + // ErrCode = ERR_WriteFault; 1021 + // return(ERROR); 1022 + // } 1023 + // 1024 + // Clr_D_Bit(Assign[Media.Zone],Media.PhyBlock); 1025 + // Media.PhyBlock=NO_ASSIGN; 1026 + // return(SUCCESS); 1027 + //} 1028 + // 1029 + ////SmartMedia Erase Subroutine 1030 + ////----- Media_D_EraseAllBlock() ---------------------------------------- 1031 + //int Media_D_EraseAllBlock(void) 1032 + //{ 1033 + // WORD cis=0; 1034 + // 1035 + // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1036 + // ADDRESS_T bb = (ADDRESS_T) &Media; 1037 + // 1038 + // MediaChange = ERROR; 1039 + // Media.Sector = 0; 1040 + // 1041 + // for(Media.Zone=0; Media.Zone<Ssfdc.MaxZones; Media.Zone++) 1042 + // for(Media.PhyBlock=0; Media.PhyBlock<Ssfdc.MaxBlocks; Media.PhyBlock++) { 1043 + // if (Ssfdc_D_ReadRedtData(Redundant)) 1044 + // { 1045 + // Ssfdc_D_Reset(fdoExt); 1046 + // return(ERROR); 1047 + // } 1048 + // 1049 + // Ssfdc_D_Reset(fdoExt); 1050 + // if (!Check_D_FailBlock(Redundant)) 1051 + // { 1052 + // if (cis) 1053 + // { 1054 + // if (Ssfdc_D_EraseBlock(fdoExt)) 1055 + // { 1056 + // ErrCode = ERR_HwError; 1057 + // return(ERROR); 1058 + // } 1059 + // 1060 + // if (Ssfdc_D_CheckStatus()) 1061 + // { 1062 + // if (MarkFail_D_PhyOneBlock()) 1063 + // return(ERROR); 1064 + // } 1065 + // 1066 + // continue; 1067 + // } 1068 + // 1069 + // if (Media.PhyBlock!=CisArea.PhyBlock) 1070 + // { 1071 + // ErrCode = ERR_IllegalFmt; 1072 + // return(ERROR); 1073 + // } 1074 + // 1075 + // cis++; 1076 + // } 1077 + // 1078 + // } 1079 + // return(SUCCESS); 1080 + //} 1081 + */ 1082 + //SmartMedia Physical Sector Data Copy Subroutine 1083 + //----- Copy_D_BlockAll() ---------------------------------------------- 1084 + int Copy_D_BlockAll(struct us_data *us, DWORD mode) 1085 + { 1086 + BYTE sect; 1087 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1088 + //ADDRESS_T bb = (ADDRESS_T) &Media; 1089 + 1090 + sect=Media.Sector; 1091 + 1092 + if (Assign_D_WriteBlock()) 1093 + return(ERROR); 1094 + if (mode==REQ_FAIL) 1095 + SectCopyMode=REQ_FAIL; 1096 + 1097 + for(Media.Sector=0; Media.Sector<Ssfdc.MaxSectors; Media.Sector++) 1098 + { 1099 + if (Copy_D_PhyOneSect(us)) 1100 + { 1101 + if (ErrCode==ERR_HwError) 1102 + return(ERROR); 1103 + if (Release_D_WriteBlock(us)) 1104 + return(ERROR); 1105 + 1106 + ErrCode = ERR_WriteFault; 1107 + Media.PhyBlock=ReadBlock; 1108 + Media.Sector=sect; 1109 + 1110 + return(ERROR); 1111 + } 1112 + } 1113 + 1114 + if (Release_D_ReadBlock(us)) 1115 + return(ERROR); 1116 + 1117 + Media.PhyBlock=WriteBlock; 1118 + Media.Sector=sect; 1119 + return(SUCCESS); 1120 + } 1121 + /* 1122 + //----- Copy_D_BlockHead() --------------------------------------------- 1123 + int Copy_D_BlockHead(PFDO_DEVICE_EXTENSION fdoExt) 1124 + { 1125 + BYTE sect; 1126 + SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1127 + ADDRESS_T bb = (ADDRESS_T) &Media; 1128 + 1129 + sect=Media.Sector; 1130 + if (Assign_D_WriteBlock()) 1131 + return(ERROR); 1132 + 1133 + for(Media.Sector=0; Media.Sector<sect; Media.Sector++) 1134 + { 1135 + if (Copy_D_PhyOneSect(fdoExt)) 1136 + { 1137 + if (ErrCode==ERR_HwError) 1138 + return(ERROR); 1139 + if (Release_D_WriteBlock(fdoExt)) 1140 + return(ERROR); 1141 + 1142 + ErrCode = ERR_WriteFault; 1143 + Media.PhyBlock=ReadBlock; 1144 + Media.Sector=sect; 1145 + 1146 + return(ERROR); 1147 + } 1148 + } 1149 + 1150 + Media.PhyBlock=WriteBlock; 1151 + Media.Sector=sect; 1152 + return(SUCCESS); 1153 + } 1154 + 1155 + //----- Copy_D_BlockTail() --------------------------------------------- 1156 + int Copy_D_BlockTail(PFDO_DEVICE_EXTENSION fdoExt) 1157 + { 1158 + BYTE sect; 1159 + SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1160 + ADDRESS_T bb = (ADDRESS_T) &Media; 1161 + 1162 + for(sect=Media.Sector; Media.Sector<Ssfdc.MaxSectors; Media.Sector++) 1163 + { 1164 + if (Copy_D_PhyOneSect(fdoExt)) 1165 + { 1166 + if (ErrCode==ERR_HwError) 1167 + return(ERROR); 1168 + 1169 + Media.PhyBlock=WriteBlock; 1170 + Media.Sector=sect; 1171 + 1172 + return(ERROR); 1173 + } 1174 + } 1175 + 1176 + if (Release_D_ReadBlock(fdoExt)) 1177 + return(ERROR); 1178 + 1179 + Media.PhyBlock=WriteBlock; 1180 + Media.Sector=sect; 1181 + return(SUCCESS); 1182 + } 1183 + 1184 + //----- Reassign_D_BlockHead() ----------------------------------------- 1185 + int Reassign_D_BlockHead(PFDO_DEVICE_EXTENSION fdoExt) 1186 + { 1187 + DWORD mode; 1188 + WORD block; 1189 + BYTE sect; 1190 + SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1191 + ADDRESS_T bb = (ADDRESS_T) &Media; 1192 + 1193 + mode=SectCopyMode; 1194 + block=ReadBlock; 1195 + sect=Media.Sector; 1196 + 1197 + if (Assign_D_WriteBlock()) 1198 + return(ERROR); 1199 + 1200 + SectCopyMode=REQ_FAIL; 1201 + 1202 + for(Media.Sector=0; Media.Sector<sect; Media.Sector++) 1203 + { 1204 + if (Copy_D_PhyOneSect(fdoExt)) 1205 + { 1206 + if (ErrCode==ERR_HwError) 1207 + return(ERROR); 1208 + if (Release_D_WriteBlock(fdoExt)) 1209 + return(ERROR); 1210 + 1211 + ErrCode = ERR_WriteFault; 1212 + SectCopyMode=mode; 1213 + WriteBlock=ReadBlock; 1214 + ReadBlock=block; 1215 + Media.Sector=sect; 1216 + Media.PhyBlock=WriteBlock; 1217 + 1218 + return(ERROR); 1219 + } 1220 + } 1221 + 1222 + if (Release_D_ReadBlock(fdoExt)) 1223 + return(ERROR); 1224 + 1225 + SectCopyMode=mode; 1226 + ReadBlock=block; 1227 + Media.Sector=sect; 1228 + Media.PhyBlock=WriteBlock; 1229 + return(SUCCESS); 1230 + } 1231 + */ 1232 + //SmartMedia Physical Block Assign/Release Subroutine 1233 + //----- Assign_D_WriteBlock() ------------------------------------------ 1234 + int Assign_D_WriteBlock(void) 1235 + { 1236 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1237 + //ADDRESS_T bb = (ADDRESS_T) &Media; 1238 + ReadBlock=Media.PhyBlock; 1239 + 1240 + for(WriteBlock=AssignStart[Media.Zone]; WriteBlock<Ssfdc.MaxBlocks; WriteBlock++) 1241 + { 1242 + if (!Chk_D_Bit(Assign[Media.Zone],WriteBlock)) 1243 + { 1244 + Set_D_Bit(Assign[Media.Zone],WriteBlock); 1245 + AssignStart[Media.Zone]=WriteBlock+1; 1246 + Media.PhyBlock=WriteBlock; 1247 + SectCopyMode=REQ_ERASE; 1248 + //ErrXDCode = NO_ERROR; 1249 + return(SUCCESS); 1250 + } 1251 + } 1252 + 1253 + for(WriteBlock=0; WriteBlock<AssignStart[Media.Zone]; WriteBlock++) 1254 + { 1255 + if (!Chk_D_Bit(Assign[Media.Zone],WriteBlock)) 1256 + { 1257 + Set_D_Bit(Assign[Media.Zone],WriteBlock); 1258 + AssignStart[Media.Zone]=WriteBlock+1; 1259 + Media.PhyBlock=WriteBlock; 1260 + SectCopyMode=REQ_ERASE; 1261 + //ErrXDCode = NO_ERROR; 1262 + return(SUCCESS); 1263 + } 1264 + } 1265 + 1266 + WriteBlock=NO_ASSIGN; 1267 + ErrCode = ERR_WriteFault; 1268 + // For xD test 1269 + //Ssfdc.Attribute |= WP; 1270 + //ErrXDCode = ERR_WrtProtect; 1271 + return(ERROR); 1272 + } 1273 + 1274 + //----- Release_D_ReadBlock() ------------------------------------------ 1275 + int Release_D_ReadBlock(struct us_data *us) 1276 + { 1277 + DWORD mode; 1278 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1279 + //ADDRESS_T bb = (ADDRESS_T) &Media; 1280 + 1281 + mode=SectCopyMode; 1282 + SectCopyMode=COMPLETED; 1283 + 1284 + if (mode==COMPLETED) 1285 + return(SUCCESS); 1286 + 1287 + Log2Phy[Media.Zone][Media.LogBlock]=WriteBlock; 1288 + Media.PhyBlock=ReadBlock; 1289 + 1290 + if (Media.PhyBlock==NO_ASSIGN) 1291 + { 1292 + Media.PhyBlock=WriteBlock; 1293 + return(SUCCESS); 1294 + } 1295 + 1296 + if (mode==REQ_ERASE) 1297 + { 1298 + if (Erase_D_PhyOneBlock(us)) 1299 + { 1300 + if (ErrCode==ERR_HwError) return(ERROR); 1301 + if (MarkFail_D_PhyOneBlock(us)) return(ERROR); 1302 + } 1303 + else 1304 + Clr_D_Bit(Assign[Media.Zone],Media.PhyBlock); 1305 + } 1306 + else if (MarkFail_D_PhyOneBlock(us)) 1307 + return(ERROR); 1308 + 1309 + Media.PhyBlock=WriteBlock; 1310 + return(SUCCESS); 1311 + } 1312 + 1313 + //----- Release_D_WriteBlock() ----------------------------------------- 1314 + int Release_D_WriteBlock(struct us_data *us) 1315 + { 1316 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1317 + //ADDRESS_T bb = (ADDRESS_T) &Media; 1318 + SectCopyMode=COMPLETED; 1319 + Media.PhyBlock=WriteBlock; 1320 + 1321 + if (MarkFail_D_PhyOneBlock(us)) 1322 + return(ERROR); 1323 + 1324 + Media.PhyBlock=ReadBlock; 1325 + return(SUCCESS); 1326 + } 1327 + 1328 + //SmartMedia Physical Sector Data Copy Subroutine 1329 + //----- Copy_D_PhyOneSect() -------------------------------------------- 1330 + int Copy_D_PhyOneSect(struct us_data *us) 1331 + { 1332 + int i; 1333 + DWORD err, retry; 1334 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1335 + //ADDRESS_T bb = (ADDRESS_T) &Media; 1336 + 1337 + //printk("Copy_D_PhyOneSect --- Secotr = %x\n", Media.Sector); 1338 + if (ReadBlock!=NO_ASSIGN) 1339 + { 1340 + Media.PhyBlock=ReadBlock; 1341 + for(retry=0; retry<2; retry++) 1342 + { 1343 + if (retry!=0) 1344 + { 1345 + Ssfdc_D_Reset(us); 1346 + if (Ssfdc_D_ReadCisSect(us,WorkBuf,WorkRedund)) 1347 + { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); } 1348 + 1349 + if (Check_D_CISdata(WorkBuf,WorkRedund)) 1350 + { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); } 1351 + } 1352 + 1353 + if (Ssfdc_D_ReadSect(us,WorkBuf,WorkRedund)) 1354 + { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); } 1355 + if (Check_D_DataStatus(WorkRedund)) 1356 + { err=ERROR; break; } 1357 + if (!Check_D_ReadError(WorkRedund)) 1358 + { err=SUCCESS; break; } 1359 + if (!Check_D_Correct(WorkBuf,WorkRedund)) 1360 + { err=SUCCESS; break; } 1361 + 1362 + err=ERROR; 1363 + SectCopyMode=REQ_FAIL; 1364 + } 1365 + } 1366 + else 1367 + { 1368 + err=SUCCESS; 1369 + for(i=0; i<SECTSIZE; i++) 1370 + WorkBuf[i]=DUMMY_DATA; 1371 + Clr_D_RedundantData(WorkRedund); 1372 + } 1373 + 1374 + Set_D_LogBlockAddr(WorkRedund); 1375 + if (err==ERROR) 1376 + { 1377 + Set_D_RightECC(WorkRedund); 1378 + Set_D_DataStaus(WorkRedund); 1379 + } 1380 + 1381 + Media.PhyBlock=WriteBlock; 1382 + 1383 + if (Ssfdc_D_WriteSectForCopy(us, WorkBuf, WorkRedund)) 1384 + { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); } 1385 + if (Ssfdc_D_CheckStatus()) 1386 + { ErrCode = ERR_WriteFault; return(ERROR); } 1387 + 1388 + Media.PhyBlock=ReadBlock; 1389 + return(SUCCESS); 1390 + } 1391 + 1392 + //SmartMedia Physical Sector Read/Write/Erase Subroutine 1393 + //----- Read_D_PhyOneSect() -------------------------------------------- 1394 + int Read_D_PhyOneSect(struct us_data *us, WORD count, BYTE *buf) 1395 + { 1396 + int i; 1397 + DWORD retry; 1398 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1399 + //ADDRESS_T bb = (ADDRESS_T) &Media; 1400 + 1401 + if (Media.PhyBlock==NO_ASSIGN) 1402 + { 1403 + for(i=0; i<SECTSIZE; i++) 1404 + *buf++=DUMMY_DATA; 1405 + return(SUCCESS); 1406 + } 1407 + 1408 + for(retry=0; retry<2; retry++) 1409 + { 1410 + if (retry!=0) 1411 + { 1412 + Ssfdc_D_Reset(us); 1413 + 1414 + if (Ssfdc_D_ReadCisSect(us,WorkBuf,WorkRedund)) 1415 + { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); } 1416 + if (Check_D_CISdata(WorkBuf,WorkRedund)) 1417 + { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); } 1418 + } 1419 + 1420 + //if (Ssfdc_D_ReadSect(fdoExt,buf,Redundant)) 1421 + if (Ssfdc_D_ReadBlock(us,count,buf,Redundant)) 1422 + { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); } 1423 + if (Check_D_DataStatus(Redundant)) 1424 + { ErrCode = ERR_DataStatus; return(ERROR); } 1425 + 1426 + if (!Check_D_ReadError(Redundant)) 1427 + return(SUCCESS); 1428 + 1429 + if (!Check_D_Correct(buf,Redundant)) 1430 + { ErrCode = ERR_CorReadErr; return(ERROR); } 1431 + } 1432 + 1433 + ErrCode = ERR_EccReadErr; 1434 + return(ERROR); 1435 + } 1436 + /* 1437 + //----- Write_D_PhyOneSect() ------------------------------------------- 1438 + int Write_D_PhyOneSect(PFDO_DEVICE_EXTENSION fdoExt, WORD count, BYTE *buf) 1439 + { 1440 + SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1441 + ADDRESS_T bb = (ADDRESS_T) &Media; 1442 + 1443 + //if (Ssfdc_D_WriteSect(fdoExt,buf,Redundant)) 1444 + if (Ssfdc_D_WriteBlock(fdoExt,count,buf,Redundant)) 1445 + { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); } 1446 + if (Ssfdc_D_CheckStatus()) 1447 + { ErrCode = ERR_WriteFault; return(ERROR); } 1448 + 1449 + return(SUCCESS); 1450 + } 1451 + */ 1452 + //----- Erase_D_PhyOneBlock() ------------------------------------------ 1453 + int Erase_D_PhyOneBlock(struct us_data *us) 1454 + { 1455 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1456 + //ADDRESS_T bb = (ADDRESS_T) &Media; 1457 + 1458 + if (Ssfdc_D_EraseBlock(us)) 1459 + { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); } 1460 + if (Ssfdc_D_CheckStatus()) 1461 + { ErrCode = ERR_WriteFault; return(ERROR); } 1462 + 1463 + return(SUCCESS); 1464 + } 1465 + 1466 + //SmartMedia Physical Format Check Local Subroutine 1467 + //----- Set_D_PhyFmtValue() -------------------------------------------- 1468 + int Set_D_PhyFmtValue(struct us_data *us) 1469 + { 1470 + // PPDO_DEVICE_EXTENSION pdoExt; 1471 + // BYTE idcode[4]; 1472 + // DWORD UserDefData_1, UserDefData_2, Data, mask; 1473 + // 1474 + // //if (!fdoExt->ChildDeviceObject) return(ERROR); 1475 + // //pdoExt = fdoExt->ChildDeviceObject->DeviceExtension; 1476 + // 1477 + // Ssfdc_D_ReadID(idcode, READ_ID_1); 1478 + // 1479 + //if (Set_D_SsfdcModel(idcode[1])) 1480 + if (Set_D_SsfdcModel(us->SM_DeviceID)) 1481 + return(ERROR); 1482 + 1483 + // //Use Multi-function pin to differentiate SM and xD. 1484 + // UserDefData_1 = ReadPCIReg(fdoExt->BusID, fdoExt->DevID, fdoExt->FuncID, PCI_REG_USER_DEF) & 0x80; 1485 + // if (UserDefData_1) 1486 + // { 1487 + // if ( READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x80 ) fdoExt->DiskType = DISKTYPE_XD; 1488 + // if ( READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x40 ) fdoExt->DiskType = DISKTYPE_SM; 1489 + // 1490 + // if ( IsXDCompliance && (fdoExt->DiskType == DISKTYPE_XD) ) 1491 + // { 1492 + // Ssfdc_D_ReadID(idcode, READ_ID_3); 1493 + // if (idcode[2] != 0xB5) 1494 + // return(ERROR); 1495 + // } 1496 + // } 1497 + // 1498 + // //Use GPIO to differentiate SM and xD. 1499 + // UserDefData_2 = ReadPCIReg(fdoExt->BusID, fdoExt->DevID, fdoExt->FuncID, PCI_REG_USER_DEF) >> 8; 1500 + // if ( UserDefData_2 ) 1501 + // { 1502 + // Data = ReadPCIReg(fdoExt->BusID, fdoExt->DevID, 0, 0xAC); 1503 + // 1504 + // mask = 1 << (UserDefData_2-1); 1505 + // // 1 : xD , 0 : SM 1506 + // if ( Data & mask) 1507 + // fdoExt->DiskType = DISKTYPE_XD; 1508 + // else 1509 + // fdoExt->DiskType = DISKTYPE_SM; 1510 + // 1511 + // if ( IsXDCompliance && (fdoExt->DiskType == DISKTYPE_XD) ) 1512 + // { 1513 + // Ssfdc_D_ReadID(idcode, READ_ID_3); 1514 + // if (idcode[2] != 0xB5) 1515 + // return(ERROR); 1516 + // } 1517 + // } 1518 + // 1519 + // if ( !(UserDefData_1 | UserDefData_2) ) 1520 + // { 1521 + // // Use UserDefine Register to differentiate SM and xD. 1522 + // Ssfdc_D_ReadID(idcode, READ_ID_3); 1523 + // 1524 + // if (idcode[2] == 0xB5) 1525 + // fdoExt->DiskType = DISKTYPE_XD; 1526 + // else 1527 + // { 1528 + // if (!IsXDCompliance) 1529 + // fdoExt->DiskType = DISKTYPE_SM; 1530 + // else 1531 + // return(ERROR); 1532 + // } 1533 + // 1534 + // if (fdoExt->UserDef_DiskType == 0x04) fdoExt->DiskType = DISKTYPE_XD; 1535 + // if (fdoExt->UserDef_DiskType == 0x08) fdoExt->DiskType = DISKTYPE_SM; 1536 + // } 1537 + // 1538 + // if (!fdoExt->UserDef_DisableWP) 1539 + // { 1540 + // if (fdoExt->DiskType == DISKTYPE_SM) 1541 + // { 1542 + // if (Check_D_SsfdcWP()) 1543 + // Ssfdc.Attribute|=WP; 1544 + // } 1545 + // } 1546 + 1547 + return(SUCCESS); 1548 + } 1549 + 1550 + //----- Search_D_CIS() ------------------------------------------------- 1551 + int Search_D_CIS(struct us_data *us) 1552 + { 1553 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1554 + //ADDRESS_T bb = (ADDRESS_T) &Media; 1555 + 1556 + Media.Zone=0; Media.Sector=0; 1557 + 1558 + for (Media.PhyBlock=0; Media.PhyBlock<(Ssfdc.MaxBlocks-Ssfdc.MaxLogBlocks-1); Media.PhyBlock++) 1559 + { 1560 + if (Ssfdc_D_ReadRedtData(us, Redundant)) 1561 + { 1562 + Ssfdc_D_Reset(us); 1563 + return(ERROR); 1564 + } 1565 + 1566 + if (!Check_D_FailBlock(Redundant)) 1567 + break; 1568 + } 1569 + 1570 + if (Media.PhyBlock==(Ssfdc.MaxBlocks-Ssfdc.MaxLogBlocks-1)) 1571 + { 1572 + Ssfdc_D_Reset(us); 1573 + return(ERROR); 1574 + } 1575 + 1576 + while (Media.Sector<CIS_SEARCH_SECT) 1577 + { 1578 + if (Media.Sector) 1579 + { 1580 + if (Ssfdc_D_ReadRedtData(us, Redundant)) 1581 + { 1582 + Ssfdc_D_Reset(us); 1583 + return(ERROR); 1584 + } 1585 + } 1586 + if (!Check_D_DataStatus(Redundant)) 1587 + { 1588 + if (Ssfdc_D_ReadSect(us,WorkBuf,Redundant)) 1589 + { 1590 + Ssfdc_D_Reset(us); 1591 + return(ERROR); 1592 + } 1593 + 1594 + if (Check_D_CISdata(WorkBuf,Redundant)) 1595 + { 1596 + Ssfdc_D_Reset(us); 1597 + return(ERROR); 1598 + } 1599 + 1600 + CisArea.PhyBlock=Media.PhyBlock; 1601 + CisArea.Sector=Media.Sector; 1602 + Ssfdc_D_Reset(us); 1603 + return(SUCCESS); 1604 + } 1605 + 1606 + Media.Sector++; 1607 + } 1608 + 1609 + Ssfdc_D_Reset(us); 1610 + return(ERROR); 1611 + } 1612 + 1613 + //----- Make_D_LogTable() ---------------------------------------------- 1614 + int Make_D_LogTable(struct us_data *us) 1615 + { 1616 + WORD phyblock,logblock; 1617 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1618 + //ADDRESS_T bb = (ADDRESS_T) &Media; 1619 + 1620 + if (Log2Phy[Media.Zone]==NULL) 1621 + { 1622 + Log2Phy[Media.Zone] = kmalloc(MAX_LOGBLOCK*sizeof(WORD), GFP_KERNEL); 1623 + //printk("ExAllocatePool Zone = %x, Addr = %x\n", Media.Zone, Log2Phy[Media.Zone]); 1624 + if (Log2Phy[Media.Zone]==NULL) 1625 + return(ERROR); 1626 + } 1627 + 1628 + Media.Sector=0; 1629 + 1630 + //for(Media.Zone=0; Media.Zone<MAX_ZONENUM; Media.Zone++) 1631 + //for(Media.Zone=0; Media.Zone<Ssfdc.MaxZones; Media.Zone++) 1632 + { 1633 + //printk("Make_D_LogTable --- MediaZone = 0x%x\n", Media.Zone); 1634 + for(Media.LogBlock=0; Media.LogBlock<Ssfdc.MaxLogBlocks; Media.LogBlock++) 1635 + Log2Phy[Media.Zone][Media.LogBlock]=NO_ASSIGN; 1636 + 1637 + for(Media.PhyBlock=0; Media.PhyBlock<(MAX_BLOCKNUM/8); Media.PhyBlock++) 1638 + Assign[Media.Zone][Media.PhyBlock]=0x00; 1639 + 1640 + for(Media.PhyBlock=0; Media.PhyBlock<Ssfdc.MaxBlocks; Media.PhyBlock++) 1641 + { 1642 + if ((!Media.Zone) && (Media.PhyBlock<=CisArea.PhyBlock)) 1643 + { 1644 + Set_D_Bit(Assign[Media.Zone],Media.PhyBlock); 1645 + continue; 1646 + } 1647 + 1648 + if (Ssfdc_D_ReadRedtData(us, Redundant)) 1649 + { Ssfdc_D_Reset(us); return(ERROR); } 1650 + 1651 + if (!Check_D_DataBlank(Redundant)) 1652 + continue; 1653 + 1654 + Set_D_Bit(Assign[Media.Zone],Media.PhyBlock); 1655 + 1656 + if (Check_D_FailBlock(Redundant)) 1657 + continue; 1658 + 1659 + //if (Check_D_DataStatus(Redundant)) 1660 + // continue; 1661 + 1662 + if (Load_D_LogBlockAddr(Redundant)) 1663 + continue; 1664 + 1665 + if (Media.LogBlock>=Ssfdc.MaxLogBlocks) 1666 + continue; 1667 + 1668 + if (Log2Phy[Media.Zone][Media.LogBlock]==NO_ASSIGN) 1669 + { 1670 + Log2Phy[Media.Zone][Media.LogBlock]=Media.PhyBlock; 1671 + continue; 1672 + } 1673 + 1674 + phyblock = Media.PhyBlock; 1675 + logblock = Media.LogBlock; 1676 + Media.Sector = (BYTE)(Ssfdc.MaxSectors-1); 1677 + 1678 + if (Ssfdc_D_ReadRedtData(us, Redundant)) 1679 + { Ssfdc_D_Reset(us); return(ERROR); } 1680 + 1681 + if (!Load_D_LogBlockAddr(Redundant)) 1682 + { 1683 + if (Media.LogBlock==logblock) 1684 + { 1685 + Media.PhyBlock=Log2Phy[Media.Zone][logblock]; 1686 + 1687 + if (Ssfdc_D_ReadRedtData(us, Redundant)) 1688 + { Ssfdc_D_Reset(us); return(ERROR); } 1689 + 1690 + Media.PhyBlock=phyblock; 1691 + 1692 + if (!Load_D_LogBlockAddr(Redundant)) 1693 + { 1694 + if (Media.LogBlock!=logblock) 1695 + { 1696 + Media.PhyBlock=Log2Phy[Media.Zone][logblock]; 1697 + Log2Phy[Media.Zone][logblock]=phyblock; 1698 + } 1699 + } 1700 + else 1701 + { 1702 + Media.PhyBlock=Log2Phy[Media.Zone][logblock]; 1703 + Log2Phy[Media.Zone][logblock]=phyblock; 1704 + } 1705 + } 1706 + } 1707 + 1708 + Media.Sector=0; 1709 + 1710 + // here Not yet 1711 + //#ifdef L2P_ERR_ERASE 1712 + // if (!(Ssfdc.Attribute &MWP)) 1713 + // { 1714 + // Ssfdc_D_Reset(fdoExt); 1715 + // if (Ssfdc_D_EraseBlock(fdoExt)) 1716 + // return(ERROR); 1717 + // 1718 + // if (Ssfdc_D_CheckStatus()) 1719 + // { 1720 + // if (MarkFail_D_PhyOneBlock()) 1721 + // return(ERROR); 1722 + // } 1723 + // else 1724 + // Clr_D_Bit(Assign[Media.Zone],Media.PhyBlock); 1725 + // } 1726 + //#else 1727 + // Ssfdc.Attribute|=MWP; 1728 + //#endif 1729 + Media.PhyBlock=phyblock; 1730 + 1731 + } // End for (Media.PhyBlock<Ssfdc.MaxBlocks) 1732 + 1733 + AssignStart[Media.Zone]=0; 1734 + 1735 + } // End for (Media.Zone<MAX_ZONENUM) 1736 + 1737 + Ssfdc_D_Reset(us); 1738 + return(SUCCESS); 1739 + } 1740 + 1741 + //----- MarkFail_D_PhyOneBlock() --------------------------------------- 1742 + int MarkFail_D_PhyOneBlock(struct us_data *us) 1743 + { 1744 + BYTE sect; 1745 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1746 + //ADDRESS_T bb = (ADDRESS_T) &Media; 1747 + 1748 + sect=Media.Sector; 1749 + Set_D_FailBlock(WorkRedund); 1750 + //Ssfdc_D_WriteRedtMode(); 1751 + 1752 + for(Media.Sector=0; Media.Sector<Ssfdc.MaxSectors; Media.Sector++) 1753 + { 1754 + if (Ssfdc_D_WriteRedtData(us, WorkRedund)) 1755 + { 1756 + Ssfdc_D_Reset(us); 1757 + Media.Sector = sect; 1758 + ErrCode = ERR_HwError; 1759 + MediaChange = ERROR; 1760 + return(ERROR); 1761 + } // NO Status Check 1762 + } 1763 + 1764 + Ssfdc_D_Reset(us); 1765 + Media.Sector=sect; 1766 + return(SUCCESS); 1767 + } 1768 + /* 1769 + // 1770 + ////----- SM_Init() ---------------------------------------------------- 1771 + //void SM_Init(void) 1772 + //{ 1773 + // _Hw_D_ClrIntCardChg(); 1774 + // _Hw_D_SetIntMask(); 1775 + // // For DMA Interrupt 1776 + // _Hw_D_ClrDMAIntCardChg(); 1777 + // _Hw_D_SetDMAIntMask(); 1778 + //} 1779 + // 1780 + ////----- Media_D_EraseAllRedtData() ----------------------------------- 1781 + //int Media_D_EraseAllRedtData(DWORD Index, BOOLEAN CheckBlock) 1782 + //{ 1783 + // BYTE i; 1784 + // 1785 + // if (Check_D_MediaPower()) 1786 + // return(ErrCode); 1787 + // 1788 + // if (Check_D_MediaWP()) 1789 + // return(ErrCode); 1790 + // 1791 + // for (i=0; i<REDTSIZE; i++) 1792 + // WorkRedund[i] = 0xFF; 1793 + // 1794 + // Media.Zone = (BYTE)Index; 1795 + // for (Media.PhyBlock=0; Media.PhyBlock<Ssfdc.MaxBlocks; Media.PhyBlock++) 1796 + // { 1797 + // if ((!Media.Zone) && (Media.PhyBlock<=CisArea.PhyBlock)) 1798 + // continue; 1799 + // 1800 + // if (Ssfdc_D_EraseBlock(fdoExt)) 1801 + // { 1802 + // ErrCode = ERR_HwError; 1803 + // return(ERROR); 1804 + // } 1805 + // 1806 + // for(Media.Sector=0; Media.Sector<Ssfdc.MaxSectors; Media.Sector++) 1807 + // { 1808 + // Ssfdc_D_WriteRedtMode(); 1809 + // 1810 + // if (Ssfdc_D_WriteRedtData(WorkRedund)) 1811 + // { 1812 + // Ssfdc_D_Reset(fdoExt); 1813 + // ErrCode = ERR_HwError; 1814 + // MediaChange = ERROR; 1815 + // return(ERROR); 1816 + // } // NO Status Check 1817 + // } 1818 + // 1819 + // Ssfdc_D_Reset(fdoExt); 1820 + // } 1821 + // 1822 + // Ssfdc_D_Reset(fdoExt); 1823 + // 1824 + // return(SUCCESS); 1825 + //} 1826 + // 1827 + ////----- Media_D_GetMediaInfo() --------------------------------------- 1828 + //DWORD Media_D_GetMediaInfo(PFDO_DEVICE_EXTENSION fdoExt, PIOCTL_MEDIA_INFO_IN pParamIn, PIOCTL_MEDIA_INFO_OUT pParamOut) 1829 + //{ 1830 + // pParamOut->ErrCode = STATUS_CMD_FAIL; 1831 + // 1832 + // Init_D_SmartMedia(); 1833 + // 1834 + // if (Check_D_MediaPower()) 1835 + // return (ErrCode==ERR_NoSmartMedia) ? STATUS_CMD_NO_MEDIA : STATUS_CMD_FAIL; 1836 + // 1837 + // if (Set_D_PhyFmtValue(fdoExt)) 1838 + // return STATUS_CMD_FAIL; 1839 + // 1840 + // //usleep(56*1024); 1841 + // if (Search_D_CIS(fdoExt)) 1842 + // return STATUS_CMD_FAIL; 1843 + // 1844 + // if (Check_D_MediaWP()) 1845 + // return STATUS_CMD_MEDIA_WP; 1846 + // 1847 + // pParamOut->PageSize = Ssfdc.MaxSectors; 1848 + // pParamOut->BlockSize = Ssfdc.MaxBlocks; 1849 + // pParamOut->ZoneSize = Ssfdc.MaxZones; 1850 + // 1851 + // return STATUS_CMD_SUCCESS; 1852 + //}*/
+1661
drivers/staging/keucr/smilsub.c
··· 1 + #include <linux/slab.h> 2 + #include "usb.h" 3 + #include "scsiglue.h" 4 + #include "transport.h" 5 + //#include "init.h" 6 + 7 + //#include "stdlib.h" 8 + //#include "EUCR6SK.h" 9 + #include "smcommon.h" 10 + #include "smil.h" 11 + 12 + void _Set_D_SsfdcRdCmd (BYTE); 13 + void _Set_D_SsfdcRdAddr (BYTE); 14 + void _Set_D_SsfdcRdChip (void); 15 + void _Set_D_SsfdcRdStandby (void); 16 + void _Start_D_SsfdcRdHwECC (void); 17 + void _Stop_D_SsfdcRdHwECC (void); 18 + void _Load_D_SsfdcRdHwECC (BYTE); 19 + void _Set_D_SsfdcWrCmd (BYTE); 20 + void _Set_D_SsfdcWrAddr (BYTE); 21 + void _Set_D_SsfdcWrBlock (void); 22 + void _Set_D_SsfdcWrStandby (void); 23 + void _Start_D_SsfdcWrHwECC (void); 24 + void _Load_D_SsfdcWrHwECC (BYTE); 25 + int _Check_D_SsfdcBusy (WORD); 26 + int _Check_D_SsfdcStatus (void); 27 + void _Reset_D_SsfdcErr (void); 28 + void _Read_D_SsfdcBuf (BYTE *); 29 + void _Write_D_SsfdcBuf (BYTE *); 30 + void _Read_D_SsfdcByte (BYTE *); 31 + void _ReadRedt_D_SsfdcBuf (BYTE *); 32 + void _WriteRedt_D_SsfdcBuf (BYTE *); 33 + BYTE _Check_D_DevCode (BYTE); 34 + 35 + void _Set_D_ECCdata (BYTE,BYTE *); 36 + void _Calc_D_ECCdata (BYTE *); 37 + 38 + //void SM_ReadDataWithDMA (PFDO_DEVICE_EXTENSION, BYTE *, WORD); 39 + //void SM_WriteDataWithDMA (PFDO_DEVICE_EXTENSION, BYTE *, WORD); 40 + // 41 + struct SSFDCTYPE Ssfdc; 42 + struct ADDRESS Media; 43 + struct CIS_AREA CisArea; 44 + 45 + BYTE EccBuf[6]; 46 + extern PBYTE SMHostAddr; 47 + extern BYTE IsSSFDCCompliance; 48 + extern BYTE IsXDCompliance; 49 + extern DWORD ErrXDCode; 50 + 51 + extern WORD ReadBlock; 52 + extern WORD WriteBlock; 53 + 54 + //KEVENT SM_DMADoneEvent; 55 + 56 + #define EVEN 0 // Even Page for 256byte/page 57 + #define ODD 1 // Odd Page for 256byte/page 58 + 59 + 60 + //SmartMedia Redundant buffer data Controll Subroutine 61 + //----- Check_D_DataBlank() -------------------------------------------- 62 + int Check_D_DataBlank(BYTE *redundant) 63 + { 64 + char i; 65 + 66 + for(i=0; i<REDTSIZE; i++) 67 + if (*redundant++!=0xFF) 68 + return(ERROR); 69 + 70 + return(SUCCESS); 71 + } 72 + 73 + //----- Check_D_FailBlock() -------------------------------------------- 74 + int Check_D_FailBlock(BYTE *redundant) 75 + { 76 + redundant+=REDT_BLOCK; 77 + 78 + if (*redundant==0xFF) 79 + return(SUCCESS); 80 + if (!*redundant) 81 + return(ERROR); 82 + if (Bit_D_Count(*redundant)<7) 83 + return(ERROR); 84 + 85 + return(SUCCESS); 86 + } 87 + 88 + //----- Check_D_DataStatus() ------------------------------------------- 89 + int Check_D_DataStatus(BYTE *redundant) 90 + { 91 + redundant+=REDT_DATA; 92 + 93 + if (*redundant==0xFF) 94 + return(SUCCESS); 95 + if (!*redundant) 96 + { 97 + ErrXDCode = ERR_DataStatus; 98 + return(ERROR); 99 + } 100 + else 101 + ErrXDCode = NO_ERROR; 102 + 103 + if (Bit_D_Count(*redundant)<5) 104 + return(ERROR); 105 + 106 + return(SUCCESS); 107 + } 108 + 109 + //----- Load_D_LogBlockAddr() ------------------------------------------ 110 + int Load_D_LogBlockAddr(BYTE *redundant) 111 + { 112 + WORD addr1,addr2; 113 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 114 + //ADDRESS_T bb = (ADDRESS_T) &Media; 115 + 116 + addr1=(WORD)*(redundant+REDT_ADDR1H)*0x0100+(WORD)*(redundant+REDT_ADDR1L); 117 + addr2=(WORD)*(redundant+REDT_ADDR2H)*0x0100+(WORD)*(redundant+REDT_ADDR2L); 118 + 119 + if (addr1==addr2) 120 + if ((addr1 &0xF000)==0x1000) 121 + { Media.LogBlock=(addr1 &0x0FFF)/2; return(SUCCESS); } 122 + 123 + if (Bit_D_CountWord((WORD)(addr1^addr2))!=0x01) return(ERROR); 124 + 125 + if ((addr1 &0xF000)==0x1000) 126 + if (!(Bit_D_CountWord(addr1) &0x01)) 127 + { Media.LogBlock=(addr1 &0x0FFF)/2; return(SUCCESS); } 128 + 129 + if ((addr2 &0xF000)==0x1000) 130 + if (!(Bit_D_CountWord(addr2) &0x01)) 131 + { Media.LogBlock=(addr2 &0x0FFF)/2; return(SUCCESS); } 132 + 133 + return(ERROR); 134 + } 135 + 136 + //----- Clr_D_RedundantData() ------------------------------------------ 137 + void Clr_D_RedundantData(BYTE *redundant) 138 + { 139 + char i; 140 + 141 + for(i=0; i<REDTSIZE; i++) 142 + *(redundant+i)=0xFF; 143 + } 144 + 145 + //----- Set_D_LogBlockAddr() ------------------------------------------- 146 + void Set_D_LogBlockAddr(BYTE *redundant) 147 + { 148 + WORD addr; 149 + 150 + *(redundant+REDT_BLOCK)=0xFF; 151 + *(redundant+REDT_DATA) =0xFF; 152 + addr=Media.LogBlock*2+0x1000; 153 + 154 + if ((Bit_D_CountWord(addr)%2)) 155 + addr++; 156 + 157 + *(redundant+REDT_ADDR1H)=*(redundant+REDT_ADDR2H)=(BYTE)(addr/0x0100); 158 + *(redundant+REDT_ADDR1L)=*(redundant+REDT_ADDR2L)=(BYTE)addr; 159 + } 160 + 161 + //----- Set_D_FailBlock() ---------------------------------------------- 162 + void Set_D_FailBlock(BYTE *redundant) 163 + { 164 + char i; 165 + 166 + for(i=0; i<REDTSIZE; i++) 167 + *redundant++=(BYTE)((i==REDT_BLOCK)?0xF0:0xFF); 168 + } 169 + 170 + //----- Set_D_DataStaus() ---------------------------------------------- 171 + void Set_D_DataStaus(BYTE *redundant) 172 + { 173 + redundant+=REDT_DATA; 174 + *redundant=0x00; 175 + } 176 + 177 + //SmartMedia Function Command Subroutine 178 + // 6250 CMD 6 179 + //----- Ssfdc_D_Reset() ------------------------------------------------ 180 + void Ssfdc_D_Reset(struct us_data *us) 181 + { 182 + //NTSTATUS ntStatus = STATUS_SUCCESS; 183 + //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw; 184 + //BYTE buf[0x200]; 185 + 186 + //printk("Ssfdc_D_Reset --- But do nothing !!\n"); 187 + return; 188 + /* RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW)); 189 + pBulkCbw->dCBWSignature = CBW_SIGNTURE; 190 + pBulkCbw->bCBWLun = CBW_LUN; 191 + //pBulkCbw->dCBWDataTransferLength = 0x200; 192 + pBulkCbw->bmCBWFlags = 0x80; 193 + pBulkCbw->CBWCb[0] = 0xF2; 194 + pBulkCbw->CBWCb[1] = 0x07; 195 + 196 + ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, NULL); 197 + 198 + if (!NT_SUCCESS(ntStatus)) 199 + { 200 + ENE_Print("Ssfdc_D_Reset Fail !!\n"); 201 + //return ntStatus; 202 + }*/ 203 + } 204 + 205 + //----- Ssfdc_D_ReadCisSect() ------------------------------------------ 206 + int Ssfdc_D_ReadCisSect(struct us_data *us, BYTE *buf,BYTE *redundant) 207 + { 208 + BYTE zone,sector; 209 + WORD block; 210 + //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 211 + //ADDRESS_T bb = (ADDRESS_T) &Media; 212 + 213 + zone=Media.Zone; block=Media.PhyBlock; sector=Media.Sector; 214 + Media.Zone=0; 215 + Media.PhyBlock=CisArea.PhyBlock; 216 + Media.Sector=CisArea.Sector; 217 + 218 + if (Ssfdc_D_ReadSect(us,buf,redundant)) 219 + { 220 + Media.Zone=zone; Media.PhyBlock=block; Media.Sector=sector; 221 + return(ERROR); 222 + } 223 + 224 + Media.Zone=zone; Media.PhyBlock=block; Media.Sector=sector; 225 + return(SUCCESS); 226 + } 227 + /* 228 + ////----- Ssfdc_D_WriteRedtMode() ---------------------------------------- 229 + //void Ssfdc_D_WriteRedtMode(void) 230 + //{ 231 + // _Set_D_SsfdcRdCmd (RST_CHIP); 232 + // _Check_D_SsfdcBusy (BUSY_RESET); 233 + // _Set_D_SsfdcRdCmd (READ_REDT); 234 + // _Check_D_SsfdcBusy (BUSY_READ); 235 + // _Set_D_SsfdcRdStandby (); 236 + //} 237 + // 238 + ////----- Ssfdc_D_ReadID() ----------------------------------------------- 239 + //void Ssfdc_D_ReadID(BYTE *buf, BYTE ReadID) 240 + //{ 241 + // _Set_D_SsfdcRdCmd (ReadID); 242 + // _Set_D_SsfdcRdChip (); 243 + // _Read_D_SsfdcByte (buf++); 244 + // _Read_D_SsfdcByte (buf++); 245 + // _Read_D_SsfdcByte (buf++); 246 + // _Read_D_SsfdcByte (buf); 247 + // _Set_D_SsfdcRdStandby (); 248 + //} 249 + */ 250 + // 6250 CMD 1 251 + //----- Ssfdc_D_ReadSect() --------------------------------------------- 252 + int Ssfdc_D_ReadSect(struct us_data *us, BYTE *buf,BYTE *redundant) 253 + { 254 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 255 + int result; 256 + WORD addr; 257 + 258 + result = ENE_LoadBinCode(us, SM_RW_PATTERN); 259 + if (result != USB_STOR_XFER_GOOD) 260 + { 261 + printk("Load SM RW Code Fail !!\n"); 262 + return USB_STOR_TRANSPORT_ERROR; 263 + } 264 + 265 + addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 266 + addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 267 + 268 + // Read sect data 269 + memset(bcb, 0, sizeof(bcb)); 270 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 271 + bcb->DataTransferLength = 0x200; 272 + bcb->Flags = 0x80; 273 + bcb->CDB[0] = 0xF1; 274 + bcb->CDB[1] = 0x02; 275 + bcb->CDB[4] = (BYTE)addr; 276 + bcb->CDB[3] = (BYTE)(addr/0x0100); 277 + bcb->CDB[2] = Media.Zone/2; 278 + 279 + result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0); 280 + if (result != USB_STOR_XFER_GOOD) 281 + return USB_STOR_TRANSPORT_ERROR; 282 + 283 + // Read redundant 284 + memset(bcb, 0, sizeof(bcb)); 285 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 286 + bcb->DataTransferLength = 0x10; 287 + bcb->Flags = 0x80; 288 + bcb->CDB[0] = 0xF1; 289 + bcb->CDB[1] = 0x03; 290 + bcb->CDB[4] = (BYTE)addr; 291 + bcb->CDB[3] = (BYTE)(addr/0x0100); 292 + bcb->CDB[2] = Media.Zone/2; 293 + bcb->CDB[8] = 0; 294 + bcb->CDB[9] = 1; 295 + 296 + result = ENE_SendScsiCmd(us, FDIR_READ, redundant, 0); 297 + if (result != USB_STOR_XFER_GOOD) 298 + return USB_STOR_TRANSPORT_ERROR; 299 + 300 + return USB_STOR_TRANSPORT_GOOD; 301 + } 302 + 303 + //----- Ssfdc_D_ReadBlock() --------------------------------------------- 304 + int Ssfdc_D_ReadBlock(struct us_data *us, WORD count, BYTE *buf,BYTE *redundant) 305 + { 306 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 307 + int result; 308 + WORD addr; 309 + 310 + //printk("Ssfdc_D_ReadBlock\n"); 311 + result = ENE_LoadBinCode(us, SM_RW_PATTERN); 312 + if (result != USB_STOR_XFER_GOOD) 313 + { 314 + printk("Load SM RW Code Fail !!\n"); 315 + return USB_STOR_TRANSPORT_ERROR; 316 + } 317 + 318 + addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 319 + addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 320 + 321 + // Read sect data 322 + memset(bcb, 0, sizeof(bcb)); 323 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 324 + bcb->DataTransferLength = 0x200*count; 325 + bcb->Flags = 0x80; 326 + bcb->CDB[0] = 0xF1; 327 + bcb->CDB[1] = 0x02; 328 + bcb->CDB[4] = (BYTE)addr; 329 + bcb->CDB[3] = (BYTE)(addr/0x0100); 330 + bcb->CDB[2] = Media.Zone/2; 331 + 332 + result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0); 333 + if (result != USB_STOR_XFER_GOOD) 334 + return USB_STOR_TRANSPORT_ERROR; 335 + 336 + // Read redundant 337 + memset(bcb, 0, sizeof(bcb)); 338 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 339 + bcb->DataTransferLength = 0x10; 340 + bcb->Flags = 0x80; 341 + bcb->CDB[0] = 0xF1; 342 + bcb->CDB[1] = 0x03; 343 + bcb->CDB[4] = (BYTE)addr; 344 + bcb->CDB[3] = (BYTE)(addr/0x0100); 345 + bcb->CDB[2] = Media.Zone/2; 346 + bcb->CDB[8] = 0; 347 + bcb->CDB[9] = 1; 348 + 349 + result = ENE_SendScsiCmd(us, FDIR_READ, redundant, 0); 350 + if (result != USB_STOR_XFER_GOOD) 351 + return USB_STOR_TRANSPORT_ERROR; 352 + 353 + return USB_STOR_TRANSPORT_GOOD; 354 + } 355 + /* 356 + ////----- Ssfdc_D_ReadSect_DMA() --------------------------------------------- 357 + //int Ssfdc_D_ReadSect_DMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant) 358 + //{ 359 + // WORD SectByteCount, addr; 360 + // DWORD Buffer[4]; 361 + // WORD len; 362 + // 363 + // if (!_Hw_D_ChkCardIn()) 364 + // return(ERROR); 365 + // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 366 + // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 367 + // // cycle starting address 368 + // SM_STARTADDR_LSB = 0x00; 369 + // SM_STARTADDR_IISB = (BYTE)addr; 370 + // SM_STARTADDR_IIISB = (BYTE)(addr/0x0100); 371 + // SM_STARTADDR_MSB = Media.Zone/2; 372 + // 373 + // //Sector byte count = 0x200(DMA) 374 + // SectByteCount = 0x20f; 375 + // SM_BYTECNT_LO = (BYTE)SectByteCount; 376 + // SM_CMD_CTRL3 = (SM_CMD_CTRL3 & 0xFC) | (BYTE)(SectByteCount/0x0100); 377 + // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate ) 378 + // SM_FIFO_CTRL = (SM_APB08_MASK | SM_DMAEN_MASK | SM_DMA_UPSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK); 379 + // else 380 + // SM_FIFO_CTRL = (SM_APB32_MASK | SM_DMAEN_MASK | SM_DMA_UPSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK); 381 + // 382 + // _Hw_D_EccRdReset(); 383 + // _Hw_D_EccRdStart(); 384 + // 385 + // SM_CMD_CTRL1 = (SM_CMD_READ_1); 386 + // SM_CMD_CTRL1 = (SM_CMD_READ_1 | SM_CMD_START_BIT); 387 + // 388 + // SectByteCount = 0x1ff; 389 + // //SM_ReadDataWithDMA(fdoExt, buf, SectByteCount); 390 + // //_ReadRedt_D_SsfdcBuf(redundant); 391 + // len = 0x1000 - ((WORD)(buf) & 0x0FFF); 392 + // if (len < 0x200) 393 + // { 394 + // SM_ReadDataWithDMA(fdoExt, buf, len-1); 395 + // SM_ReadDataWithDMA(fdoExt, buf+len, SectByteCount-len); 396 + // //ENE_Print("Read DMA !!! buf1 = %p, len = %x, buf2 = %p\n", buf, len, buf+len); 397 + // } 398 + // else 399 + // SM_ReadDataWithDMA(fdoExt, buf, SectByteCount); 400 + // 401 + // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate ) 402 + // { 403 + // _ReadRedt_D_SsfdcBuf(redundant); 404 + // } 405 + // else 406 + // { 407 + // Buffer[0] = READ_PORT_DWORD(SM_REG_DATA); 408 + // Buffer[1] = READ_PORT_DWORD(SM_REG_DATA); 409 + // Buffer[2] = READ_PORT_DWORD(SM_REG_DATA); 410 + // Buffer[3] = READ_PORT_DWORD(SM_REG_DATA); 411 + // memcpy(redundant, Buffer, 0x10); 412 + // } 413 + // 414 + // while ( _Hw_D_ChkCardIn() ) 415 + // { 416 + // if((READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x10)) 417 + // { 418 + // WRITE_PORT_BYTE(SM_REG_INT_STATUS, 0x10); 419 + // break; 420 + // } 421 + // } 422 + // _Hw_D_EccRdStop(); 423 + // _Hw_D_SetRdStandby(); 424 + // _Load_D_SsfdcRdHwECC(EVEN); 425 + // 426 + // _Calc_D_ECCdata(buf); 427 + // _Set_D_SsfdcRdStandby(); 428 + // 429 + // if (!_Hw_D_ChkCardIn()) 430 + // return(ERROR); 431 + // return(SUCCESS); 432 + //} 433 + // 434 + ////----- Ssfdc_D_ReadSect_PIO() --------------------------------------------- 435 + //int Ssfdc_D_ReadSect_PIO(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant) 436 + //{ 437 + // _Set_D_SsfdcRdCmd(READ); 438 + // _Set_D_SsfdcRdAddr(EVEN); 439 + // 440 + // if (_Check_D_SsfdcBusy(BUSY_READ)) 441 + // { _Reset_D_SsfdcErr(); return(ERROR); } 442 + // 443 + // _Start_D_SsfdcRdHwECC(); 444 + // _Read_D_SsfdcBuf(buf); 445 + // _Stop_D_SsfdcRdHwECC(); 446 + // _ReadRedt_D_SsfdcBuf(redundant); 447 + // _Load_D_SsfdcRdHwECC(EVEN); 448 + // 449 + // if (_Check_D_SsfdcBusy(BUSY_READ)) 450 + // { _Reset_D_SsfdcErr(); return(ERROR); } 451 + // 452 + // _Calc_D_ECCdata(buf); 453 + // _Set_D_SsfdcRdStandby(); 454 + // return(SUCCESS); 455 + //} 456 + 457 + // 6250 CMD 3 458 + //----- Ssfdc_D_WriteSect() -------------------------------------------- 459 + int Ssfdc_D_WriteSect(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant) 460 + { 461 + PBULK_CBW pBulkCbw = fdoExt->pBulkCbw; 462 + NTSTATUS ntStatus; 463 + WORD addr; 464 + 465 + //ENE_Print("SMILSUB --- Ssfdc_D_WriteSect\n"); 466 + ENE_LoadBinCode(fdoExt, SM_RW_PATTERN); 467 + 468 + addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 469 + addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 470 + 471 + // Write sect data 472 + RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW)); 473 + pBulkCbw->dCBWSignature = CBW_SIGNTURE; 474 + pBulkCbw->bCBWLun = CBW_LUN; 475 + pBulkCbw->dCBWDataTransferLength = 0x200; 476 + pBulkCbw->bmCBWFlags = 0x00; 477 + pBulkCbw->CBWCb[0] = 0xF0; 478 + pBulkCbw->CBWCb[1] = 0x04; 479 + //pBulkCbw->CBWCb[4] = (BYTE)addr; 480 + //pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100); 481 + //pBulkCbw->CBWCb[2] = Media.Zone/2; 482 + //pBulkCbw->CBWCb[5] = *(redundant+REDT_ADDR1H); 483 + //pBulkCbw->CBWCb[6] = *(redundant+REDT_ADDR1L); 484 + pBulkCbw->CBWCb[7] = (BYTE)addr; 485 + pBulkCbw->CBWCb[6] = (BYTE)(addr/0x0100); 486 + pBulkCbw->CBWCb[5] = Media.Zone/2; 487 + pBulkCbw->CBWCb[8] = *(redundant+REDT_ADDR1H); 488 + pBulkCbw->CBWCb[9] = *(redundant+REDT_ADDR1L); 489 + 490 + ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_WRITE, buf); 491 + 492 + if (!NT_SUCCESS(ntStatus)) 493 + return(ERROR); 494 + 495 + // // For Test 496 + // { 497 + // BYTE bf[0x200], rdd[0x10]; 498 + // ULONG i; 499 + // 500 + // RtlZeroMemory(bf, 0x200); 501 + // RtlZeroMemory(rdd, 0x10); 502 + // ntStatus = SM_ReadBlock(fdoExt, bf, rdd); 503 + // for (i=0; i<0x200; i++) 504 + // { 505 + // if (buf[i] != bf[i]) 506 + // ENE_Print("buf[%x] = %x, bf[%x] = %x\n", buf, bf); 507 + // } 508 + // if (!NT_SUCCESS(ntStatus)) 509 + // ENE_Print("Error\n"); 510 + // } 511 + 512 + return(SUCCESS); 513 + } 514 + */ 515 + //----- Ssfdc_D_CopyBlock() -------------------------------------------- 516 + int Ssfdc_D_CopyBlock(struct us_data *us, WORD count, BYTE *buf,BYTE *redundant) 517 + { 518 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 519 + int result; 520 + //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw; 521 + //NTSTATUS ntStatus; 522 + WORD ReadAddr, WriteAddr; 523 + 524 + //printk("Ssfdc_D_WriteSect --- ZONE = %x, ReadBlock = %x, WriteBlock = %x\n", Media.Zone, ReadBlock, WriteBlock); 525 + 526 + result = ENE_LoadBinCode(us, SM_RW_PATTERN); 527 + if (result != USB_STOR_XFER_GOOD) 528 + { 529 + printk("Load SM RW Code Fail !!\n"); 530 + return USB_STOR_TRANSPORT_ERROR; 531 + } 532 + 533 + ReadAddr = (WORD)Media.Zone*Ssfdc.MaxBlocks+ReadBlock; 534 + ReadAddr = ReadAddr*(WORD)Ssfdc.MaxSectors; 535 + WriteAddr = (WORD)Media.Zone*Ssfdc.MaxBlocks+WriteBlock; 536 + WriteAddr = WriteAddr*(WORD)Ssfdc.MaxSectors; 537 + 538 + // Write sect data 539 + memset(bcb, 0, sizeof(bcb)); 540 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 541 + bcb->DataTransferLength = 0x200*count; 542 + bcb->Flags = 0x00; 543 + bcb->CDB[0] = 0xF0; 544 + bcb->CDB[1] = 0x08; 545 + bcb->CDB[7] = (BYTE)WriteAddr; 546 + bcb->CDB[6] = (BYTE)(WriteAddr/0x0100); 547 + bcb->CDB[5] = Media.Zone/2; 548 + bcb->CDB[8] = *(redundant+REDT_ADDR1H); 549 + bcb->CDB[9] = *(redundant+REDT_ADDR1L); 550 + bcb->CDB[10] = Media.Sector; 551 + 552 + if (ReadBlock != NO_ASSIGN) 553 + { 554 + bcb->CDB[4] = (BYTE)ReadAddr; 555 + bcb->CDB[3] = (BYTE)(ReadAddr/0x0100); 556 + bcb->CDB[2] = Media.Zone/2; 557 + } 558 + else 559 + bcb->CDB[11] = 1; 560 + 561 + result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0); 562 + if (result != USB_STOR_XFER_GOOD) 563 + return USB_STOR_TRANSPORT_ERROR; 564 + 565 + return USB_STOR_TRANSPORT_GOOD; 566 + } 567 + /* 568 + //----- Ssfdc_D_WriteBlock() -------------------------------------------- 569 + int Ssfdc_D_WriteBlock(PFDO_DEVICE_EXTENSION fdoExt, WORD count, BYTE *buf,BYTE *redundant) 570 + { 571 + PBULK_CBW pBulkCbw = fdoExt->pBulkCbw; 572 + NTSTATUS ntStatus; 573 + WORD addr; 574 + 575 + //ENE_Print("SMILSUB --- Ssfdc_D_WriteSect\n"); 576 + ENE_LoadBinCode(fdoExt, SM_RW_PATTERN); 577 + 578 + addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 579 + addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 580 + 581 + // Write sect data 582 + RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW)); 583 + pBulkCbw->dCBWSignature = CBW_SIGNTURE; 584 + pBulkCbw->bCBWLun = CBW_LUN; 585 + pBulkCbw->dCBWDataTransferLength = 0x200*count; 586 + pBulkCbw->bmCBWFlags = 0x00; 587 + pBulkCbw->CBWCb[0] = 0xF0; 588 + pBulkCbw->CBWCb[1] = 0x04; 589 + pBulkCbw->CBWCb[7] = (BYTE)addr; 590 + pBulkCbw->CBWCb[6] = (BYTE)(addr/0x0100); 591 + pBulkCbw->CBWCb[5] = Media.Zone/2; 592 + pBulkCbw->CBWCb[8] = *(redundant+REDT_ADDR1H); 593 + pBulkCbw->CBWCb[9] = *(redundant+REDT_ADDR1L); 594 + 595 + ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_WRITE, buf); 596 + 597 + if (!NT_SUCCESS(ntStatus)) 598 + return(ERROR); 599 + 600 + // // For Test 601 + // { 602 + // BYTE bf[0x200], rdd[0x10]; 603 + // ULONG i; 604 + // 605 + // RtlZeroMemory(bf, 0x200); 606 + // RtlZeroMemory(rdd, 0x10); 607 + // ntStatus = SM_ReadBlock(fdoExt, bf, rdd); 608 + // for (i=0; i<0x200; i++) 609 + // { 610 + // if (buf[i] != bf[i]) 611 + // ENE_Print("buf[%x] = %x, bf[%x] = %x\n", buf, bf); 612 + // } 613 + // if (!NT_SUCCESS(ntStatus)) 614 + // ENE_Print("Error\n"); 615 + // } 616 + 617 + return(SUCCESS); 618 + } 619 + // 620 + ////----- Ssfdc_D_WriteSect_DMA() -------------------------------------------- 621 + //int Ssfdc_D_WriteSect_DMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant) 622 + //{ 623 + // WORD SectByteCount, addr; 624 + // DWORD Buffer[4]; 625 + // WORD len; 626 + // 627 + // if (!_Hw_D_ChkCardIn()) 628 + // return(ERROR); 629 + // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 630 + // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 631 + // // cycle starting address 632 + // SM_STARTADDR_LSB = 0x00; 633 + // SM_STARTADDR_IISB = (BYTE)addr; 634 + // SM_STARTADDR_IIISB = (BYTE)(addr/0x0100); 635 + // SM_STARTADDR_MSB = Media.Zone/2; 636 + // 637 + // //Sector byte count (DMA) 638 + // SectByteCount = 0x20f; 639 + // SM_BYTECNT_LO = (BYTE)SectByteCount; 640 + // SM_CMD_CTRL3 = (SM_CMD_CTRL3 & 0xFC) | 0x20 | (BYTE)(SectByteCount/0x0100); 641 + // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate ) 642 + // SM_FIFO_CTRL = (SM_APB08_MASK | SM_DMAEN_MASK | SM_DMA_DOWNSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK); 643 + // else 644 + // SM_FIFO_CTRL = (SM_APB32_MASK | SM_DMAEN_MASK | SM_DMA_DOWNSTREAM_MASK | SM_FIFOSHLDVLU_8_MASK); 645 + // 646 + // _Hw_D_EccRdReset(); 647 + // _Hw_D_EccRdStart(); 648 + // 649 + // SM_CMD_CTRL1 = SM_CMD_PAGPRGM_TRUE; 650 + // SM_CMD_CTRL1 = (SM_CMD_PAGPRGM_TRUE | SM_CMD_START_BIT); 651 + // 652 + // SectByteCount = 0x1ff; 653 + // //SM_WriteDataWithDMA(fdoExt, buf, SectByteCount); 654 + // //_WriteRedt_D_SsfdcBuf(redundant); 655 + // len = 0x1000 - ((WORD)(buf) & 0x0FFF); 656 + // if (len < 0x200) 657 + // { 658 + // SM_WriteDataWithDMA(fdoExt, buf, len-1); 659 + // SM_WriteDataWithDMA(fdoExt, buf+len, SectByteCount-len); 660 + // //ENE_Print("Read DMA !!! buf1 = %p, len = %x, buf2 = %p\n", buf, len, buf+len); 661 + // } 662 + // else 663 + // SM_WriteDataWithDMA(fdoExt, buf, SectByteCount); 664 + // 665 + // //T1 = (ULONGLONG)buf & 0xFFFFFFFFFFFFF000; 666 + // //T2 = ((ULONGLONG)buf + 0x1FF) & 0xFFFFFFFFFFFFF000; 667 + // //if (T1 != T2) 668 + // // ENE_Print("Ssfdc_D_WriteSect_DMA !!! buf = %p, T1 = %p, T2 = %p\n", buf, T1, T2); 669 + // //if (T2-T1) 670 + // //{ 671 + // // l1 = (WORD)(T2 - (ULONGLONG)buf); 672 + // // SM_WriteDataWithDMA(fdoExt, buf, l1-1); 673 + // // SM_WriteDataWithDMA(fdoExt, (PBYTE)T2, SectByteCount-l1); 674 + // //} 675 + // //else 676 + // // SM_WriteDataWithDMA(fdoExt, buf, SectByteCount); 677 + // 678 + // if ( ((fdoExt->ChipID==READER_CB712)&&(fdoExt->RevID==CHIP_A)) || fdoExt->IsHibernate ) 679 + // { 680 + // _WriteRedt_D_SsfdcBuf(redundant); 681 + // } 682 + // else 683 + // { 684 + // memcpy(Buffer, redundant, 0x10); 685 + // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[0]); 686 + // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[1]); 687 + // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[2]); 688 + // WRITE_PORT_DWORD(SM_REG_DATA, Buffer[3]); 689 + // } 690 + // 691 + // while ( _Hw_D_ChkCardIn() ) 692 + // { 693 + // if ((READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x10)) 694 + // { 695 + // WRITE_PORT_BYTE(SM_REG_INT_STATUS, 0x10); 696 + // break; 697 + // } 698 + // } 699 + // _Hw_D_EccRdStop(); 700 + // _Hw_D_SetRdStandby(); 701 + // 702 + // _Set_D_SsfdcWrStandby(); 703 + // _Set_D_SsfdcRdStandby(); 704 + // if (!_Hw_D_ChkCardIn()) 705 + // return(ERROR); 706 + // 707 + // return(SUCCESS); 708 + //} 709 + // 710 + ////----- Ssfdc_D_WriteSect_PIO() -------------------------------------------- 711 + //int Ssfdc_D_WriteSect_PIO(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant) 712 + //{ 713 + // _Calc_D_ECCdata(buf); 714 + // _Set_D_SsfdcWrCmd(WRDATA); 715 + // _Set_D_SsfdcWrAddr(EVEN); 716 + // _Start_D_SsfdcWrHwECC(); 717 + // 718 + // _Write_D_SsfdcBuf(buf); 719 + // 720 + // _Load_D_SsfdcWrHwECC(EVEN); 721 + // _Set_D_ECCdata(EVEN,redundant); 722 + // 723 + // _WriteRedt_D_SsfdcBuf(redundant); 724 + // 725 + // _Set_D_SsfdcWrCmd(WRITE); 726 + // 727 + // if (_Check_D_SsfdcBusy(BUSY_PROG)) 728 + // { _Reset_D_SsfdcErr(); return(ERROR); } 729 + // 730 + // _Set_D_SsfdcWrStandby(); 731 + // _Set_D_SsfdcRdStandby(); 732 + // return(SUCCESS); 733 + //} 734 + */ 735 + //----- Ssfdc_D_WriteSectForCopy() ------------------------------------- 736 + int Ssfdc_D_WriteSectForCopy(struct us_data *us, BYTE *buf, BYTE *redundant) 737 + { 738 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 739 + int result; 740 + //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw; 741 + //NTSTATUS ntStatus; 742 + WORD addr; 743 + 744 + //printk("SMILSUB --- Ssfdc_D_WriteSectForCopy\n"); 745 + result = ENE_LoadBinCode(us, SM_RW_PATTERN); 746 + if (result != USB_STOR_XFER_GOOD) 747 + { 748 + printk("Load SM RW Code Fail !!\n"); 749 + return USB_STOR_TRANSPORT_ERROR; 750 + } 751 + 752 + 753 + addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 754 + addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 755 + 756 + // Write sect data 757 + memset(bcb, 0, sizeof(bcb)); 758 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 759 + bcb->DataTransferLength = 0x200; 760 + bcb->Flags = 0x00; 761 + bcb->CDB[0] = 0xF0; 762 + bcb->CDB[1] = 0x04; 763 + bcb->CDB[7] = (BYTE)addr; 764 + bcb->CDB[6] = (BYTE)(addr/0x0100); 765 + bcb->CDB[5] = Media.Zone/2; 766 + bcb->CDB[8] = *(redundant+REDT_ADDR1H);; 767 + bcb->CDB[9] = *(redundant+REDT_ADDR1L);; 768 + 769 + result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0); 770 + if (result != USB_STOR_XFER_GOOD) 771 + return USB_STOR_TRANSPORT_ERROR; 772 + 773 + return USB_STOR_TRANSPORT_GOOD; 774 + } 775 + 776 + // 6250 CMD 5 777 + //----- Ssfdc_D_EraseBlock() ------------------------------------------- 778 + int Ssfdc_D_EraseBlock(struct us_data *us) 779 + { 780 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 781 + int result; 782 + WORD addr; 783 + 784 + result = ENE_LoadBinCode(us, SM_RW_PATTERN); 785 + if (result != USB_STOR_XFER_GOOD) 786 + { 787 + printk("Load SM RW Code Fail !!\n"); 788 + return USB_STOR_TRANSPORT_ERROR; 789 + } 790 + 791 + addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 792 + addr=addr*(WORD)Ssfdc.MaxSectors; 793 + 794 + memset(bcb, 0, sizeof(bcb)); 795 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 796 + bcb->DataTransferLength = 0x200; 797 + bcb->Flags = 0x80; 798 + bcb->CDB[0] = 0xF2; 799 + bcb->CDB[1] = 0x06; 800 + bcb->CDB[7] = (BYTE)addr; 801 + bcb->CDB[6] = (BYTE)(addr/0x0100); 802 + bcb->CDB[5] = Media.Zone/2; 803 + 804 + result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0); 805 + if (result != USB_STOR_XFER_GOOD) 806 + return USB_STOR_TRANSPORT_ERROR; 807 + 808 + return USB_STOR_TRANSPORT_GOOD; 809 + } 810 + 811 + // 6250 CMD 2 812 + //----- Ssfdc_D_ReadRedtData() ----------------------------------------- 813 + int Ssfdc_D_ReadRedtData(struct us_data *us, BYTE *redundant) 814 + { 815 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 816 + int result; 817 + WORD addr; 818 + BYTE *buf; 819 + 820 + result = ENE_LoadBinCode(us, SM_RW_PATTERN); 821 + if (result != USB_STOR_XFER_GOOD) 822 + { 823 + printk("Load SM RW Code Fail !!\n"); 824 + return USB_STOR_TRANSPORT_ERROR; 825 + } 826 + 827 + addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 828 + addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 829 + 830 + memset(bcb, 0, sizeof(bcb)); 831 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 832 + bcb->DataTransferLength = 0x10; 833 + bcb->Flags = 0x80; 834 + bcb->CDB[0] = 0xF1; 835 + bcb->CDB[1] = 0x03; 836 + bcb->CDB[4] = (BYTE)addr; 837 + bcb->CDB[3] = (BYTE)(addr/0x0100); 838 + bcb->CDB[2] = Media.Zone/2; 839 + bcb->CDB[8] = 0; 840 + bcb->CDB[9] = 1; 841 + 842 + buf = kmalloc(0x10, GFP_KERNEL); 843 + //result = ENE_SendScsiCmd(us, FDIR_READ, redundant, 0); 844 + result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0); 845 + memcpy(redundant, buf, 0x10); 846 + kfree(buf); 847 + if (result != USB_STOR_XFER_GOOD) 848 + return USB_STOR_TRANSPORT_ERROR; 849 + 850 + return USB_STOR_TRANSPORT_GOOD; 851 + } 852 + 853 + // 6250 CMD 4 854 + //----- Ssfdc_D_WriteRedtData() ---------------------------------------- 855 + int Ssfdc_D_WriteRedtData(struct us_data *us, BYTE *redundant) 856 + { 857 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 858 + int result; 859 + //PBULK_CBW pBulkCbw = fdoExt->pBulkCbw; 860 + //NTSTATUS ntStatus; 861 + WORD addr; 862 + 863 + result = ENE_LoadBinCode(us, SM_RW_PATTERN); 864 + if (result != USB_STOR_XFER_GOOD) 865 + { 866 + printk("Load SM RW Code Fail !!\n"); 867 + return USB_STOR_TRANSPORT_ERROR; 868 + } 869 + 870 + addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 871 + addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 872 + 873 + memset(bcb, 0, sizeof(bcb)); 874 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 875 + bcb->DataTransferLength = 0x10; 876 + bcb->Flags = 0x80; 877 + bcb->CDB[0] = 0xF2; 878 + bcb->CDB[1] = 0x05; 879 + bcb->CDB[7] = (BYTE)addr; 880 + bcb->CDB[6] = (BYTE)(addr/0x0100); 881 + bcb->CDB[5] = Media.Zone/2; 882 + bcb->CDB[8] = *(redundant+REDT_ADDR1H); 883 + bcb->CDB[9] = *(redundant+REDT_ADDR1L); 884 + 885 + result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0); 886 + if (result != USB_STOR_XFER_GOOD) 887 + return USB_STOR_TRANSPORT_ERROR; 888 + 889 + return USB_STOR_TRANSPORT_GOOD; 890 + } 891 + 892 + //----- Ssfdc_D_CheckStatus() ------------------------------------------ 893 + int Ssfdc_D_CheckStatus(void) 894 + { 895 + // Driver ���� 896 + return(SUCCESS); 897 + //_Set_D_SsfdcRdCmd(RDSTATUS); 898 + // 899 + //if (_Check_D_SsfdcStatus()) 900 + //{ _Set_D_SsfdcRdStandby(); return(ERROR); } 901 + // 902 + //_Set_D_SsfdcRdStandby(); 903 + //return(SUCCESS); 904 + } 905 + /* 906 + ////NAND Memory (SmartMedia) Control Subroutine for Read Data 907 + ////----- _Set_D_SsfdcRdCmd() -------------------------------------------- 908 + //void _Set_D_SsfdcRdCmd(BYTE cmd) 909 + //{ 910 + // _Hw_D_SetRdCmd(); 911 + // _Hw_D_OutData(cmd); 912 + // _Hw_D_SetRdData(); 913 + //} 914 + // 915 + ////----- _Set_D_SsfdcRdAddr() ------------------------------------------- 916 + //void _Set_D_SsfdcRdAddr(BYTE add) 917 + //{ 918 + // WORD addr; 919 + // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 920 + // ADDRESS_T bb = (ADDRESS_T) &Media; 921 + // 922 + // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 923 + // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 924 + // 925 + // //if ((Ssfdc.Attribute &MPS)==PS256) // for 256byte/page 926 + // // addr=addr*2+(WORD)add; 927 + // 928 + // _Hw_D_SetRdAddr(); 929 + // _Hw_D_OutData(0x00); 930 + // _Hw_D_OutData((BYTE)addr); 931 + // _Hw_D_OutData((BYTE)(addr/0x0100)); 932 + // 933 + // if ((Ssfdc.Attribute &MADC)==AD4CYC) 934 + // _Hw_D_OutData((BYTE)(Media.Zone/2)); // Patch 935 + // 936 + // _Hw_D_SetRdData(); 937 + //} 938 + // 939 + ////----- _Set_D_SsfdcRdChip() ------------------------------------------- 940 + //void _Set_D_SsfdcRdChip(void) 941 + //{ 942 + // _Hw_D_SetRdAddr(); 943 + // _Hw_D_OutData(0x00); 944 + // _Hw_D_SetRdData(); 945 + //} 946 + // 947 + ////----- _Set_D_SsfdcRdStandby() ---------------------------------------- 948 + //void _Set_D_SsfdcRdStandby(void) 949 + //{ 950 + // _Hw_D_SetRdStandby(); 951 + //} 952 + // 953 + ////----- _Start_D_SsfdcRdHwECC() ---------------------------------------- 954 + //void _Start_D_SsfdcRdHwECC(void) 955 + //{ 956 + //#ifdef HW_ECC_SUPPORTED 957 + // _Hw_D_EccRdReset(); 958 + // _Hw_D_InData(); 959 + // _Hw_D_EccRdStart(); 960 + //#endif 961 + //} 962 + // 963 + ////----- _Stop_D_SsfdcRdHwECC() ----------------------------------------- 964 + //void _Stop_D_SsfdcRdHwECC(void) 965 + //{ 966 + //#ifdef HW_ECC_SUPPORTED 967 + // _Hw_D_EccRdStop(); 968 + //#endif 969 + //} 970 + // 971 + ////----- _Load_D_SsfdcRdHwECC() ----------------------------------------- 972 + //void _Load_D_SsfdcRdHwECC(BYTE add) 973 + //{ 974 + //#ifdef HW_ECC_SUPPORTED 975 + // _Hw_D_EccRdRead(); 976 + // //if (!(add==ODD && (Ssfdc.Attribute &MPS)==PS256)) 977 + // { 978 + // EccBuf[0]=_Hw_D_InData(); 979 + // EccBuf[1]=_Hw_D_InData(); 980 + // EccBuf[2]=_Hw_D_InData(); 981 + // } 982 + // 983 + // //if (!(add==EVEN && (Ssfdc.Attribute &MPS)==PS256)) 984 + // { 985 + // EccBuf[3]=_Hw_D_InData(); 986 + // EccBuf[4]=_Hw_D_InData(); 987 + // EccBuf[5]=_Hw_D_InData(); 988 + // } 989 + // 990 + // _Hw_D_EccRdStop(); 991 + //#endif 992 + //} 993 + // 994 + ////NAND Memory (SmartMedia) Control Subroutine for Write Data 995 + // 996 + ////----- _Set_D_SsfdcWrCmd() ----------------------------------------- 997 + //void _Set_D_SsfdcWrCmd(BYTE cmd) 998 + //{ 999 + // _Hw_D_SetWrCmd(); 1000 + // _Hw_D_OutData(cmd); 1001 + // _Hw_D_SetWrData(); 1002 + //} 1003 + // 1004 + ////----- _Set_D_SsfdcWrAddr() ----------------------------------------- 1005 + //void _Set_D_SsfdcWrAddr(BYTE add) 1006 + //{ 1007 + // WORD addr; 1008 + // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1009 + // ADDRESS_T bb = (ADDRESS_T) &Media; 1010 + // 1011 + // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 1012 + // addr=addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 1013 + // 1014 + // //if ((Ssfdc.Attribute &MPS)==PS256) // for 256byte/page 1015 + // // addr=addr*2+(WORD)add; 1016 + // 1017 + // _Hw_D_SetWrAddr(); 1018 + // _Hw_D_OutData(0x00); 1019 + // _Hw_D_OutData((BYTE)addr); 1020 + // _Hw_D_OutData((BYTE)(addr/0x0100)); 1021 + // 1022 + // if ((Ssfdc.Attribute &MADC)==AD4CYC) 1023 + // _Hw_D_OutData((BYTE)(Media.Zone/2)); // Patch 1024 + // 1025 + // _Hw_D_SetWrData(); 1026 + //} 1027 + // 1028 + ////----- _Set_D_SsfdcWrBlock() ----------------------------------------- 1029 + //void _Set_D_SsfdcWrBlock(void) 1030 + //{ 1031 + // WORD addr; 1032 + // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc; 1033 + // ADDRESS_T bb = (ADDRESS_T) &Media; 1034 + // 1035 + // addr=(WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 1036 + // addr=addr*(WORD)Ssfdc.MaxSectors; 1037 + // 1038 + // //if ((Ssfdc.Attribute &MPS)==PS256) // for 256byte/page 1039 + // // addr=addr*2; 1040 + // 1041 + // _Hw_D_SetWrAddr(); 1042 + // _Hw_D_OutData((BYTE)addr); 1043 + // _Hw_D_OutData((BYTE)(addr/0x0100)); 1044 + // 1045 + // if ((Ssfdc.Attribute &MADC)==AD4CYC) 1046 + // _Hw_D_OutData((BYTE)(Media.Zone/2)); // Patch 1047 + // 1048 + // _Hw_D_SetWrData(); 1049 + //} 1050 + // 1051 + ////----- _Set_D_SsfdcWrStandby() ----------------------------------------- 1052 + //void _Set_D_SsfdcWrStandby(void) 1053 + //{ 1054 + // _Hw_D_SetWrStandby(); 1055 + //} 1056 + // 1057 + ////----- _Start_D_SsfdcWrHwECC() ----------------------------------------- 1058 + //void _Start_D_SsfdcWrHwECC(void) 1059 + //{ 1060 + //#ifdef HW_ECC_SUPPORTED 1061 + // _Hw_D_EccWrReset(); 1062 + // _Hw_D_InData(); 1063 + // _Hw_D_EccWrStart(); 1064 + //#endif 1065 + //} 1066 + // 1067 + ////----- _Load_D_SsfdcWrHwECC() ----------------------------------------- 1068 + //void _Load_D_SsfdcWrHwECC(BYTE add) 1069 + //{ 1070 + //#ifdef HW_ECC_SUPPORTED 1071 + // _Hw_D_EccWrRead(); 1072 + // //if (!(add==ODD && (Ssfdc.Attribute &MPS)==PS256)) 1073 + // { 1074 + // EccBuf[0]=_Hw_D_InData(); 1075 + // EccBuf[1]=_Hw_D_InData(); 1076 + // EccBuf[2]=_Hw_D_InData(); 1077 + // } 1078 + // 1079 + // //if (!(add==EVEN && (Ssfdc.Attribute &MPS)==PS256)) 1080 + // { 1081 + // EccBuf[3]=_Hw_D_InData(); 1082 + // EccBuf[4]=_Hw_D_InData(); 1083 + // EccBuf[5]=_Hw_D_InData(); 1084 + // } 1085 + // 1086 + // _Hw_D_EccWrStop(); 1087 + //#endif 1088 + //} 1089 + // 1090 + ////NAND Memory (SmartMedia) Control Subroutine 1091 + ////----- _Check_D_SsfdcBusy() ------------------------------------------- 1092 + //int _Check_D_SsfdcBusy(WORD time) 1093 + //{ 1094 + // WORD count = 0; 1095 + // 1096 + // do { 1097 + // if (!_Hw_D_ChkBusy()) 1098 + // return(SUCCESS); 1099 + // EDelay(100); 1100 + // count++; 1101 + // } while (count<=time); 1102 + // 1103 + // return(ERROR); 1104 + //} 1105 + // 1106 + ////----- _Check_D_SsfdcStatus() ----------------------------------------- 1107 + //int _Check_D_SsfdcStatus(void) 1108 + //{ 1109 + // if (_Hw_D_InData() & WR_FAIL) 1110 + // return(ERROR); 1111 + // 1112 + // return(SUCCESS); 1113 + //} 1114 + // 1115 + //// For 712 1116 + ////----- _Reset_D_SsfdcErr() ----------------------------------------- 1117 + //void _Reset_D_SsfdcErr(void) 1118 + //{ 1119 + // WORD count = 0; 1120 + // 1121 + // _Hw_D_SetRdCmd(); 1122 + // _Hw_D_OutData(RST_CHIP); 1123 + // _Hw_D_SetRdData(); 1124 + // 1125 + // do { 1126 + // if (!_Hw_D_ChkBusy()) 1127 + // break; 1128 + // EDelay(100); 1129 + // count++; 1130 + // } while (count<=BUSY_RESET); 1131 + // 1132 + // _Hw_D_SetRdStandby(); 1133 + //} 1134 + // 1135 + ////NAND Memory (SmartMedia) Buffer Data Xfer Subroutine 1136 + ////----- SM_ReadDataWithDMA() ----------------------------------------- 1137 + //void SM_ReadDataWithDMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *databuf, WORD SectByteCount) 1138 + //{ 1139 + // PHYSICAL_ADDRESS Addr; 1140 + // LARGE_INTEGER ptimeout ; 1141 + // 1142 + // KeClearEvent(&fdoExt->SM_DMADoneEvent); 1143 + // 1144 + // Addr = MmGetPhysicalAddress(databuf); 1145 + // 1146 + // WRITE_PORT_DWORD(SM_DMA_ADDR_REG, (DWORD)Addr.LowPart); 1147 + // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 0); 1148 + // WRITE_PORT_WORD(SM_DMA_BYTE_COUNT_REG, SectByteCount); 1149 + // 1150 + // while ( _Hw_D_ChkCardIn() ) 1151 + // { 1152 + // if ((READ_PORT_BYTE(SM_REG_FIFO_STATUS) & 0x80)) 1153 + // break; 1154 + // } 1155 + // if (!_Hw_D_ChkCardIn()) return; 1156 + // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 0x01); 1157 + // 1158 + // ptimeout.QuadPart = 2000 * (-10000); // 2 sec 1159 + // KeWaitForSingleObject(&fdoExt->SM_DMADoneEvent, Executive, KernelMode, FALSE, &ptimeout); 1160 + // _Hw_D_SetDMAIntMask(); 1161 + //} 1162 + // 1163 + ////----- SM_WriteDataWithDMA() ----------------------------------------- 1164 + //void SM_WriteDataWithDMA(PFDO_DEVICE_EXTENSION fdoExt, BYTE *databuf, WORD SectByteCount) 1165 + //{ 1166 + // PHYSICAL_ADDRESS Addr; 1167 + // LARGE_INTEGER ptimeout ; 1168 + // 1169 + // KeClearEvent(&fdoExt->SM_DMADoneEvent); 1170 + // 1171 + // Addr = MmGetPhysicalAddress(databuf); 1172 + // 1173 + // WRITE_PORT_DWORD(SM_DMA_ADDR_REG, (DWORD)Addr.LowPart); 1174 + // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 2); 1175 + // WRITE_PORT_WORD(SM_DMA_BYTE_COUNT_REG, SectByteCount); 1176 + // 1177 + // while ( _Hw_D_ChkCardIn() ) 1178 + // { 1179 + // if ((READ_PORT_BYTE(SM_REG_FIFO_STATUS) & 0x40)) 1180 + // break; 1181 + // } 1182 + // if (!_Hw_D_ChkCardIn()) return; 1183 + // WRITE_PORT_BYTE(SM_DMA_DATA_CTRL, 0x03); 1184 + // 1185 + // ptimeout.QuadPart = 2000 * (-10000); // 2 sec 1186 + // KeWaitForSingleObject(&fdoExt->SM_DMADoneEvent, Executive, KernelMode, FALSE, &ptimeout); 1187 + // _Hw_D_SetDMAIntMask(); 1188 + //} 1189 + // 1190 + ////----- _Read_D_SsfdcBuf() ----------------------------------------- 1191 + //void _Read_D_SsfdcBuf(BYTE *databuf) 1192 + //{ 1193 + // int i; 1194 + // 1195 + // //for(i=0x0000;i<(((Ssfdc.Attribute &MPS)==PS256)?0x0100:0x0200);i++) 1196 + // for(i=0; i<0x200; i++) 1197 + // *databuf++ =_Hw_D_InData(); 1198 + //} 1199 + // 1200 + ////----- _Write_D_SsfdcBuf() ----------------------------------------- 1201 + //void _Write_D_SsfdcBuf(BYTE *databuf) 1202 + //{ 1203 + // int i; 1204 + // 1205 + // //for(i=0x0000;i<(((Ssfdc.Attribute &MPS)==PS256)?0x0100:0x0200);i++) 1206 + // for(i=0; i<0x200; i++) 1207 + // _Hw_D_OutData(*databuf++); 1208 + //} 1209 + // 1210 + ////----- _Read_D_SsfdcByte() ----------------------------------------- 1211 + //void _Read_D_SsfdcByte(BYTE *databuf) 1212 + //{ 1213 + // *databuf=(BYTE)_Hw_D_InData(); 1214 + //} 1215 + // 1216 + ////----- _ReadRedt_D_SsfdcBuf() ----------------------------------------- 1217 + //void _ReadRedt_D_SsfdcBuf(BYTE *redundant) 1218 + //{ 1219 + // char i; 1220 + // 1221 + // //for(i=0x00;i<(((Ssfdc.Attribute &MPS)==PS256)?0x08:0x10);i++) 1222 + // for(i=0; i<0x10; i++) 1223 + // redundant[i] =_Hw_D_InData(); 1224 + //} 1225 + // 1226 + ////----- _WriteRedt_D_SsfdcBuf() ----------------------------------------- 1227 + //void _WriteRedt_D_SsfdcBuf(BYTE *redundant) 1228 + //{ 1229 + // char i; 1230 + // 1231 + // //for(i=0x00;i<(((Ssfdc.Attribute &MPS)==PS256)?0x08:0x10);i++) 1232 + // for(i=0; i<0x10; i++) 1233 + // _Hw_D_OutData(*redundant++); 1234 + //} 1235 + */ 1236 + //SmartMedia ID Code Check & Mode Set Subroutine 1237 + //----- Set_D_SsfdcModel() --------------------------------------------- 1238 + int Set_D_SsfdcModel(BYTE dcode) 1239 + { 1240 + switch (_Check_D_DevCode(dcode)) { 1241 + case SSFDC1MB: 1242 + Ssfdc.Model = SSFDC1MB; 1243 + Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS256; 1244 + Ssfdc.MaxZones = 1; 1245 + Ssfdc.MaxBlocks = 256; 1246 + Ssfdc.MaxLogBlocks = 250; 1247 + Ssfdc.MaxSectors = 8; 1248 + break; 1249 + case SSFDC2MB: 1250 + Ssfdc.Model = SSFDC2MB; 1251 + Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS256; 1252 + Ssfdc.MaxZones = 1; 1253 + Ssfdc.MaxBlocks = 512; 1254 + Ssfdc.MaxLogBlocks = 500; 1255 + Ssfdc.MaxSectors = 8; 1256 + break; 1257 + case SSFDC4MB: 1258 + Ssfdc.Model = SSFDC4MB; 1259 + Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS512; 1260 + Ssfdc.MaxZones = 1; 1261 + Ssfdc.MaxBlocks = 512; 1262 + Ssfdc.MaxLogBlocks = 500; 1263 + Ssfdc.MaxSectors = 16; 1264 + break; 1265 + case SSFDC8MB: 1266 + Ssfdc.Model = SSFDC8MB; 1267 + Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS512; 1268 + Ssfdc.MaxZones = 1; 1269 + Ssfdc.MaxBlocks = 1024; 1270 + Ssfdc.MaxLogBlocks = 1000; 1271 + Ssfdc.MaxSectors = 16; 1272 + break; 1273 + case SSFDC16MB: 1274 + Ssfdc.Model = SSFDC16MB; 1275 + Ssfdc.Attribute = FLASH | AD3CYC | BS32 | PS512; 1276 + Ssfdc.MaxZones = 1; 1277 + Ssfdc.MaxBlocks = 1024; 1278 + Ssfdc.MaxLogBlocks = 1000; 1279 + Ssfdc.MaxSectors = 32; 1280 + break; 1281 + case SSFDC32MB: 1282 + Ssfdc.Model = SSFDC32MB; 1283 + Ssfdc.Attribute = FLASH | AD3CYC | BS32 | PS512; 1284 + Ssfdc.MaxZones = 2; 1285 + Ssfdc.MaxBlocks = 1024; 1286 + Ssfdc.MaxLogBlocks = 1000; 1287 + Ssfdc.MaxSectors = 32; 1288 + break; 1289 + case SSFDC64MB: 1290 + Ssfdc.Model = SSFDC64MB; 1291 + Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; 1292 + Ssfdc.MaxZones = 4; 1293 + Ssfdc.MaxBlocks = 1024; 1294 + Ssfdc.MaxLogBlocks = 1000; 1295 + Ssfdc.MaxSectors = 32; 1296 + break; 1297 + case SSFDC128MB: 1298 + Ssfdc.Model = SSFDC128MB; 1299 + Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; 1300 + Ssfdc.MaxZones = 8; 1301 + Ssfdc.MaxBlocks = 1024; 1302 + Ssfdc.MaxLogBlocks = 1000; 1303 + Ssfdc.MaxSectors = 32; 1304 + break; 1305 + case SSFDC256MB: 1306 + Ssfdc.Model = SSFDC256MB; 1307 + Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; 1308 + Ssfdc.MaxZones = 16; 1309 + Ssfdc.MaxBlocks = 1024; 1310 + Ssfdc.MaxLogBlocks = 1000; 1311 + Ssfdc.MaxSectors = 32; 1312 + break; 1313 + case SSFDC512MB: 1314 + Ssfdc.Model = SSFDC512MB; 1315 + Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; 1316 + Ssfdc.MaxZones = 32; 1317 + Ssfdc.MaxBlocks = 1024; 1318 + Ssfdc.MaxLogBlocks = 1000; 1319 + Ssfdc.MaxSectors = 32; 1320 + break; 1321 + case SSFDC1GB: 1322 + Ssfdc.Model = SSFDC1GB; 1323 + Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; 1324 + Ssfdc.MaxZones = 64; 1325 + Ssfdc.MaxBlocks = 1024; 1326 + Ssfdc.MaxLogBlocks = 1000; 1327 + Ssfdc.MaxSectors = 32; 1328 + break; 1329 + case SSFDC2GB: 1330 + Ssfdc.Model = SSFDC2GB; 1331 + Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; 1332 + Ssfdc.MaxZones = 128; 1333 + Ssfdc.MaxBlocks = 1024; 1334 + Ssfdc.MaxLogBlocks = 1000; 1335 + Ssfdc.MaxSectors = 32; 1336 + break; 1337 + default: 1338 + Ssfdc.Model = NOSSFDC; 1339 + return(ERROR); 1340 + } 1341 + 1342 + return(SUCCESS); 1343 + } 1344 + 1345 + //----- _Check_D_DevCode() --------------------------------------------- 1346 + BYTE _Check_D_DevCode(BYTE dcode) 1347 + { 1348 + switch(dcode){ 1349 + case 0x6E: 1350 + case 0xE8: 1351 + case 0xEC: return(SSFDC1MB); // 8Mbit (1M) NAND 1352 + case 0x64: 1353 + case 0xEA: return(SSFDC2MB); // 16Mbit (2M) NAND 1354 + case 0x6B: 1355 + case 0xE3: 1356 + case 0xE5: return(SSFDC4MB); // 32Mbit (4M) NAND 1357 + case 0xE6: return(SSFDC8MB); // 64Mbit (8M) NAND 1358 + case 0x73: return(SSFDC16MB); // 128Mbit (16M)NAND 1359 + case 0x75: return(SSFDC32MB); // 256Mbit (32M)NAND 1360 + case 0x76: return(SSFDC64MB); // 512Mbit (64M)NAND 1361 + case 0x79: return(SSFDC128MB); // 1Gbit(128M)NAND 1362 + case 0x71: return(SSFDC256MB); 1363 + case 0xDC: return(SSFDC512MB); 1364 + case 0xD3: return(SSFDC1GB); 1365 + case 0xD5: return(SSFDC2GB); 1366 + default: return(NOSSFDC); 1367 + } 1368 + } 1369 + /* 1370 + ////SmartMedia Power Controll Subroutine 1371 + ////----- Cnt_D_Reset() ---------------------------------------------- 1372 + //void Cnt_D_Reset(void) 1373 + //{ 1374 + // _Hw_D_LedOff(); 1375 + // _Hw_D_SetRdStandby(); 1376 + // _Hw_D_VccOff(); 1377 + //} 1378 + // 1379 + ////----- Cnt_D_PowerOn() ---------------------------------------------- 1380 + //int Cnt_D_PowerOn(void) 1381 + //{ 1382 + // // No support 5V. 1383 + // _Hw_D_EnableVcc3VOn(); // Set SM_REG_CTRL_5 Reg. to 3V 1384 + // _Hw_D_VccOn(); 1385 + // _Hw_D_SetRdStandby(); 1386 + // _Wait_D_Timer(TIME_PON); 1387 + // 1388 + // if (_Hw_D_ChkPower()) 1389 + // { 1390 + // _Hw_D_EnableOB(); // Set SM_REG_CTRL_5 Reg. to 0x83 1391 + // return(SUCCESS); 1392 + // } 1393 + // 1394 + // _Hw_D_SetVccOff(); 1395 + // return(ERROR); 1396 + //} 1397 + // 1398 + ////----- Cnt_D_PowerOff() ---------------------------------------------- 1399 + //void Cnt_D_PowerOff(void) 1400 + //{ 1401 + // _Hw_D_SetRdStandby(); 1402 + // _Hw_D_SetVccOff(); 1403 + // _Hw_D_VccOff(); 1404 + //} 1405 + // 1406 + ////----- Cnt_D_LedOn() ---------------------------------------------- 1407 + //void Cnt_D_LedOn(void) 1408 + //{ 1409 + // _Hw_D_LedOn(); 1410 + //} 1411 + // 1412 + ////----- Cnt_D_LedOff() ---------------------------------------------- 1413 + //void Cnt_D_LedOff(void) 1414 + //{ 1415 + // _Hw_D_LedOff(); 1416 + //} 1417 + // 1418 + ////----- Check_D_CntPower() ---------------------------------------------- 1419 + //int Check_D_CntPower(void) 1420 + //{ 1421 + // if (_Hw_D_ChkPower()) 1422 + // return(SUCCESS); // Power On 1423 + // 1424 + // return(ERROR); // Power Off 1425 + //} 1426 + // 1427 + ////----- Check_D_CardExist() ---------------------------------------------- 1428 + //int Check_D_CardExist(void) 1429 + //{ 1430 + // char i,j,k; 1431 + // 1432 + // if (!_Hw_D_ChkStatus()) // Not Status Change 1433 + // if (_Hw_D_ChkCardIn()) 1434 + // return(SUCCESS); // Card exist in Slot 1435 + // 1436 + // for(i=0,j=0,k=0; i<16; i++) { 1437 + // if (_Hw_D_ChkCardIn()) // Status Change 1438 + // { 1439 + // j++; k=0; 1440 + // } 1441 + // else 1442 + // { 1443 + // j=0; k++; 1444 + // } 1445 + // 1446 + // if (j>3) 1447 + // return(SUCCESS); // Card exist in Slot 1448 + // if (k>3) 1449 + // return(ERROR); // NO Card exist in Slot 1450 + // 1451 + // _Wait_D_Timer(TIME_CDCHK); 1452 + // } 1453 + // 1454 + // return(ERROR); 1455 + //} 1456 + // 1457 + ////----- Check_D_CardStsChg() ---------------------------------------------- 1458 + //int Check_D_CardStsChg(void) 1459 + //{ 1460 + // if (_Hw_D_ChkStatus()) 1461 + // return(ERROR); // Status Change 1462 + // 1463 + // return(SUCCESS); // Not Status Change 1464 + //} 1465 + // 1466 + ////----- Check_D_SsfdcWP() ---------------------------------------------- 1467 + //int Check_D_SsfdcWP(void) 1468 + //{ // ERROR: WP, SUCCESS: Not WP 1469 + // char i; 1470 + // 1471 + // for(i=0; i<8; i++) { 1472 + // if (_Hw_D_ChkWP()) 1473 + // return(ERROR); 1474 + // _Wait_D_Timer(TIME_WPCHK); 1475 + // } 1476 + // 1477 + // return(SUCCESS); 1478 + //} 1479 + // 1480 + */ 1481 + //SmartMedia ECC Controll Subroutine 1482 + //----- Check_D_ReadError() ---------------------------------------------- 1483 + int Check_D_ReadError(BYTE *redundant) 1484 + { 1485 + // Driver ���� ECC Check 1486 + return(SUCCESS); 1487 + if (!StringCmp((char *)(redundant+0x0D),(char *)EccBuf,3)) 1488 + if (!StringCmp((char *)(redundant+0x08),(char *)(EccBuf+0x03),3)) 1489 + return(SUCCESS); 1490 + 1491 + return(ERROR); 1492 + } 1493 + 1494 + //----- Check_D_Correct() ---------------------------------------------- 1495 + int Check_D_Correct(BYTE *buf,BYTE *redundant) 1496 + { 1497 + // Driver ���� ECC Check 1498 + return(SUCCESS); 1499 + if (StringCmp((char *)(redundant+0x0D),(char *)EccBuf,3)) 1500 + if (_Correct_D_SwECC(buf,redundant+0x0D,EccBuf)) 1501 + return(ERROR); 1502 + 1503 + buf+=0x100; 1504 + if (StringCmp((char *)(redundant+0x08),(char *)(EccBuf+0x03),3)) 1505 + if (_Correct_D_SwECC(buf,redundant+0x08,EccBuf+0x03)) 1506 + return(ERROR); 1507 + 1508 + return(SUCCESS); 1509 + } 1510 + 1511 + //----- Check_D_CISdata() ---------------------------------------------- 1512 + int Check_D_CISdata(BYTE *buf, BYTE *redundant) 1513 + { 1514 + BYTE cis[]={0x01,0x03,0xD9,0x01,0xFF,0x18,0x02,0xDF,0x01,0x20}; 1515 + 1516 + if (!IsSSFDCCompliance && !IsXDCompliance) 1517 + return(SUCCESS); // �ثe���j�� SUCCESS [Arnold 02-08-23] SSFDC ����, ����j�� SUCCESS 1518 + 1519 + if (!StringCmp((char *)(redundant+0x0D),(char *)EccBuf,3)) 1520 + return(StringCmp((char *)buf,(char *)cis,10)); 1521 + 1522 + if (!_Correct_D_SwECC(buf,redundant+0x0D,EccBuf)) 1523 + return(StringCmp((char *)buf,(char *)cis,10)); 1524 + 1525 + buf+=0x100; 1526 + if (!StringCmp((char *)(redundant+0x08),(char *)(EccBuf+0x03),3)) 1527 + return(StringCmp((char *)buf,(char *)cis,10)); 1528 + 1529 + if (!_Correct_D_SwECC(buf,redundant+0x08,EccBuf+0x03)) 1530 + return(StringCmp((char *)buf,(char *)cis,10)); 1531 + 1532 + return(ERROR); 1533 + } 1534 + 1535 + //----- Set_D_RightECC() ---------------------------------------------- 1536 + void Set_D_RightECC(BYTE *redundant) 1537 + { 1538 + // Driver ���� ECC Check 1539 + return; 1540 + //StringCopy((char *)(redundant+0x0D),(char *)EccBuf,3); 1541 + //StringCopy((char *)(redundant+0x08),(char *)(EccBuf+0x03),3); 1542 + } 1543 + /* 1544 + ////----- _Calc_D_ECCdata() ---------------------------------------------- 1545 + //void _Calc_D_ECCdata(BYTE *buf) 1546 + //{ 1547 + //#ifdef HW_ECC_SUPPORTED 1548 + //#else 1549 + // _Calculate_D_SwECC(buf,EccBuf); 1550 + // buf+=0x0100; 1551 + // _Calculate_D_SwECC(buf,EccBuf+0x03); 1552 + //#endif 1553 + //} 1554 + // 1555 + ////----- _Set_D_ECCdata() ---------------------------------------------- 1556 + //void _Set_D_ECCdata(BYTE add,BYTE *redundant) 1557 + //{ 1558 + // //if (add==EVEN && (Ssfdc.Attribute &MPS)==PS256) 1559 + // // return; 1560 + // 1561 + // // for 256byte/page 1562 + // StringCopy((char *)(redundant+0x0D),(char *)EccBuf,3); 1563 + // StringCopy((char *)(redundant+0x08),(char *)(EccBuf+0x03),3); 1564 + //} 1565 + */ 1566 + //Common Subroutine 1567 + char Bit_D_Count(BYTE cdata) 1568 + { 1569 + WORD bitcount=0; 1570 + 1571 + while(cdata) { 1572 + bitcount+=(WORD)(cdata &0x01); 1573 + cdata /=2; 1574 + } 1575 + 1576 + return((char)bitcount); 1577 + } 1578 + 1579 + //----- 1580 + char Bit_D_CountWord(WORD cdata) 1581 + { 1582 + WORD bitcount=0; 1583 + 1584 + while(cdata) { 1585 + bitcount+=(cdata &0x01); 1586 + cdata /=2; 1587 + } 1588 + 1589 + return((char)bitcount); 1590 + } 1591 + 1592 + void StringCopy(char *stringA, char *stringB, int count) 1593 + { 1594 + int i; 1595 + 1596 + for(i=0; i<count; i++) 1597 + *stringA++ = *stringB++; 1598 + } 1599 + 1600 + //----- 1601 + int StringCmp(char *stringA, char *stringB, int count) 1602 + { 1603 + int i; 1604 + 1605 + for (i=0;i<count;i++) 1606 + if (*stringA++ != *stringB++) 1607 + return(ERROR); 1608 + 1609 + return(SUCCESS); 1610 + } 1611 + /* 1612 + //----- SM_ReadBlock() --------------------------------------------- 1613 + int SM_ReadBlock(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf,BYTE *redundant) 1614 + { 1615 + PBULK_CBW pBulkCbw = fdoExt->pBulkCbw; 1616 + NTSTATUS ntStatus; 1617 + WORD addr; 1618 + 1619 + ENE_LoadBinCode(fdoExt, SM_RW_PATTERN); 1620 + 1621 + addr = (WORD)Media.Zone*Ssfdc.MaxBlocks+Media.PhyBlock; 1622 + addr = addr*(WORD)Ssfdc.MaxSectors+Media.Sector; 1623 + 1624 + // Read sect data 1625 + RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW)); 1626 + pBulkCbw->dCBWSignature = CBW_SIGNTURE; 1627 + pBulkCbw->bCBWLun = CBW_LUN; 1628 + pBulkCbw->dCBWDataTransferLength = 0x200; 1629 + pBulkCbw->bmCBWFlags = 0x80; 1630 + pBulkCbw->CBWCb[0] = 0xF1; 1631 + pBulkCbw->CBWCb[1] = 0x02; 1632 + pBulkCbw->CBWCb[4] = (BYTE)addr; 1633 + pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100); 1634 + pBulkCbw->CBWCb[2] = Media.Zone/2; 1635 + 1636 + ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, buf); 1637 + 1638 + if (!NT_SUCCESS(ntStatus)) 1639 + return(ERROR); 1640 + 1641 + // Read redundant 1642 + RtlZeroMemory(pBulkCbw, sizeof(struct _BULK_CBW)); 1643 + pBulkCbw->dCBWSignature = CBW_SIGNTURE; 1644 + pBulkCbw->bCBWLun = CBW_LUN; 1645 + pBulkCbw->dCBWDataTransferLength = 0x10; 1646 + pBulkCbw->bmCBWFlags = 0x80; 1647 + pBulkCbw->CBWCb[0] = 0xF1; 1648 + pBulkCbw->CBWCb[1] = 0x03; 1649 + pBulkCbw->CBWCb[4] = (BYTE)addr; 1650 + pBulkCbw->CBWCb[3] = (BYTE)(addr/0x0100); 1651 + pBulkCbw->CBWCb[2] = Media.Zone/2; 1652 + pBulkCbw->CBWCb[5] = 0; 1653 + pBulkCbw->CBWCb[6] = 1; 1654 + 1655 + ntStatus = ENE_SendScsiCmd(fdoExt, FDIR_READ, redundant); 1656 + 1657 + if (!NT_SUCCESS(ntStatus)) 1658 + return(ERROR); 1659 + 1660 + return(SUCCESS); 1661 + }*/
+189
drivers/staging/keucr/smscsi.c
··· 1 + #include <linux/sched.h> 2 + #include <linux/errno.h> 3 + #include <linux/slab.h> 4 + 5 + #include <scsi/scsi.h> 6 + #include <scsi/scsi_eh.h> 7 + #include <scsi/scsi_device.h> 8 + 9 + #include "usb.h" 10 + #include "scsiglue.h" 11 + #include "transport.h" 12 + //#include "smcommon.h" 13 + #include "smil.h" 14 + 15 + int SM_SCSI_Test_Unit_Ready (struct us_data *us, struct scsi_cmnd *srb); 16 + int SM_SCSI_Inquiry (struct us_data *us, struct scsi_cmnd *srb); 17 + int SM_SCSI_Mode_Sense (struct us_data *us, struct scsi_cmnd *srb); 18 + int SM_SCSI_Start_Stop (struct us_data *us, struct scsi_cmnd *srb); 19 + int SM_SCSI_Read_Capacity (struct us_data *us, struct scsi_cmnd *srb); 20 + int SM_SCSI_Read (struct us_data *us, struct scsi_cmnd *srb); 21 + int SM_SCSI_Write (struct us_data *us, struct scsi_cmnd *srb); 22 + 23 + extern struct SSFDCTYPE Ssfdc; 24 + extern struct ADDRESS Media; 25 + extern PBYTE SMHostAddr; 26 + extern DWORD ErrXDCode; 27 + 28 + //----- SM_SCSIIrp() -------------------------------------------------- 29 + int SM_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb) 30 + { 31 + int result; 32 + 33 + us->SrbStatus = SS_SUCCESS; 34 + switch (srb->cmnd[0]) 35 + { 36 + case TEST_UNIT_READY : result = SM_SCSI_Test_Unit_Ready (us, srb); break; //0x00 37 + case INQUIRY : result = SM_SCSI_Inquiry (us, srb); break; //0x12 38 + case MODE_SENSE : result = SM_SCSI_Mode_Sense (us, srb); break; //0x1A 39 + case READ_CAPACITY : result = SM_SCSI_Read_Capacity (us, srb); break; //0x25 40 + case READ_10 : result = SM_SCSI_Read (us, srb); break; //0x28 41 + case WRITE_10 : result = SM_SCSI_Write (us, srb); break; //0x2A 42 + 43 + default: 44 + us->SrbStatus = SS_ILLEGAL_REQUEST; 45 + result = USB_STOR_TRANSPORT_FAILED; 46 + break; 47 + } 48 + return result; 49 + } 50 + 51 + //----- SM_SCSI_Test_Unit_Ready() -------------------------------------------------- 52 + int SM_SCSI_Test_Unit_Ready(struct us_data *us, struct scsi_cmnd *srb) 53 + { 54 + //printk("SM_SCSI_Test_Unit_Ready\n"); 55 + if (us->SM_Status.Insert && us->SM_Status.Ready) 56 + return USB_STOR_TRANSPORT_GOOD; 57 + else 58 + { 59 + ENE_SMInit(us); 60 + return USB_STOR_TRANSPORT_GOOD; 61 + } 62 + 63 + return USB_STOR_TRANSPORT_GOOD; 64 + } 65 + 66 + //----- SM_SCSI_Inquiry() -------------------------------------------------- 67 + int SM_SCSI_Inquiry(struct us_data *us, struct scsi_cmnd *srb) 68 + { 69 + //printk("SM_SCSI_Inquiry\n"); 70 + BYTE data_ptr[36] = {0x00, 0x80, 0x02, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x55, 0x53, 0x42, 0x32, 0x2E, 0x30, 0x20, 0x20, 0x43, 0x61, 0x72, 0x64, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x30, 0x30}; 71 + 72 + usb_stor_set_xfer_buf(us, data_ptr, 36, srb, TO_XFER_BUF); 73 + return USB_STOR_TRANSPORT_GOOD; 74 + } 75 + 76 + 77 + //----- SM_SCSI_Mode_Sense() -------------------------------------------------- 78 + int SM_SCSI_Mode_Sense(struct us_data *us, struct scsi_cmnd *srb) 79 + { 80 + BYTE mediaNoWP[12] = {0x0b,0x00,0x00,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00}; 81 + BYTE mediaWP[12] = {0x0b,0x00,0x80,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00}; 82 + 83 + if (us->SM_Status.WtP) 84 + usb_stor_set_xfer_buf(us, mediaWP, 12, srb, TO_XFER_BUF); 85 + else 86 + usb_stor_set_xfer_buf(us, mediaNoWP, 12, srb, TO_XFER_BUF); 87 + 88 + 89 + return USB_STOR_TRANSPORT_GOOD; 90 + } 91 + 92 + //----- SM_SCSI_Read_Capacity() -------------------------------------------------- 93 + int SM_SCSI_Read_Capacity(struct us_data *us, struct scsi_cmnd *srb) 94 + { 95 + unsigned int offset = 0; 96 + struct scatterlist *sg = NULL; 97 + DWORD bl_num; 98 + WORD bl_len; 99 + BYTE buf[8]; 100 + 101 + printk("SM_SCSI_Read_Capacity\n"); 102 + 103 + bl_len = 0x200; 104 + bl_num = Ssfdc.MaxLogBlocks * Ssfdc.MaxSectors * Ssfdc.MaxZones - 1; 105 + //printk("MaxLogBlocks = %x\n", Ssfdc.MaxLogBlocks); 106 + //printk("MaxSectors = %x\n", Ssfdc.MaxSectors); 107 + //printk("MaxZones = %x\n", Ssfdc.MaxZones); 108 + //printk("bl_num = %x\n", bl_num); 109 + 110 + us->bl_num = bl_num; 111 + printk("bl_len = %x\n", bl_len); 112 + printk("bl_num = %x\n", bl_num); 113 + 114 + //srb->request_bufflen = 8; 115 + buf[0] = (bl_num>>24) & 0xff; 116 + buf[1] = (bl_num>>16) & 0xff; 117 + buf[2] = (bl_num>> 8) & 0xff; 118 + buf[3] = (bl_num>> 0) & 0xff; 119 + buf[4] = (bl_len>>24) & 0xff; 120 + buf[5] = (bl_len>>16) & 0xff; 121 + buf[6] = (bl_len>> 8) & 0xff; 122 + buf[7] = (bl_len>> 0) & 0xff; 123 + 124 + usb_stor_access_xfer_buf(us, buf, 8, srb, &sg, &offset, TO_XFER_BUF); 125 + //usb_stor_set_xfer_buf(us, buf, srb->request_bufflen, srb, TO_XFER_BUF); 126 + 127 + return USB_STOR_TRANSPORT_GOOD; 128 + } 129 + 130 + //----- SM_SCSI_Read() -------------------------------------------------- 131 + int SM_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb) 132 + { 133 + //struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 134 + int result=0; 135 + PBYTE Cdb = srb->cmnd; 136 + DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) | 137 + ((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff); 138 + WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff); 139 + DWORD blenByte = blen * 0x200; 140 + void *buf; 141 + 142 + //printk("SCSIOP_READ --- bn = %X, blen = %X, srb->use_sg = %X\n", bn, blen, srb->use_sg); 143 + 144 + if (bn > us->bl_num) 145 + return USB_STOR_TRANSPORT_ERROR; 146 + 147 + buf = kmalloc(blenByte, GFP_KERNEL); 148 + result = Media_D_ReadSector(us, bn, blen, buf); 149 + usb_stor_set_xfer_buf(us, buf, blenByte, srb, TO_XFER_BUF); 150 + kfree(buf); 151 + 152 + if (!result) 153 + return USB_STOR_TRANSPORT_GOOD; 154 + else 155 + return USB_STOR_TRANSPORT_ERROR; 156 + 157 + return USB_STOR_TRANSPORT_GOOD; 158 + } 159 + 160 + //----- SM_SCSI_Write() -------------------------------------------------- 161 + int SM_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb) 162 + { 163 + //struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 164 + int result=0; 165 + PBYTE Cdb = srb->cmnd; 166 + DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) | 167 + ((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff); 168 + WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff); 169 + DWORD blenByte = blen * 0x200; 170 + void *buf; 171 + 172 + //printk("SCSIOP_Write --- bn = %X, blen = %X, srb->use_sg = %X\n", bn, blen, srb->use_sg); 173 + 174 + if (bn > us->bl_num) 175 + return USB_STOR_TRANSPORT_ERROR; 176 + 177 + buf = kmalloc(blenByte, GFP_KERNEL); 178 + usb_stor_set_xfer_buf(us, buf, blenByte, srb, FROM_XFER_BUF); 179 + result = Media_D_CopySector(us, bn, blen, buf); 180 + kfree(buf); 181 + 182 + if (!result) 183 + return USB_STOR_TRANSPORT_GOOD; 184 + else 185 + return USB_STOR_TRANSPORT_ERROR; 186 + 187 + return USB_STOR_TRANSPORT_GOOD; 188 + } 189 +
+788
drivers/staging/keucr/transport.c
··· 1 + #include <linux/sched.h> 2 + #include <linux/errno.h> 3 + #include <linux/slab.h> 4 + 5 + #include <scsi/scsi.h> 6 + #include <scsi/scsi_eh.h> 7 + #include <scsi/scsi_device.h> 8 + 9 + #include "usb.h" 10 + #include "scsiglue.h" 11 + #include "transport.h" 12 + 13 + /*********************************************************************** 14 + * Data transfer routines 15 + ***********************************************************************/ 16 + //----- usb_stor_blocking_completion() --------------------- 17 + static void usb_stor_blocking_completion(struct urb *urb) 18 + { 19 + struct completion *urb_done_ptr = urb->context; 20 + 21 + //printk("transport --- usb_stor_blocking_completion\n"); 22 + complete(urb_done_ptr); 23 + } 24 + 25 + //----- usb_stor_msg_common() --------------------- 26 + static int usb_stor_msg_common(struct us_data *us, int timeout) 27 + { 28 + struct completion urb_done; 29 + long timeleft; 30 + int status; 31 + 32 + //printk("transport --- usb_stor_msg_common\n"); 33 + if (test_bit(US_FLIDX_ABORTING, &us->dflags)) 34 + return -EIO; 35 + 36 + init_completion(&urb_done); 37 + 38 + us->current_urb->context = &urb_done; 39 + us->current_urb->actual_length = 0; 40 + us->current_urb->error_count = 0; 41 + us->current_urb->status = 0; 42 + 43 + // us->current_urb->transfer_flags = URB_NO_SETUP_DMA_MAP; 44 + if (us->current_urb->transfer_buffer == us->iobuf) 45 + us->current_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 46 + us->current_urb->transfer_dma = us->iobuf_dma; 47 + us->current_urb->setup_dma = us->cr_dma; 48 + 49 + status = usb_submit_urb(us->current_urb, GFP_NOIO); 50 + if (status) 51 + return status; 52 + 53 + set_bit(US_FLIDX_URB_ACTIVE, &us->dflags); 54 + 55 + if (test_bit(US_FLIDX_ABORTING, &us->dflags)) 56 + { 57 + if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) 58 + { 59 + //printk("-- cancelling URB\n"); 60 + usb_unlink_urb(us->current_urb); 61 + } 62 + } 63 + 64 + timeleft = wait_for_completion_interruptible_timeout(&urb_done, timeout ? : MAX_SCHEDULE_TIMEOUT); 65 + clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags); 66 + 67 + if (timeleft <= 0) 68 + { 69 + //printk("%s -- cancelling URB\n", timeleft == 0 ? "Timeout" : "Signal"); 70 + usb_kill_urb(us->current_urb); 71 + } 72 + 73 + return us->current_urb->status; 74 + } 75 + 76 + //----- usb_stor_control_msg() --------------------- 77 + int usb_stor_control_msg(struct us_data *us, unsigned int pipe, 78 + u8 request, u8 requesttype, u16 value, u16 index, 79 + void *data, u16 size, int timeout) 80 + { 81 + int status; 82 + 83 + //printk("transport --- usb_stor_control_msg\n"); 84 + 85 + /* fill in the devrequest structure */ 86 + us->cr->bRequestType = requesttype; 87 + us->cr->bRequest = request; 88 + us->cr->wValue = cpu_to_le16(value); 89 + us->cr->wIndex = cpu_to_le16(index); 90 + us->cr->wLength = cpu_to_le16(size); 91 + 92 + /* fill and submit the URB */ 93 + usb_fill_control_urb(us->current_urb, us->pusb_dev, pipe, 94 + (unsigned char*) us->cr, data, size, 95 + usb_stor_blocking_completion, NULL); 96 + status = usb_stor_msg_common(us, timeout); 97 + 98 + /* return the actual length of the data transferred if no error */ 99 + if (status == 0) 100 + status = us->current_urb->actual_length; 101 + return status; 102 + } 103 + 104 + //----- usb_stor_clear_halt() --------------------- 105 + int usb_stor_clear_halt(struct us_data *us, unsigned int pipe) 106 + { 107 + int result; 108 + int endp = usb_pipeendpoint(pipe); 109 + 110 + //printk("transport --- usb_stor_clear_halt\n"); 111 + if (usb_pipein (pipe)) 112 + endp |= USB_DIR_IN; 113 + 114 + result = usb_stor_control_msg(us, us->send_ctrl_pipe, 115 + USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT, 116 + USB_ENDPOINT_HALT, endp, 117 + NULL, 0, 3*HZ); 118 + 119 + /* reset the endpoint toggle */ 120 + if (result >= 0) 121 + //usb_settoggle(us->pusb_dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 0); 122 + usb_reset_endpoint(us->pusb_dev, endp); 123 + 124 + return result; 125 + } 126 + 127 + //----- interpret_urb_result() --------------------- 128 + static int interpret_urb_result(struct us_data *us, unsigned int pipe, 129 + unsigned int length, int result, unsigned int partial) 130 + { 131 + //printk("transport --- interpret_urb_result\n"); 132 + switch (result) { 133 + /* no error code; did we send all the data? */ 134 + case 0: 135 + if (partial != length) 136 + { 137 + //printk("-- short transfer\n"); 138 + return USB_STOR_XFER_SHORT; 139 + } 140 + //printk("-- transfer complete\n"); 141 + return USB_STOR_XFER_GOOD; 142 + case -EPIPE: 143 + if (usb_pipecontrol(pipe)) 144 + { 145 + //printk("-- stall on control pipe\n"); 146 + return USB_STOR_XFER_STALLED; 147 + } 148 + //printk("clearing endpoint halt for pipe 0x%x\n", pipe); 149 + if (usb_stor_clear_halt(us, pipe) < 0) 150 + return USB_STOR_XFER_ERROR; 151 + return USB_STOR_XFER_STALLED; 152 + case -EOVERFLOW: 153 + //printk("-- babble\n"); 154 + return USB_STOR_XFER_LONG; 155 + case -ECONNRESET: 156 + //printk("-- transfer cancelled\n"); 157 + return USB_STOR_XFER_ERROR; 158 + case -EREMOTEIO: 159 + //printk("-- short read transfer\n"); 160 + return USB_STOR_XFER_SHORT; 161 + case -EIO: 162 + //printk("-- abort or disconnect in progress\n"); 163 + return USB_STOR_XFER_ERROR; 164 + default: 165 + //printk("-- unknown error\n"); 166 + return USB_STOR_XFER_ERROR; 167 + } 168 + } 169 + 170 + //----- usb_stor_bulk_transfer_buf() --------------------- 171 + int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe, 172 + void *buf, unsigned int length, unsigned int *act_len) 173 + { 174 + int result; 175 + 176 + //printk("transport --- usb_stor_bulk_transfer_buf\n"); 177 + 178 + /* fill and submit the URB */ 179 + usb_fill_bulk_urb(us->current_urb, us->pusb_dev, pipe, buf, length, usb_stor_blocking_completion, NULL); 180 + result = usb_stor_msg_common(us, 0); 181 + 182 + /* store the actual length of the data transferred */ 183 + if (act_len) 184 + *act_len = us->current_urb->actual_length; 185 + 186 + return interpret_urb_result(us, pipe, length, result, us->current_urb->actual_length); 187 + } 188 + 189 + //----- usb_stor_bulk_transfer_sglist() --------------------- 190 + static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe, 191 + struct scatterlist *sg, int num_sg, unsigned int length, 192 + unsigned int *act_len) 193 + { 194 + int result; 195 + 196 + //printk("transport --- usb_stor_bulk_transfer_sglist\n"); 197 + if (test_bit(US_FLIDX_ABORTING, &us->dflags)) 198 + return USB_STOR_XFER_ERROR; 199 + 200 + /* initialize the scatter-gather request block */ 201 + result = usb_sg_init(&us->current_sg, us->pusb_dev, pipe, 0, sg, num_sg, length, GFP_NOIO); 202 + if (result) 203 + { 204 + //printk("usb_sg_init returned %d\n", result); 205 + return USB_STOR_XFER_ERROR; 206 + } 207 + 208 + /* since the block has been initialized successfully, it's now okay to cancel it */ 209 + set_bit(US_FLIDX_SG_ACTIVE, &us->dflags); 210 + 211 + /* did an abort/disconnect occur during the submission? */ 212 + if (test_bit(US_FLIDX_ABORTING, &us->dflags)) 213 + { 214 + /* cancel the request, if it hasn't been cancelled already */ 215 + if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) 216 + { 217 + //printk("-- cancelling sg request\n"); 218 + usb_sg_cancel(&us->current_sg); 219 + } 220 + } 221 + 222 + /* wait for the completion of the transfer */ 223 + usb_sg_wait(&us->current_sg); 224 + clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags); 225 + 226 + result = us->current_sg.status; 227 + if (act_len) 228 + *act_len = us->current_sg.bytes; 229 + 230 + return interpret_urb_result(us, pipe, length, result, us->current_sg.bytes); 231 + } 232 + 233 + //----- usb_stor_bulk_srb() --------------------- 234 + int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe, struct scsi_cmnd* srb) 235 + { 236 + unsigned int partial; 237 + int result = usb_stor_bulk_transfer_sglist(us, pipe, scsi_sglist(srb), 238 + scsi_sg_count(srb), scsi_bufflen(srb), 239 + &partial); 240 + 241 + scsi_set_resid(srb, scsi_bufflen(srb) - partial); 242 + return result; 243 + } 244 + 245 + //----- usb_stor_bulk_transfer_sg() --------------------- 246 + int usb_stor_bulk_transfer_sg(struct us_data* us, unsigned int pipe, 247 + void *buf, unsigned int length_left, int use_sg, int *residual) 248 + { 249 + int result; 250 + unsigned int partial; 251 + 252 + //printk("transport --- usb_stor_bulk_transfer_sg\n"); 253 + /* are we scatter-gathering? */ 254 + if (use_sg) 255 + { 256 + /* use the usb core scatter-gather primitives */ 257 + result = usb_stor_bulk_transfer_sglist(us, pipe, 258 + (struct scatterlist *) buf, use_sg, 259 + length_left, &partial); 260 + length_left -= partial; 261 + } 262 + else 263 + { 264 + /* no scatter-gather, just make the request */ 265 + result = usb_stor_bulk_transfer_buf(us, pipe, buf, length_left, &partial); 266 + length_left -= partial; 267 + } 268 + 269 + /* store the residual and return the error code */ 270 + if (residual) 271 + *residual = length_left; 272 + return result; 273 + } 274 + 275 + /*********************************************************************** 276 + * Transport routines 277 + ***********************************************************************/ 278 + //----- usb_stor_invoke_transport() --------------------- 279 + void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) 280 + { 281 + int need_auto_sense; 282 + int result; 283 + 284 + //printk("transport --- usb_stor_invoke_transport\n"); 285 + usb_stor_print_cmd(srb); 286 + /* send the command to the transport layer */ 287 + scsi_set_resid(srb, 0); 288 + result = us->transport(srb, us); //usb_stor_Bulk_transport; 289 + 290 + /* if the command gets aborted by the higher layers, we need to short-circuit all other processing */ 291 + if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) 292 + { 293 + //printk("-- command was aborted\n"); 294 + srb->result = DID_ABORT << 16; 295 + goto Handle_Errors; 296 + } 297 + 298 + /* if there is a transport error, reset and don't auto-sense */ 299 + if (result == USB_STOR_TRANSPORT_ERROR) 300 + { 301 + //printk("-- transport indicates error, resetting\n"); 302 + srb->result = DID_ERROR << 16; 303 + goto Handle_Errors; 304 + } 305 + 306 + /* if the transport provided its own sense data, don't auto-sense */ 307 + if (result == USB_STOR_TRANSPORT_NO_SENSE) 308 + { 309 + srb->result = SAM_STAT_CHECK_CONDITION; 310 + return; 311 + } 312 + 313 + srb->result = SAM_STAT_GOOD; 314 + 315 + /* Determine if we need to auto-sense */ 316 + need_auto_sense = 0; 317 + 318 + if ((us->protocol == US_PR_CB || us->protocol == US_PR_DPCM_USB) && srb->sc_data_direction != DMA_FROM_DEVICE) 319 + { 320 + //printk("-- CB transport device requiring auto-sense\n"); 321 + need_auto_sense = 1; 322 + } 323 + 324 + if (result == USB_STOR_TRANSPORT_FAILED) 325 + { 326 + //printk("-- transport indicates command failure\n"); 327 + need_auto_sense = 1; 328 + } 329 + 330 + /* Now, if we need to do the auto-sense, let's do it */ 331 + if (need_auto_sense) 332 + { 333 + int temp_result; 334 + struct scsi_eh_save ses; 335 + 336 + printk("Issuing auto-REQUEST_SENSE\n"); 337 + 338 + scsi_eh_prep_cmnd(srb, &ses, NULL, 0, US_SENSE_SIZE); 339 + 340 + /* we must do the protocol translation here */ 341 + if (us->subclass == US_SC_RBC || us->subclass == US_SC_SCSI || us->subclass == US_SC_CYP_ATACB) 342 + srb->cmd_len = 6; 343 + else 344 + srb->cmd_len = 12; 345 + 346 + /* issue the auto-sense command */ 347 + scsi_set_resid(srb, 0); 348 + temp_result = us->transport(us->srb, us); 349 + 350 + /* let's clean up right away */ 351 + scsi_eh_restore_cmnd(srb, &ses); 352 + 353 + if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) 354 + { 355 + //printk("-- auto-sense aborted\n"); 356 + srb->result = DID_ABORT << 16; 357 + goto Handle_Errors; 358 + } 359 + if (temp_result != USB_STOR_TRANSPORT_GOOD) 360 + { 361 + //printk("-- auto-sense failure\n"); 362 + srb->result = DID_ERROR << 16; 363 + if (!(us->fflags & US_FL_SCM_MULT_TARG)) 364 + goto Handle_Errors; 365 + return; 366 + } 367 + 368 + /* set the result so the higher layers expect this data */ 369 + srb->result = SAM_STAT_CHECK_CONDITION; 370 + 371 + if (result == USB_STOR_TRANSPORT_GOOD && 372 + (srb->sense_buffer[2] & 0xaf) == 0 && 373 + srb->sense_buffer[12] == 0 && 374 + srb->sense_buffer[13] == 0) 375 + { 376 + srb->result = SAM_STAT_GOOD; 377 + srb->sense_buffer[0] = 0x0; 378 + } 379 + } 380 + 381 + /* Did we transfer less than the minimum amount required? */ 382 + if (srb->result == SAM_STAT_GOOD && scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow) 383 + srb->result = (DID_ERROR << 16);//v02 | (SUGGEST_RETRY << 24); 384 + 385 + return; 386 + 387 + Handle_Errors: 388 + scsi_lock(us_to_host(us)); 389 + set_bit(US_FLIDX_RESETTING, &us->dflags); 390 + clear_bit(US_FLIDX_ABORTING, &us->dflags); 391 + scsi_unlock(us_to_host(us)); 392 + 393 + mutex_unlock(&us->dev_mutex); 394 + result = usb_stor_port_reset(us); 395 + mutex_lock(&us->dev_mutex); 396 + 397 + if (result < 0) 398 + { 399 + scsi_lock(us_to_host(us)); 400 + usb_stor_report_device_reset(us); 401 + scsi_unlock(us_to_host(us)); 402 + us->transport_reset(us); 403 + } 404 + clear_bit(US_FLIDX_RESETTING, &us->dflags); 405 + } 406 + 407 + //----- ENE_stor_invoke_transport() --------------------- 408 + void ENE_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) 409 + { 410 + int result=0; 411 + 412 + //printk("transport --- ENE_stor_invoke_transport\n"); 413 + usb_stor_print_cmd(srb); 414 + /* send the command to the transport layer */ 415 + scsi_set_resid(srb, 0); 416 + if ( !(us->SD_Status.Ready || us->MS_Status.Ready || us->SM_Status.Ready) ) 417 + result = ENE_InitMedia(us); 418 + 419 + if (us->Power_IsResum == true) { 420 + result = ENE_InitMedia(us); 421 + us->Power_IsResum = false; 422 + } 423 + 424 + if (us->SD_Status.Ready) result = SD_SCSIIrp(us, srb); 425 + if (us->MS_Status.Ready) result = MS_SCSIIrp(us, srb); 426 + if (us->SM_Status.Ready) result = SM_SCSIIrp(us, srb); 427 + 428 + /* if the command gets aborted by the higher layers, we need to short-circuit all other processing */ 429 + if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) 430 + { 431 + //printk("-- command was aborted\n"); 432 + srb->result = DID_ABORT << 16; 433 + goto Handle_Errors; 434 + } 435 + 436 + /* if there is a transport error, reset and don't auto-sense */ 437 + if (result == USB_STOR_TRANSPORT_ERROR) 438 + { 439 + //printk("-- transport indicates error, resetting\n"); 440 + srb->result = DID_ERROR << 16; 441 + goto Handle_Errors; 442 + } 443 + 444 + /* if the transport provided its own sense data, don't auto-sense */ 445 + if (result == USB_STOR_TRANSPORT_NO_SENSE) 446 + { 447 + srb->result = SAM_STAT_CHECK_CONDITION; 448 + return; 449 + } 450 + 451 + srb->result = SAM_STAT_GOOD; 452 + if (result == USB_STOR_TRANSPORT_FAILED) 453 + { 454 + //printk("-- transport indicates command failure\n"); 455 + //need_auto_sense = 1; 456 + BuildSenseBuffer(srb, us->SrbStatus); 457 + srb->result = SAM_STAT_CHECK_CONDITION; 458 + } 459 + 460 + /* Did we transfer less than the minimum amount required? */ 461 + if (srb->result == SAM_STAT_GOOD && scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow) 462 + srb->result = (DID_ERROR << 16);//v02 | (SUGGEST_RETRY << 24); 463 + 464 + return; 465 + 466 + Handle_Errors: 467 + scsi_lock(us_to_host(us)); 468 + set_bit(US_FLIDX_RESETTING, &us->dflags); 469 + clear_bit(US_FLIDX_ABORTING, &us->dflags); 470 + scsi_unlock(us_to_host(us)); 471 + 472 + mutex_unlock(&us->dev_mutex); 473 + result = usb_stor_port_reset(us); 474 + mutex_lock(&us->dev_mutex); 475 + 476 + if (result < 0) 477 + { 478 + scsi_lock(us_to_host(us)); 479 + usb_stor_report_device_reset(us); 480 + scsi_unlock(us_to_host(us)); 481 + us->transport_reset(us); 482 + } 483 + clear_bit(US_FLIDX_RESETTING, &us->dflags); 484 + } 485 + 486 + //----- BuildSenseBuffer() ------------------------------------------- 487 + void BuildSenseBuffer(struct scsi_cmnd *srb, int SrbStatus) 488 + { 489 + BYTE *buf = srb->sense_buffer; 490 + BYTE asc; 491 + 492 + printk("transport --- BuildSenseBuffer\n"); 493 + switch (SrbStatus) 494 + { 495 + case SS_NOT_READY: asc = 0x3a; break; // sense key = 0x02 496 + case SS_MEDIUM_ERR: asc = 0x0c; break; // sense key = 0x03 497 + case SS_ILLEGAL_REQUEST: asc = 0x20; break; // sense key = 0x05 498 + default: asc = 0x00; break; // ?? 499 + } 500 + 501 + memset(buf, 0, 18); 502 + buf[0x00] = 0xf0; 503 + buf[0x02] = SrbStatus; 504 + buf[0x07] = 0x0b; 505 + buf[0x0c] = asc; 506 + } 507 + 508 + //----- usb_stor_stop_transport() --------------------- 509 + void usb_stor_stop_transport(struct us_data *us) 510 + { 511 + //printk("transport --- usb_stor_stop_transport\n"); 512 + 513 + if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) 514 + { 515 + //printk("-- cancelling URB\n"); 516 + usb_unlink_urb(us->current_urb); 517 + } 518 + 519 + if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) 520 + { 521 + //printk("-- cancelling sg request\n"); 522 + usb_sg_cancel(&us->current_sg); 523 + } 524 + } 525 + 526 + //----- usb_stor_Bulk_max_lun() --------------------- 527 + int usb_stor_Bulk_max_lun(struct us_data *us) 528 + { 529 + int result; 530 + 531 + //printk("transport --- usb_stor_Bulk_max_lun\n"); 532 + /* issue the command */ 533 + us->iobuf[0] = 0; 534 + result = usb_stor_control_msg(us, us->recv_ctrl_pipe, 535 + US_BULK_GET_MAX_LUN, 536 + USB_DIR_IN | USB_TYPE_CLASS | 537 + USB_RECIP_INTERFACE, 538 + 0, us->ifnum, us->iobuf, 1, HZ); 539 + 540 + //printk("GetMaxLUN command result is %d, data is %d\n", result, us->iobuf[0]); 541 + 542 + /* if we have a successful request, return the result */ 543 + if (result > 0) 544 + return us->iobuf[0]; 545 + 546 + return 0; 547 + } 548 + 549 + //----- usb_stor_Bulk_transport() --------------------- 550 + int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us) 551 + { 552 + struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 553 + struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; 554 + unsigned int transfer_length = scsi_bufflen(srb); 555 + unsigned int residue; 556 + int result; 557 + int fake_sense = 0; 558 + unsigned int cswlen; 559 + unsigned int cbwlen = US_BULK_CB_WRAP_LEN; 560 + 561 + //printk("transport --- usb_stor_Bulk_transport\n"); 562 + /* Take care of BULK32 devices; set extra byte to 0 */ 563 + if (unlikely(us->fflags & US_FL_BULK32)) 564 + { 565 + cbwlen = 32; 566 + us->iobuf[31] = 0; 567 + } 568 + 569 + /* set up the command wrapper */ 570 + bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 571 + bcb->DataTransferLength = cpu_to_le32(transfer_length); 572 + bcb->Flags = srb->sc_data_direction == DMA_FROM_DEVICE ? 1 << 7 : 0; 573 + bcb->Tag = ++us->tag; 574 + bcb->Lun = srb->device->lun; 575 + if (us->fflags & US_FL_SCM_MULT_TARG) 576 + bcb->Lun |= srb->device->id << 4; 577 + bcb->Length = srb->cmd_len; 578 + 579 + /* copy the command payload */ 580 + memset(bcb->CDB, 0, sizeof(bcb->CDB)); 581 + memcpy(bcb->CDB, srb->cmnd, bcb->Length); 582 + 583 + // send command 584 + /* send it to out endpoint */ 585 + /*printk("Bulk Command S 0x%x T 0x%x L %d F %d Trg %d LUN %d CL %d\n", 586 + le32_to_cpu(bcb->Signature), bcb->Tag, 587 + le32_to_cpu(bcb->DataTransferLength), bcb->Flags, 588 + (bcb->Lun >> 4), (bcb->Lun & 0x0F), 589 + bcb->Length);*/ 590 + result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb, cbwlen, NULL); 591 + //printk("Bulk command transfer result=%d\n", result); 592 + if (result != USB_STOR_XFER_GOOD) 593 + return USB_STOR_TRANSPORT_ERROR; 594 + 595 + if (unlikely(us->fflags & US_FL_GO_SLOW)) 596 + udelay(125); 597 + 598 + // R/W data 599 + if (transfer_length) 600 + { 601 + unsigned int pipe = srb->sc_data_direction == DMA_FROM_DEVICE ? us->recv_bulk_pipe : us->send_bulk_pipe; 602 + result = usb_stor_bulk_srb(us, pipe, srb); 603 + //printk("Bulk data transfer result 0x%x\n", result); 604 + if (result == USB_STOR_XFER_ERROR) 605 + return USB_STOR_TRANSPORT_ERROR; 606 + 607 + if (result == USB_STOR_XFER_LONG) 608 + fake_sense = 1; 609 + } 610 + 611 + /* get CSW for device status */ 612 + //printk("Attempting to get CSW...\n"); 613 + result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, &cswlen); 614 + 615 + if (result == USB_STOR_XFER_SHORT && cswlen == 0) 616 + { 617 + //printk("Received 0-length CSW; retrying...\n"); 618 + result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, &cswlen); 619 + } 620 + 621 + /* did the attempt to read the CSW fail? */ 622 + if (result == USB_STOR_XFER_STALLED) 623 + { 624 + /* get the status again */ 625 + //printk("Attempting to get CSW (2nd try)...\n"); 626 + result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, NULL); 627 + } 628 + 629 + /* if we still have a failure at this point, we're in trouble */ 630 + //printk("Bulk status result = %d\n", result); 631 + if (result != USB_STOR_XFER_GOOD) 632 + return USB_STOR_TRANSPORT_ERROR; 633 + 634 + /* check bulk status */ 635 + residue = le32_to_cpu(bcs->Residue); 636 + //printk("Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n", le32_to_cpu(bcs->Signature), bcs->Tag, residue, bcs->Status); 637 + if (!(bcs->Tag == us->tag || (us->fflags & US_FL_BULK_IGNORE_TAG)) || bcs->Status > US_BULK_STAT_PHASE) 638 + { 639 + //printk("Bulk logical error\n"); 640 + return USB_STOR_TRANSPORT_ERROR; 641 + } 642 + 643 + if (!us->bcs_signature) 644 + { 645 + us->bcs_signature = bcs->Signature; 646 + //if (us->bcs_signature != cpu_to_le32(US_BULK_CS_SIGN)) 647 + // printk("Learnt BCS signature 0x%08X\n", le32_to_cpu(us->bcs_signature)); 648 + } 649 + else if (bcs->Signature != us->bcs_signature) 650 + { 651 + /*printk("Signature mismatch: got %08X, expecting %08X\n", 652 + le32_to_cpu(bcs->Signature), 653 + le32_to_cpu(us->bcs_signature));*/ 654 + return USB_STOR_TRANSPORT_ERROR; 655 + } 656 + 657 + /* try to compute the actual residue, based on how much data 658 + * was really transferred and what the device tells us */ 659 + if (residue && !(us->fflags & US_FL_IGNORE_RESIDUE)) 660 + { 661 + 662 + /* Heuristically detect devices that generate bogus residues 663 + * by seeing what happens with INQUIRY and READ CAPACITY 664 + * commands. 665 + */ 666 + if (bcs->Status == US_BULK_STAT_OK && 667 + scsi_get_resid(srb) == 0 && 668 + ((srb->cmnd[0] == INQUIRY && 669 + transfer_length == 36) || 670 + (srb->cmnd[0] == READ_CAPACITY && 671 + transfer_length == 8))) 672 + { 673 + us->fflags |= US_FL_IGNORE_RESIDUE; 674 + 675 + } 676 + else 677 + { 678 + residue = min(residue, transfer_length); 679 + scsi_set_resid(srb, max(scsi_get_resid(srb), (int) residue)); 680 + } 681 + } 682 + 683 + /* based on the status code, we report good or bad */ 684 + switch (bcs->Status) 685 + { 686 + case US_BULK_STAT_OK: 687 + if (fake_sense) 688 + { 689 + memcpy(srb->sense_buffer, usb_stor_sense_invalidCDB, sizeof(usb_stor_sense_invalidCDB)); 690 + return USB_STOR_TRANSPORT_NO_SENSE; 691 + } 692 + return USB_STOR_TRANSPORT_GOOD; 693 + 694 + case US_BULK_STAT_FAIL: 695 + return USB_STOR_TRANSPORT_FAILED; 696 + 697 + case US_BULK_STAT_PHASE: 698 + return USB_STOR_TRANSPORT_ERROR; 699 + } 700 + return USB_STOR_TRANSPORT_ERROR; 701 + } 702 + 703 + /*********************************************************************** 704 + * Reset routines 705 + ***********************************************************************/ 706 + //----- usb_stor_reset_common() --------------------- 707 + static int usb_stor_reset_common(struct us_data *us, 708 + u8 request, u8 requesttype, 709 + u16 value, u16 index, void *data, u16 size) 710 + { 711 + int result; 712 + int result2; 713 + 714 + //printk("transport --- usb_stor_reset_common\n"); 715 + if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) 716 + { 717 + //printk("No reset during disconnect\n"); 718 + return -EIO; 719 + } 720 + 721 + result = usb_stor_control_msg(us, us->send_ctrl_pipe, request, requesttype, value, index, data, size, 5*HZ); 722 + if (result < 0) 723 + { 724 + //printk("Soft reset failed: %d\n", result); 725 + return result; 726 + } 727 + 728 + wait_event_interruptible_timeout(us->delay_wait, test_bit(US_FLIDX_DISCONNECTING, &us->dflags), HZ*6); 729 + if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) 730 + { 731 + //printk("Reset interrupted by disconnect\n"); 732 + return -EIO; 733 + } 734 + 735 + //printk("Soft reset: clearing bulk-in endpoint halt\n"); 736 + result = usb_stor_clear_halt(us, us->recv_bulk_pipe); 737 + 738 + //printk("Soft reset: clearing bulk-out endpoint halt\n"); 739 + result2 = usb_stor_clear_halt(us, us->send_bulk_pipe); 740 + 741 + /* return a result code based on the result of the clear-halts */ 742 + if (result >= 0) 743 + result = result2; 744 + //if (result < 0) 745 + // printk("Soft reset failed\n"); 746 + //else 747 + // printk("Soft reset done\n"); 748 + return result; 749 + } 750 + 751 + //----- usb_stor_Bulk_reset() --------------------- 752 + int usb_stor_Bulk_reset(struct us_data *us) 753 + { 754 + //printk("transport --- usb_stor_Bulk_reset\n"); 755 + return usb_stor_reset_common(us, US_BULK_RESET_REQUEST, 756 + USB_TYPE_CLASS | USB_RECIP_INTERFACE, 757 + 0, us->ifnum, NULL, 0); 758 + } 759 + 760 + //----- usb_stor_port_reset() --------------------- 761 + int usb_stor_port_reset(struct us_data *us) 762 + { 763 + int result, rc_lock; 764 + 765 + //printk("transport --- usb_stor_port_reset\n"); 766 + result = rc_lock = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf); 767 + if (result < 0) 768 + printk("unable to lock device for reset: %d\n", result); 769 + else 770 + { 771 + /* Were we disconnected while waiting for the lock? */ 772 + if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) 773 + { 774 + result = -EIO; 775 + //printk("No reset during disconnect\n"); 776 + } 777 + else 778 + { 779 + result = usb_reset_device(us->pusb_dev); 780 + //printk("usb_reset_composite_device returns %d\n", result); 781 + } 782 + if (rc_lock) 783 + usb_unlock_device(us->pusb_dev); 784 + } 785 + return result; 786 + } 787 + 788 +
+144
drivers/staging/keucr/transport.h
··· 1 + #ifndef _TRANSPORT_H_ 2 + #define _TRANSPORT_H_ 3 + 4 + #include <linux/blkdev.h> 5 + 6 + /* Bulk only data structures */ 7 + 8 + /* command block wrapper */ 9 + struct bulk_cb_wrap { 10 + __le32 Signature; /* contains 'USBC' */ 11 + __u32 Tag; /* unique per command id */ 12 + __le32 DataTransferLength; /* size of data */ 13 + __u8 Flags; /* direction in bit 0 */ 14 + __u8 Lun; /* LUN normally 0 */ 15 + __u8 Length; /* of of the CDB */ 16 + __u8 CDB[16]; /* max command */ 17 + }; 18 + 19 + #define US_BULK_CB_WRAP_LEN 31 20 + #define US_BULK_CB_SIGN 0x43425355 /*spells out USBC */ 21 + #define US_BULK_FLAG_IN 1 22 + #define US_BULK_FLAG_OUT 0 23 + 24 + /* command status wrapper */ 25 + struct bulk_cs_wrap { 26 + __le32 Signature; /* should = 'USBS' */ 27 + __u32 Tag; /* same as original command */ 28 + __le32 Residue; /* amount not transferred */ 29 + __u8 Status; /* see below */ 30 + __u8 Filler[18]; 31 + }; 32 + 33 + #define US_BULK_CS_WRAP_LEN 13 34 + #define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */ 35 + #define US_BULK_STAT_OK 0 36 + #define US_BULK_STAT_FAIL 1 37 + #define US_BULK_STAT_PHASE 2 38 + 39 + /* bulk-only class specific requests */ 40 + #define US_BULK_RESET_REQUEST 0xff 41 + #define US_BULK_GET_MAX_LUN 0xfe 42 + 43 + /* usb_stor_bulk_transfer_xxx() return codes, in order of severity */ 44 + #define USB_STOR_XFER_GOOD 0 /* good transfer */ 45 + #define USB_STOR_XFER_SHORT 1 /* transferred less than expected */ 46 + #define USB_STOR_XFER_STALLED 2 /* endpoint stalled */ 47 + #define USB_STOR_XFER_LONG 3 /* device tried to send too much */ 48 + #define USB_STOR_XFER_ERROR 4 /* transfer died in the middle */ 49 + 50 + /* Transport return codes */ 51 + #define USB_STOR_TRANSPORT_GOOD 0 /* Transport good, command good */ 52 + #define USB_STOR_TRANSPORT_FAILED 1 /* Transport good, command failed */ 53 + #define USB_STOR_TRANSPORT_NO_SENSE 2 /* Command failed, no auto-sense */ 54 + #define USB_STOR_TRANSPORT_ERROR 3 /* Transport bad (i.e. device dead) */ 55 + 56 + /* 57 + * We used to have USB_STOR_XFER_ABORTED and USB_STOR_TRANSPORT_ABORTED 58 + * return codes. But now the transport and low-level transfer routines 59 + * treat an abort as just another error (-ENOENT for a cancelled URB). 60 + * It is up to the invoke_transport() function to test for aborts and 61 + * distinguish them from genuine communication errors. 62 + */ 63 + 64 + /* CBI accept device specific command */ 65 + #define US_CBI_ADSC 0 66 + extern int usb_stor_Bulk_transport(struct scsi_cmnd *, struct us_data*); 67 + extern int usb_stor_Bulk_max_lun(struct us_data*); 68 + extern int usb_stor_Bulk_reset(struct us_data*); 69 + extern void usb_stor_print_cmd(struct scsi_cmnd *); 70 + extern void usb_stor_invoke_transport(struct scsi_cmnd *, struct us_data*); 71 + extern void usb_stor_stop_transport(struct us_data*); 72 + extern int usb_stor_control_msg(struct us_data *us, unsigned int pipe, 73 + u8 request, u8 requesttype, u16 value, u16 index, 74 + void *data, u16 size, int timeout); 75 + extern int usb_stor_clear_halt(struct us_data *us, unsigned int pipe); 76 + extern int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe, 77 + void *buf, unsigned int length, unsigned int *act_len); 78 + extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe, 79 + void *buf, unsigned int length, int use_sg, int *residual); 80 + extern int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe, 81 + struct scsi_cmnd* srb); 82 + extern int usb_stor_port_reset(struct us_data *us); 83 + 84 + /* Protocol handling routines */ 85 + enum xfer_buf_dir {TO_XFER_BUF, FROM_XFER_BUF}; 86 + extern unsigned int usb_stor_access_xfer_buf(struct us_data*, unsigned char *buffer, 87 + unsigned int buflen, struct scsi_cmnd *srb, struct scatterlist **, 88 + unsigned int *offset, enum xfer_buf_dir dir); 89 + extern void usb_stor_set_xfer_buf(struct us_data*, unsigned char *buffer, unsigned int buflen, struct scsi_cmnd *srb, 90 + unsigned int dir); 91 + 92 + // ENE scsi function 93 + extern void ENE_stor_invoke_transport(struct scsi_cmnd *, struct us_data*); 94 + extern int ENE_InitMedia(struct us_data*); 95 + extern int ENE_SDInit(struct us_data*); 96 + extern int ENE_MSInit(struct us_data*); 97 + extern int ENE_SMInit(struct us_data*); 98 + extern int ENE_ReadSDReg(struct us_data*, u8*); 99 + extern int ENE_SendScsiCmd(struct us_data*, BYTE, void*, int); 100 + extern int ENE_LoadBinCode(struct us_data*, BYTE); 101 + extern int ENE_Read_BYTE(struct us_data*, WORD index, void *buf); 102 + extern int ENE_Read_Data(struct us_data*, void *buf, unsigned int length); 103 + extern int ENE_Write_Data(struct us_data*, void *buf, unsigned int length); 104 + extern void BuildSenseBuffer(struct scsi_cmnd *, int); 105 + 106 + // ENE scsi function 107 + extern int SD_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb); 108 + extern int MS_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb); 109 + extern int SM_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb); 110 + 111 + // ENE MS function 112 + extern int MS_CardInit(struct us_data *us); 113 + extern void MS_LibFreeAllocatedArea(struct us_data *us); 114 + extern void MS_LibFreeWriteBuf(struct us_data *us); 115 + extern int MS_LibFreeLogicalMap(struct us_data *us); 116 + extern int MS_LibForceSetLogicalPair(struct us_data *us, WORD logblk, WORD phyblk); 117 + extern int MS_ReaderReadPage(struct us_data *us, DWORD PhyBlockAddr, BYTE PageNum, DWORD *PageBuf, MS_LibTypeExtdat *ExtraDat); 118 + extern int MS_ReaderCopyBlock(struct us_data *us, WORD oldphy, WORD newphy, WORD PhyBlockAddr, BYTE PageNum, PBYTE buf, WORD len); 119 + extern int MS_ReaderEraseBlock(struct us_data *us, DWORD PhyBlockAddr); 120 + extern int MS_LibProcessBootBlock(struct us_data *us, WORD PhyBlock, BYTE *PageData); 121 + extern int MS_LibAllocLogicalMap(struct us_data *us); 122 + extern int MS_LibSetBootBlockMark(struct us_data *us, WORD phyblk); 123 + extern int MS_LibSetLogicalBlockMark(struct us_data *us, WORD phyblk, WORD mark); 124 + extern int MS_LibSetInitialErrorBlock(struct us_data *us, WORD phyblk); 125 + extern int MS_LibScanLogicalBlockNumber(struct us_data *us, WORD phyblk); 126 + extern int MS_LibAllocWriteBuf(struct us_data *us); 127 + void MS_LibClearWriteBuf(struct us_data *us); 128 + void MS_LibPhy2LogRange(WORD PhyBlock, WORD *LogStart, WORD *LogEnde); 129 + extern int MS_LibReadExtra(struct us_data *us, DWORD PhyBlock, BYTE PageNum, MS_LibTypeExtdat *ExtraDat); 130 + extern int MS_LibReadExtraBlock(struct us_data *us, DWORD PhyBlock, BYTE PageNum, BYTE blen, void *buf); 131 + extern int MS_LibSetAcquiredErrorBlock(struct us_data *us, WORD phyblk); 132 + extern int MS_LibErasePhyBlock(struct us_data *us, WORD phyblk); 133 + extern int MS_LibErrorPhyBlock(struct us_data *us, WORD phyblk); 134 + extern int MS_LibOverwriteExtra(struct us_data *us, DWORD PhyBlockAddr, BYTE PageNum, BYTE OverwriteFlag); 135 + extern int MS_LibSetLogicalPair(struct us_data *us, WORD logblk, WORD phyblk); 136 + extern int MS_LibCheckDisableBlock(struct us_data *us, WORD PhyBlock); 137 + extern int MS_CountFreeBlock(struct us_data *us, WORD PhyBlock); 138 + extern int MS_LibSearchBlockFromLogical(struct us_data *us, WORD logblk); 139 + extern int MS_LibSearchBlockFromPhysical(struct us_data *us, WORD phyblk); 140 + 141 + // ENE SM function 142 + extern int SM_FreeMem(void); 143 + 144 + #endif
+701
drivers/staging/keucr/usb.c
··· 1 + #include <linux/sched.h> 2 + #include <linux/errno.h> 3 + #include <linux/freezer.h> 4 + #include <linux/module.h> 5 + #include <linux/init.h> 6 + #include <linux/slab.h> 7 + #include <linux/kthread.h> 8 + #include <linux/mutex.h> 9 + #include <linux/utsname.h> 10 + 11 + #include <scsi/scsi.h> 12 + #include <scsi/scsi_cmnd.h> 13 + #include <scsi/scsi_device.h> 14 + 15 + #include "usb.h" 16 + #include "scsiglue.h" 17 + #include "transport.h" 18 + 19 + /* Some informational data */ 20 + MODULE_AUTHOR("Domao"); 21 + MODULE_DESCRIPTION("ENE USB Mass Storage driver for Linux"); 22 + MODULE_LICENSE("GPL"); 23 + 24 + static struct usb_device_id eucr_usb_ids [] = { 25 + { USB_DEVICE(0x058f, 0x6366) }, 26 + { USB_DEVICE(0x0cf2, 0x6230) }, 27 + { USB_DEVICE(0x0cf2, 0x6250) }, 28 + { } /* Terminating entry */ 29 + }; 30 + MODULE_DEVICE_TABLE (usb, eucr_usb_ids); 31 + 32 + 33 + 34 + int eucr_suspend(struct usb_interface *iface, pm_message_t message) 35 + { 36 + struct us_data *us = usb_get_intfdata(iface); 37 + printk("--- eucr_suspend ---\n"); 38 + /* Wait until no command is running */ 39 + mutex_lock(&us->dev_mutex); 40 + 41 + //US_DEBUGP("%s\n", __func__); 42 + if (us->suspend_resume_hook) 43 + (us->suspend_resume_hook)(us, US_SUSPEND); 44 + 45 + /* When runtime PM is working, we'll set a flag to indicate 46 + * whether we should autoresume when a SCSI request arrives. */ 47 + // us->Power_IsResum = true; 48 + //us->SD_Status.Ready = 0; 49 + 50 + mutex_unlock(&us->dev_mutex); 51 + return 0; 52 + } 53 + //EXPORT_SYMBOL_GPL(eucr_suspend); 54 + 55 + int eucr_resume(struct usb_interface *iface) 56 + { 57 + BYTE tmp = 0; 58 + 59 + struct us_data *us = usb_get_intfdata(iface); 60 + printk("--- eucr_resume---\n"); 61 + mutex_lock(&us->dev_mutex); 62 + 63 + //US_DEBUGP("%s\n", __func__); 64 + if (us->suspend_resume_hook) 65 + (us->suspend_resume_hook)(us, US_RESUME); 66 + 67 + 68 + mutex_unlock(&us->dev_mutex); 69 + 70 + 71 + us->Power_IsResum = true; 72 + // 73 + //us->SD_Status.Ready = 0; //?? 74 + us->SD_Status = *(PSD_STATUS)&tmp; 75 + us->MS_Status = *(PMS_STATUS)&tmp; 76 + us->SM_Status = *(PSM_STATUS)&tmp; 77 + 78 + return 0; 79 + } 80 + //EXPORT_SYMBOL_GPL(eucr_resume); 81 + int eucr_reset_resume(struct usb_interface *iface) 82 + { 83 + BYTE tmp = 0; 84 + struct us_data *us = usb_get_intfdata(iface); 85 + 86 + printk("--- eucr_reset_resume---\n"); 87 + //US_DEBUGP("%s\n", __func__); 88 + 89 + /* Report the reset to the SCSI core */ 90 + usb_stor_report_bus_reset(us); 91 + 92 + /* FIXME: Notify the subdrivers that they need to reinitialize 93 + * the device */ 94 + //ENE_InitMedia(us); 95 + us->Power_IsResum = true; 96 + // 97 + //us->SD_Status.Ready = 0; //?? 98 + us->SD_Status = *(PSD_STATUS)&tmp; 99 + us->MS_Status = *(PMS_STATUS)&tmp; 100 + us->SM_Status = *(PSM_STATUS)&tmp; 101 + return 0; 102 + } 103 + //EXPORT_SYMBOL_GPL(usb_stor_reset_resume); 104 + 105 + //----- eucr_pre_reset() --------------------- 106 + static int eucr_pre_reset(struct usb_interface *iface) 107 + { 108 + struct us_data *us = usb_get_intfdata(iface); 109 + 110 + printk("usb --- eucr_pre_reset\n"); 111 + 112 + /* Make sure no command runs during the reset */ 113 + mutex_lock(&us->dev_mutex); 114 + return 0; 115 + } 116 + 117 + //----- eucr_post_reset() --------------------- 118 + static int eucr_post_reset(struct usb_interface *iface) 119 + { 120 + struct us_data *us = usb_get_intfdata(iface); 121 + 122 + printk("usb --- eucr_post_reset\n"); 123 + 124 + /* Report the reset to the SCSI core */ 125 + usb_stor_report_bus_reset(us); 126 + 127 + mutex_unlock(&us->dev_mutex); 128 + return 0; 129 + } 130 + 131 + //----- fill_inquiry_response() --------------------- 132 + void fill_inquiry_response(struct us_data *us, unsigned char *data, unsigned int data_len) 133 + { 134 + printk("usb --- fill_inquiry_response\n"); 135 + if (data_len<36) // You lose. 136 + return; 137 + 138 + if (data[0]&0x20) 139 + { 140 + memset(data+8,0,28); 141 + } 142 + else 143 + { 144 + u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice); 145 + memcpy(data+8, us->unusual_dev->vendorName, 146 + strlen(us->unusual_dev->vendorName) > 8 ? 8 : 147 + strlen(us->unusual_dev->vendorName)); 148 + memcpy(data+16, us->unusual_dev->productName, 149 + strlen(us->unusual_dev->productName) > 16 ? 16 : 150 + strlen(us->unusual_dev->productName)); 151 + data[32] = 0x30 + ((bcdDevice>>12) & 0x0F); 152 + data[33] = 0x30 + ((bcdDevice>>8) & 0x0F); 153 + data[34] = 0x30 + ((bcdDevice>>4) & 0x0F); 154 + data[35] = 0x30 + ((bcdDevice) & 0x0F); 155 + } 156 + usb_stor_set_xfer_buf(us, data, data_len, us->srb, TO_XFER_BUF); 157 + } 158 + 159 + //----- usb_stor_control_thread() --------------------- 160 + static int usb_stor_control_thread(void * __us) 161 + { 162 + struct us_data *us = (struct us_data *)__us; 163 + struct Scsi_Host *host = us_to_host(us); 164 + 165 + printk("usb --- usb_stor_control_thread\n"); 166 + for(;;) 167 + { 168 + if (wait_for_completion_interruptible(&us->cmnd_ready)) 169 + break; 170 + 171 + /* lock the device pointers */ 172 + mutex_lock(&(us->dev_mutex)); 173 + 174 + /* if the device has disconnected, we are free to exit */ 175 + /* if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) 176 + { 177 + mutex_unlock(&us->dev_mutex); 178 + break; 179 + }*/ 180 + 181 + /* lock access to the state */ 182 + scsi_lock(host); 183 + 184 + /* When we are called with no command pending, we're done */ 185 + if (us->srb == NULL) 186 + { 187 + scsi_unlock(host); 188 + mutex_unlock(&us->dev_mutex); 189 + //US_DEBUGP("-- exiting\n"); 190 + break; 191 + } 192 + 193 + /* has the command timed out *already* ? */ 194 + if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) 195 + { 196 + us->srb->result = DID_ABORT << 16; 197 + goto SkipForAbort; 198 + } 199 + 200 + scsi_unlock(host); 201 + 202 + if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL) 203 + { 204 + us->srb->result = DID_ERROR << 16; 205 + } 206 + else if (us->srb->device->id && !(us->fflags & US_FL_SCM_MULT_TARG)) 207 + { 208 + us->srb->result = DID_BAD_TARGET << 16; 209 + } 210 + else if (us->srb->device->lun > us->max_lun) 211 + { 212 + us->srb->result = DID_BAD_TARGET << 16; 213 + } 214 + else if ((us->srb->cmnd[0] == INQUIRY) && (us->fflags & US_FL_FIX_INQUIRY)) 215 + { 216 + unsigned char data_ptr[36] = {0x00, 0x80, 0x02, 0x02, 0x1F, 0x00, 0x00, 0x00}; 217 + 218 + fill_inquiry_response(us, data_ptr, 36); 219 + us->srb->result = SAM_STAT_GOOD; 220 + } 221 + else 222 + { 223 + us->proto_handler(us->srb, us); 224 + } 225 + 226 + /* lock access to the state */ 227 + scsi_lock(host); 228 + 229 + /* indicate that the command is done */ 230 + if (us->srb->result != DID_ABORT << 16) 231 + { 232 + us->srb->scsi_done(us->srb); 233 + } 234 + else 235 + { 236 + SkipForAbort: 237 + printk("scsi command aborted\n"); 238 + } 239 + 240 + if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) 241 + { 242 + complete(&(us->notify)); 243 + 244 + /* Allow USB transfers to resume */ 245 + clear_bit(US_FLIDX_ABORTING, &us->dflags); 246 + clear_bit(US_FLIDX_TIMED_OUT, &us->dflags); 247 + } 248 + 249 + /* finished working on this command */ 250 + us->srb = NULL; 251 + scsi_unlock(host); 252 + 253 + /* unlock the device pointers */ 254 + mutex_unlock(&us->dev_mutex); 255 + } /* for (;;) */ 256 + 257 + /* Wait until we are told to stop */ 258 + for (;;) 259 + { 260 + set_current_state(TASK_INTERRUPTIBLE); 261 + if (kthread_should_stop()) 262 + break; 263 + schedule(); 264 + } 265 + __set_current_state(TASK_RUNNING); 266 + return 0; 267 + } 268 + 269 + //----- associate_dev() --------------------- 270 + static int associate_dev(struct us_data *us, struct usb_interface *intf) 271 + { 272 + printk("usb --- associate_dev\n"); 273 + 274 + /* Fill in the device-related fields */ 275 + us->pusb_dev = interface_to_usbdev(intf); 276 + us->pusb_intf = intf; 277 + us->ifnum = intf->cur_altsetting->desc.bInterfaceNumber; 278 + 279 + /* Store our private data in the interface */ 280 + usb_set_intfdata(intf, us); 281 + 282 + /* Allocate the device-related DMA-mapped buffers */ 283 + us->cr = usb_alloc_coherent(us->pusb_dev, sizeof(*us->cr), GFP_KERNEL, &us->cr_dma); 284 + if (!us->cr) 285 + { 286 + printk("usb_ctrlrequest allocation failed\n"); 287 + return -ENOMEM; 288 + } 289 + 290 + us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE, GFP_KERNEL, &us->iobuf_dma); 291 + if (!us->iobuf) 292 + { 293 + printk("I/O buffer allocation failed\n"); 294 + return -ENOMEM; 295 + } 296 + 297 + us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL); 298 + if (!us->sensebuf) 299 + { 300 + printk("Sense buffer allocation failed\n"); 301 + return -ENOMEM; 302 + } 303 + return 0; 304 + } 305 + 306 + //----- get_device_info() --------------------- 307 + static int get_device_info(struct us_data *us, const struct usb_device_id *id) 308 + { 309 + struct usb_device *dev = us->pusb_dev; 310 + struct usb_interface_descriptor *idesc = &us->pusb_intf->cur_altsetting->desc; 311 + 312 + printk("usb --- get_device_info\n"); 313 + 314 + us->subclass = idesc->bInterfaceSubClass; 315 + us->protocol = idesc->bInterfaceProtocol; 316 + us->fflags = USB_US_ORIG_FLAGS(id->driver_info); 317 + us->Power_IsResum = false; 318 + 319 + if (us->fflags & US_FL_IGNORE_DEVICE) 320 + { 321 + printk("device ignored\n"); 322 + return -ENODEV; 323 + } 324 + 325 + if (dev->speed != USB_SPEED_HIGH) 326 + us->fflags &= ~US_FL_GO_SLOW; 327 + 328 + return 0; 329 + } 330 + 331 + //----- get_transport() --------------------- 332 + static int get_transport(struct us_data *us) 333 + { 334 + printk("usb --- get_transport\n"); 335 + switch (us->protocol) { 336 + case US_PR_BULK: 337 + us->transport_name = "Bulk"; 338 + us->transport = usb_stor_Bulk_transport; 339 + us->transport_reset = usb_stor_Bulk_reset; 340 + break; 341 + 342 + default: 343 + return -EIO; 344 + } 345 + //printk("Transport: %s\n", us->transport_name); 346 + 347 + /* fix for single-lun devices */ 348 + if (us->fflags & US_FL_SINGLE_LUN) 349 + us->max_lun = 0; 350 + return 0; 351 + } 352 + 353 + //----- get_protocol() --------------------- 354 + static int get_protocol(struct us_data *us) 355 + { 356 + printk("usb --- get_protocol\n"); 357 + printk("us->pusb_dev->descriptor.idVendor = %x\n", us->pusb_dev->descriptor.idVendor); 358 + printk("us->pusb_dev->descriptor.idProduct = %x\n", us->pusb_dev->descriptor.idProduct); 359 + switch (us->subclass) { 360 + case US_SC_SCSI: 361 + us->protocol_name = "Transparent SCSI"; 362 + if( (us->pusb_dev->descriptor.idVendor == 0x0CF2) && (us->pusb_dev->descriptor.idProduct == 0x6250) ) 363 + us->proto_handler = ENE_stor_invoke_transport; 364 + else 365 + us->proto_handler = usb_stor_invoke_transport; 366 + break; 367 + 368 + default: 369 + return -EIO; 370 + } 371 + //printk("Protocol: %s\n", us->protocol_name); 372 + return 0; 373 + } 374 + 375 + //----- get_pipes() --------------------- 376 + static int get_pipes(struct us_data *us) 377 + { 378 + struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting; 379 + int i; 380 + struct usb_endpoint_descriptor *ep; 381 + struct usb_endpoint_descriptor *ep_in = NULL; 382 + struct usb_endpoint_descriptor *ep_out = NULL; 383 + struct usb_endpoint_descriptor *ep_int = NULL; 384 + 385 + printk("usb --- get_pipes\n"); 386 + 387 + for (i = 0; i < altsetting->desc.bNumEndpoints; i++) 388 + { 389 + ep = &altsetting->endpoint[i].desc; 390 + 391 + if (usb_endpoint_xfer_bulk(ep)) 392 + { 393 + if (usb_endpoint_dir_in(ep)) 394 + { 395 + if (!ep_in) 396 + ep_in = ep; 397 + } 398 + else 399 + { 400 + if (!ep_out) 401 + ep_out = ep; 402 + } 403 + } 404 + else if (usb_endpoint_is_int_in(ep)) 405 + { 406 + if (!ep_int) 407 + ep_int = ep; 408 + } 409 + } 410 + 411 + if (!ep_in || !ep_out || (us->protocol == US_PR_CBI && !ep_int)) 412 + { 413 + printk("Endpoint sanity check failed! Rejecting dev.\n"); 414 + return -EIO; 415 + } 416 + 417 + /* Calculate and store the pipe values */ 418 + us->send_ctrl_pipe = usb_sndctrlpipe(us->pusb_dev, 0); 419 + us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0); 420 + us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev, ep_out->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 421 + us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev, ep_in->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 422 + if (ep_int) 423 + { 424 + us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev, ep_int->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 425 + us->ep_bInterval = ep_int->bInterval; 426 + } 427 + return 0; 428 + } 429 + 430 + //----- usb_stor_acquire_resources() --------------------- 431 + static int usb_stor_acquire_resources(struct us_data *us) 432 + { 433 + struct task_struct *th; 434 + 435 + printk("usb --- usb_stor_acquire_resources\n"); 436 + us->current_urb = usb_alloc_urb(0, GFP_KERNEL); 437 + if (!us->current_urb) 438 + { 439 + printk("URB allocation failed\n"); 440 + return -ENOMEM; 441 + } 442 + 443 + /* Start up our control thread */ 444 + th = kthread_run(usb_stor_control_thread, us, "eucr-storage"); 445 + if (IS_ERR(th)) 446 + { 447 + printk("Unable to start control thread\n"); 448 + return PTR_ERR(th); 449 + } 450 + us->ctl_thread = th; 451 + 452 + return 0; 453 + } 454 + 455 + //----- usb_stor_release_resources() --------------------- 456 + static void usb_stor_release_resources(struct us_data *us) 457 + { 458 + printk("usb --- usb_stor_release_resources\n"); 459 + 460 + SM_FreeMem(); 461 + 462 + complete(&us->cmnd_ready); 463 + if (us->ctl_thread) 464 + kthread_stop(us->ctl_thread); 465 + 466 + /* Call the destructor routine, if it exists */ 467 + if (us->extra_destructor) 468 + { 469 + printk("-- calling extra_destructor()\n"); 470 + us->extra_destructor(us->extra); 471 + } 472 + 473 + /* Free the extra data and the URB */ 474 + kfree(us->extra); 475 + usb_free_urb(us->current_urb); 476 + } 477 + 478 + //----- dissociate_dev() --------------------- 479 + static void dissociate_dev(struct us_data *us) 480 + { 481 + printk("usb --- dissociate_dev\n"); 482 + 483 + kfree(us->sensebuf); 484 + 485 + /* Free the device-related DMA-mapped buffers */ 486 + if (us->cr) 487 + usb_free_coherent(us->pusb_dev, sizeof(*us->cr), us->cr, us->cr_dma); 488 + if (us->iobuf) 489 + usb_free_coherent(us->pusb_dev, US_IOBUF_SIZE, us->iobuf, us->iobuf_dma); 490 + 491 + /* Remove our private data from the interface */ 492 + usb_set_intfdata(us->pusb_intf, NULL); 493 + } 494 + 495 + //----- quiesce_and_remove_host() --------------------- 496 + static void quiesce_and_remove_host(struct us_data *us) 497 + { 498 + struct Scsi_Host *host = us_to_host(us); 499 + 500 + printk("usb --- quiesce_and_remove_host\n"); 501 + 502 + /* If the device is really gone, cut short reset delays */ 503 + if (us->pusb_dev->state == USB_STATE_NOTATTACHED) 504 + set_bit(US_FLIDX_DISCONNECTING, &us->dflags); 505 + 506 + /* Prevent SCSI-scanning (if it hasn't started yet) 507 + * and wait for the SCSI-scanning thread to stop. 508 + */ 509 + set_bit(US_FLIDX_DONT_SCAN, &us->dflags); 510 + wake_up(&us->delay_wait); 511 + wait_for_completion(&us->scanning_done); 512 + 513 + /* Removing the host will perform an orderly shutdown: caches 514 + * synchronized, disks spun down, etc. 515 + */ 516 + scsi_remove_host(host); 517 + 518 + /* Prevent any new commands from being accepted and cut short 519 + * reset delays. 520 + */ 521 + scsi_lock(host); 522 + set_bit(US_FLIDX_DISCONNECTING, &us->dflags); 523 + scsi_unlock(host); 524 + wake_up(&us->delay_wait); 525 + } 526 + 527 + //----- release_everything() --------------------- 528 + static void release_everything(struct us_data *us) 529 + { 530 + printk("usb --- release_everything\n"); 531 + 532 + usb_stor_release_resources(us); 533 + dissociate_dev(us); 534 + scsi_host_put(us_to_host(us)); 535 + } 536 + 537 + //----- usb_stor_scan_thread() --------------------- 538 + static int usb_stor_scan_thread(void * __us) 539 + { 540 + struct us_data *us = (struct us_data *)__us; 541 + 542 + printk("usb --- usb_stor_scan_thread\n"); 543 + printk("EUCR : device found at %d\n", us->pusb_dev->devnum); 544 + 545 + // Have we to add this code ? 546 + // set_freezable(); 547 + // /* Wait for the timeout to expire or for a disconnect */ 548 + // if (delay_use > 0) 549 + // { 550 + // wait_event_freezable_timeout(us->delay_wait, 551 + // test_bit(US_FLIDX_DONT_SCAN, &us->dflags), 552 + // delay_use * HZ); 553 + // } 554 + 555 + /* If the device is still connected, perform the scanning */ 556 + if (!test_bit(US_FLIDX_DONT_SCAN, &us->dflags)) 557 + { 558 + /* For bulk-only devices, determine the max LUN value */ 559 + if (us->protocol == US_PR_BULK && !(us->fflags & US_FL_SINGLE_LUN)) 560 + { 561 + mutex_lock(&us->dev_mutex); 562 + us->max_lun = usb_stor_Bulk_max_lun(us); 563 + mutex_unlock(&us->dev_mutex); 564 + } 565 + scsi_scan_host(us_to_host(us)); 566 + printk("EUCR : device scan complete\n"); 567 + } 568 + complete_and_exit(&us->scanning_done, 0); 569 + } 570 + 571 + //----- eucr_probe() --------------------- 572 + static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id) 573 + { 574 + struct Scsi_Host *host; 575 + struct us_data *us; 576 + int result; 577 + struct task_struct *th; 578 + 579 + printk("usb --- eucr_probe\n"); 580 + 581 + host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us)); 582 + if (!host) 583 + { 584 + printk("Unable to allocate the scsi host\n"); 585 + return -ENOMEM; 586 + } 587 + 588 + /* Allow 16-byte CDBs and thus > 2TB */ 589 + host->max_cmd_len = 16; 590 + us = host_to_us(host); 591 + memset(us, 0, sizeof(struct us_data)); 592 + mutex_init(&(us->dev_mutex)); 593 + init_completion(&us->cmnd_ready); 594 + init_completion(&(us->notify)); 595 + init_waitqueue_head(&us->delay_wait); 596 + init_completion(&us->scanning_done); 597 + 598 + /* Associate the us_data structure with the USB device */ 599 + result = associate_dev(us, intf); 600 + if (result) 601 + goto BadDevice; 602 + 603 + /* Get Device info */ 604 + result = get_device_info(us, id); 605 + if (result) 606 + goto BadDevice; 607 + 608 + /* Get the transport, protocol, and pipe settings */ 609 + result = get_transport(us); 610 + if (result) 611 + goto BadDevice; 612 + result = get_protocol(us); 613 + if (result) 614 + goto BadDevice; 615 + result = get_pipes(us); 616 + if (result) 617 + goto BadDevice; 618 + 619 + /* Acquire all the other resources and add the host */ 620 + result = usb_stor_acquire_resources(us); 621 + if (result) 622 + goto BadDevice; 623 + 624 + result = scsi_add_host(host, &intf->dev); 625 + if (result) 626 + { 627 + printk("Unable to add the scsi host\n"); 628 + goto BadDevice; 629 + } 630 + 631 + /* Start up the thread for delayed SCSI-device scanning */ 632 + th = kthread_create(usb_stor_scan_thread, us, "eucr-stor-scan"); 633 + if (IS_ERR(th)) 634 + { 635 + printk("Unable to start the device-scanning thread\n"); 636 + complete(&us->scanning_done); 637 + quiesce_and_remove_host(us); 638 + result = PTR_ERR(th); 639 + goto BadDevice; 640 + } 641 + wake_up_process(th); 642 + return 0; 643 + 644 + /* We come here if there are any problems */ 645 + BadDevice: 646 + printk("usb --- eucr_probe failed\n"); 647 + release_everything(us); 648 + return result; 649 + } 650 + 651 + //----- eucr_disconnect() --------------------- 652 + static void eucr_disconnect(struct usb_interface *intf) 653 + { 654 + struct us_data *us = usb_get_intfdata(intf); 655 + 656 + printk("usb --- eucr_disconnect\n"); 657 + quiesce_and_remove_host(us); 658 + release_everything(us); 659 + } 660 + 661 + /*********************************************************************** 662 + * Initialization and registration 663 + ***********************************************************************/ 664 + 665 + //----- usb_storage_driver() --------------------- 666 + static struct usb_driver usb_storage_driver = { 667 + .name = "eucr", 668 + .probe = eucr_probe, 669 + .suspend = eucr_suspend, 670 + .resume = eucr_resume, 671 + .reset_resume = eucr_reset_resume, 672 + .disconnect = eucr_disconnect, 673 + .pre_reset = eucr_pre_reset, 674 + .post_reset = eucr_post_reset, 675 + .id_table = eucr_usb_ids, 676 + .soft_unbind = 1, 677 + }; 678 + 679 + //----- usb_stor_init() --------------------- 680 + static int __init usb_stor_init(void) 681 + { 682 + int retval; 683 + printk("usb --- usb_stor_init start\n"); 684 + 685 + retval = usb_register(&usb_storage_driver); 686 + if (retval == 0) 687 + printk("ENE USB Mass Storage support registered.\n"); 688 + 689 + return retval; 690 + } 691 + 692 + //----- usb_stor_exit() --------------------- 693 + static void __exit usb_stor_exit(void) 694 + { 695 + printk("usb --- usb_stor_exit\n"); 696 + 697 + usb_deregister(&usb_storage_driver) ; 698 + } 699 + 700 + module_init(usb_stor_init); 701 + module_exit(usb_stor_exit);
+238
drivers/staging/keucr/usb.h
··· 1 + // Driver for USB Mass Storage compliant devices 2 + 3 + #ifndef _USB_H_ 4 + #define _USB_H_ 5 + 6 + #include <linux/usb.h> 7 + #include <linux/usb_usual.h> 8 + #include <linux/blkdev.h> 9 + #include <linux/completion.h> 10 + #include <linux/mutex.h> 11 + #include <scsi/scsi_host.h> 12 + #include "common.h" 13 + #include "ms.h" 14 + 15 + struct us_data; 16 + struct scsi_cmnd; 17 + 18 + /* 19 + * Unusual device list definitions 20 + */ 21 + 22 + struct us_unusual_dev { 23 + const char* vendorName; 24 + const char* productName; 25 + __u8 useProtocol; 26 + __u8 useTransport; 27 + int (*initFunction)(struct us_data *); 28 + }; 29 + 30 + //EnE HW Register 31 + #define REG_CARD_STATUS 0xFF83 32 + #define REG_HW_TRAP1 0xFF89 33 + 34 + // SRB Status. Refers /usr/include/wine/wine/wnaspi32.h & SCSI sense key 35 + #define SS_SUCCESS 0x00 // No Sense 36 + #define SS_NOT_READY 0x02 37 + #define SS_MEDIUM_ERR 0x03 38 + #define SS_HW_ERR 0x04 39 + #define SS_ILLEGAL_REQUEST 0x05 40 + #define SS_UNIT_ATTENTION 0x06 41 + 42 + //ENE Load FW Pattern 43 + #define SD_INIT1_PATTERN 1 44 + #define SD_INIT2_PATTERN 2 45 + #define SD_RW_PATTERN 3 46 + #define MS_INIT_PATTERN 4 47 + #define MSP_RW_PATTERN 5 48 + #define MS_RW_PATTERN 6 49 + #define SM_INIT_PATTERN 7 50 + #define SM_RW_PATTERN 8 51 + 52 + #define FDIR_WRITE 0 53 + #define FDIR_READ 1 54 + 55 + typedef struct _SD_STATUS { 56 + BYTE Insert:1; 57 + BYTE Ready:1; 58 + BYTE MediaChange:1; 59 + BYTE IsMMC:1; 60 + BYTE HiCapacity:1; 61 + BYTE HiSpeed:1; 62 + BYTE WtP:1; 63 + BYTE Reserved:1; 64 + } SD_STATUS, *PSD_STATUS; 65 + 66 + typedef struct _MS_STATUS { 67 + BYTE Insert:1; 68 + BYTE Ready:1; 69 + BYTE MediaChange:1; 70 + BYTE IsMSPro:1; 71 + BYTE IsMSPHG:1; 72 + BYTE Reserved1:1; 73 + BYTE WtP:1; 74 + BYTE Reserved2:1; 75 + } MS_STATUS, *PMS_STATUS; 76 + 77 + typedef struct _SM_STATUS { 78 + BYTE Insert:1; 79 + BYTE Ready:1; 80 + BYTE MediaChange:1; 81 + BYTE Reserved:3; 82 + BYTE WtP:1; 83 + BYTE IsMS:1; 84 + } SM_STATUS, *PSM_STATUS; 85 + 86 + // SD Block Length 87 + #define SD_BLOCK_LEN 9 // 2^9 = 512 Bytes, The HW maximum read/write data length 88 + 89 + /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */ 90 + #define US_FLIDX_URB_ACTIVE 0 /* current_urb is in use */ 91 + #define US_FLIDX_SG_ACTIVE 1 /* current_sg is in use */ 92 + #define US_FLIDX_ABORTING 2 /* abort is in progress */ 93 + #define US_FLIDX_DISCONNECTING 3 /* disconnect in progress */ 94 + #define US_FLIDX_RESETTING 4 /* device reset in progress */ 95 + #define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */ 96 + #define US_FLIDX_DONT_SCAN 6 /* don't scan (disconnect) */ 97 + 98 + 99 + #define USB_STOR_STRING_LEN 32 100 + 101 + /* 102 + * We provide a DMA-mapped I/O buffer for use with small USB transfers. 103 + * It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a 104 + * 31-byte buffer. But Freecom needs a 64-byte buffer, so that's the 105 + * size we'll allocate. 106 + */ 107 + 108 + #define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */ 109 + #define US_SENSE_SIZE 18 /* Size of the autosense data buffer */ 110 + 111 + typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*); 112 + typedef int (*trans_reset)(struct us_data*); 113 + typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*); 114 + typedef void (*extra_data_destructor)(void *); /* extra data destructor */ 115 + typedef void (*pm_hook)(struct us_data *, int); /* power management hook */ 116 + 117 + #define US_SUSPEND 0 118 + #define US_RESUME 1 119 + 120 + /* we allocate one of these for every device that we remember */ 121 + struct us_data { 122 + /* The device we're working with 123 + * It's important to note: 124 + * (o) you must hold dev_mutex to change pusb_dev 125 + */ 126 + struct mutex dev_mutex; /* protect pusb_dev */ 127 + struct usb_device *pusb_dev; /* this usb_device */ 128 + struct usb_interface *pusb_intf; /* this interface */ 129 + struct us_unusual_dev *unusual_dev; /* device-filter entry */ 130 + unsigned long fflags; /* fixed flags from filter */ 131 + unsigned long dflags; /* dynamic atomic bitflags */ 132 + unsigned int send_bulk_pipe; /* cached pipe values */ 133 + unsigned int recv_bulk_pipe; 134 + unsigned int send_ctrl_pipe; 135 + unsigned int recv_ctrl_pipe; 136 + unsigned int recv_intr_pipe; 137 + 138 + /* information about the device */ 139 + char *transport_name; 140 + char *protocol_name; 141 + __le32 bcs_signature; 142 + u8 subclass; 143 + u8 protocol; 144 + u8 max_lun; 145 + 146 + u8 ifnum; /* interface number */ 147 + u8 ep_bInterval; /* interrupt interval */ 148 + 149 + /* function pointers for this device */ 150 + trans_cmnd transport; /* transport function */ 151 + trans_reset transport_reset; /* transport device reset */ 152 + proto_cmnd proto_handler; /* protocol handler */ 153 + 154 + /* SCSI interfaces */ 155 + struct scsi_cmnd *srb; /* current srb */ 156 + unsigned int tag; /* current dCBWTag */ 157 + 158 + /* control and bulk communications data */ 159 + struct urb *current_urb; /* USB requests */ 160 + struct usb_ctrlrequest *cr; /* control requests */ 161 + struct usb_sg_request current_sg; /* scatter-gather req. */ 162 + unsigned char *iobuf; /* I/O buffer */ 163 + unsigned char *sensebuf; /* sense data buffer */ 164 + dma_addr_t cr_dma; /* buffer DMA addresses */ 165 + dma_addr_t iobuf_dma; 166 + struct task_struct *ctl_thread; /* the control thread */ 167 + 168 + /* mutual exclusion and synchronization structures */ 169 + struct completion cmnd_ready; /* to sleep thread on */ 170 + struct completion notify; /* thread begin/end */ 171 + wait_queue_head_t delay_wait; /* wait during scan, reset */ 172 + struct completion scanning_done; /* wait for scan thread */ 173 + 174 + /* subdriver information */ 175 + void *extra; /* Any extra data */ 176 + extra_data_destructor extra_destructor;/* extra data destructor */ 177 + #ifdef CONFIG_PM 178 + pm_hook suspend_resume_hook; 179 + #endif 180 + // for 6250 code 181 + SD_STATUS SD_Status; 182 + MS_STATUS MS_Status; 183 + SM_STATUS SM_Status; 184 + 185 + //----- SD Control Data ---------------- 186 + //SD_REGISTER SD_Regs; 187 + WORD SD_Block_Mult; 188 + BYTE SD_READ_BL_LEN; 189 + WORD SD_C_SIZE; 190 + BYTE SD_C_SIZE_MULT; 191 + 192 + // SD/MMC New spec. 193 + BYTE SD_SPEC_VER; 194 + BYTE SD_CSD_VER; 195 + BYTE SD20_HIGH_CAPACITY; 196 + DWORD HC_C_SIZE; 197 + BYTE MMC_SPEC_VER; 198 + BYTE MMC_BusWidth; 199 + BYTE MMC_HIGH_CAPACITY; 200 + 201 + //----- MS Control Data ---------------- 202 + BOOLEAN MS_SWWP; 203 + DWORD MSP_TotalBlock; 204 + MS_LibControl MS_Lib; 205 + BOOLEAN MS_IsRWPage; 206 + WORD MS_Model; 207 + 208 + //----- SM Control Data ---------------- 209 + BYTE SM_DeviceID; 210 + BYTE SM_CardID; 211 + 212 + PBYTE testbuf; 213 + BYTE BIN_FLAG; 214 + DWORD bl_num; 215 + int SrbStatus; 216 + 217 + //------Power Managerment --------------- 218 + BOOLEAN Power_IsResum; 219 + }; 220 + 221 + /* Convert between us_data and the corresponding Scsi_Host */ 222 + static inline struct Scsi_Host *us_to_host(struct us_data *us) { 223 + return container_of((void *) us, struct Scsi_Host, hostdata); 224 + } 225 + static inline struct us_data *host_to_us(struct Scsi_Host *host) { 226 + return (struct us_data *) host->hostdata; 227 + } 228 + 229 + /* Function to fill an inquiry response. See usb.c for details */ 230 + extern void fill_inquiry_response(struct us_data *us, 231 + unsigned char *data, unsigned int data_len); 232 + 233 + /* The scsi_lock() and scsi_unlock() macros protect the sm_state and the 234 + * single queue element srb for write access */ 235 + #define scsi_unlock(host) spin_unlock_irq(host->host_lock) 236 + #define scsi_lock(host) spin_lock_irq(host->host_lock) 237 + 238 + #endif