ocfs2: fix possible use-after-free with AIO
[linux/fpc-iii.git] / drivers / staging / keucr / smilmain.c
blob31f7813cab0d6f6093fee72dbf1726e9ff96b556
1 #include <linux/slab.h>
2 #include "usb.h"
3 #include "scsiglue.h"
4 #include "smcommon.h"
5 #include "smil.h"
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);
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 *);
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 *);
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 *);
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);
46 int MarkFail_D_PhyOneBlock (struct us_data *);
48 DWORD ErrXDCode;
49 DWORD ErrCode;
50 //BYTE SectBuf[SECTSIZE];
51 static BYTE WorkBuf[SECTSIZE];
52 static BYTE Redundant[REDTSIZE];
53 static BYTE WorkRedund[REDTSIZE];
54 //WORD Log2Phy[MAX_ZONENUM][MAX_LOGBLOCK];
55 static WORD *Log2Phy[MAX_ZONENUM]; // 128 x 1000, Log2Phy[MAX_ZONENUM][MAX_LOGBLOCK];
56 static BYTE Assign[MAX_ZONENUM][MAX_BLOCKNUM/8];
57 static WORD AssignStart[MAX_ZONENUM];
58 WORD ReadBlock;
59 WORD WriteBlock;
60 DWORD MediaChange;
61 static DWORD SectCopyMode;
63 //BIT Control Macro
64 static BYTE BitData[] = { 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80 } ;
65 #define Set_D_Bit(a,b) (a[(BYTE)((b)/8)]|= BitData[(b)%8])
66 #define Clr_D_Bit(a,b) (a[(BYTE)((b)/8)]&=~BitData[(b)%8])
67 #define Chk_D_Bit(a,b) (a[(BYTE)((b)/8)] & BitData[(b)%8])
69 //extern PBYTE SMHostAddr;
70 BYTE IsSSFDCCompliance;
71 BYTE IsXDCompliance;
75 ////Power Control & Media Exist Check Function
76 ////----- Init_D_SmartMedia() --------------------------------------------
77 //int Init_D_SmartMedia(void)
78 //{
79 // int i;
81 // EMCR_Print("Init_D_SmartMedia start\n");
82 // for (i=0; i<MAX_ZONENUM; i++)
83 // {
84 // if (Log2Phy[i]!=NULL)
85 // {
86 // EMCR_Print("ExFreePool Zone = %x, Addr = %x\n", i, Log2Phy[i]);
87 // ExFreePool(Log2Phy[i]);
88 // Log2Phy[i] = NULL;
89 // }
90 // }
92 // Initialize_D_Media();
93 // return(NO_ERROR);
94 //}
96 //----- SM_FreeMem() -------------------------------------------------
97 int SM_FreeMem(void)
99 int i;
101 pr_info("SM_FreeMem start\n");
102 for (i=0; i<MAX_ZONENUM; i++)
104 if (Log2Phy[i]!=NULL)
106 pr_info("Free Zone = %x, Addr = %p\n", i, Log2Phy[i]);
107 kfree(Log2Phy[i]);
108 Log2Phy[i] = NULL;
111 return(NO_ERROR);
114 ////----- Pwoff_D_SmartMedia() -------------------------------------------
115 //int Pwoff_D_SmartMedia(void)
117 // PowerOff_D_Media();
118 // return(NO_ERROR);
121 ////----- Check_D_SmartMedia() -------------------------------------------
122 //int Check_D_SmartMedia(void)
124 // if (Check_D_MediaExist())
125 // return(ErrCode);
127 // return(NO_ERROR);
130 ////----- Check_D_Parameter() --------------------------------------------
131 //int Check_D_Parameter(PFDO_DEVICE_EXTENSION fdoExt,WORD *pcyl,BYTE *phead,BYTE *psect)
133 // if (Check_D_MediaPower())
134 // return(ErrCode);
136 // if (Check_D_MediaFmt(fdoExt))
137 // return(ErrCode);
139 // if (Check_D_LogCHS(pcyl,phead,psect))
140 // return(ErrCode);
142 // return(NO_ERROR);
145 //SmartMedia Read/Write/Erase Function
146 //----- Media_D_ReadSector() -------------------------------------------
147 int Media_D_ReadSector(struct us_data *us, DWORD start,WORD count,BYTE *buf)
149 WORD len, bn;
151 //if (Check_D_MediaPower()) ; ¦b 6250 don't care
152 // return(ErrCode);
153 //if (Check_D_MediaFmt(fdoExt)) ;
154 // return(ErrCode);
155 if (Conv_D_MediaAddr(us, start))
156 return(ErrCode);
158 while(1)
160 len = Ssfdc.MaxSectors - Media.Sector;
161 if (count > len)
162 bn = len;
163 else
164 bn = count;
165 //if (Media_D_ReadOneSect(fdoExt, SectBuf))
166 //if (Media_D_ReadOneSect(fdoExt, count, buf))
167 if (Media_D_ReadOneSect(us, bn, buf))
169 ErrCode = ERR_EccReadErr;
170 return(ErrCode);
173 Media.Sector += bn;
174 count -= bn;
176 if (count<=0)
177 break;
179 buf += bn * SECTSIZE;
181 if (Inc_D_MediaAddr(us))
182 return(ErrCode);
185 return(NO_ERROR);
187 // here
188 //----- Media_D_CopySector() ------------------------------------------
189 int Media_D_CopySector(struct us_data *us, DWORD start,WORD count,BYTE *buf)
191 //DWORD mode;
192 //int i;
193 WORD len, bn;
194 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
195 //ADDRESS_T bb = (ADDRESS_T) &Media;
197 /* pr_info("Media_D_CopySector !!!\n"); */
198 if (Conv_D_MediaAddr(us, start))
199 return(ErrCode);
201 while(1)
203 if (Assign_D_WriteBlock())
204 return(ERROR);
206 len = Ssfdc.MaxSectors - Media.Sector;
207 if (count > len)
208 bn = len;
209 else
210 bn = count;
212 //if (Ssfdc_D_CopyBlock(fdoExt,count,buf,Redundant))
213 if (Ssfdc_D_CopyBlock(us,bn,buf,Redundant))
215 ErrCode = ERR_WriteFault;
216 return(ErrCode);
219 Media.Sector = 0x1F;
220 //if (Release_D_ReadBlock(fdoExt))
221 if (Release_D_CopySector(us))
223 if (ErrCode==ERR_HwError)
225 ErrCode = ERR_WriteFault;
226 return(ErrCode);
229 count -= bn;
231 if (count<=0)
232 break;
234 buf += bn * SECTSIZE;
236 if (Inc_D_MediaAddr(us))
237 return(ErrCode);
240 return(NO_ERROR);
243 //----- Release_D_CopySector() ------------------------------------------
244 int Release_D_CopySector(struct us_data *us)
246 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
247 //ADDRESS_T bb = (ADDRESS_T) &Media;
249 Log2Phy[Media.Zone][Media.LogBlock]=WriteBlock;
250 Media.PhyBlock=ReadBlock;
252 if (Media.PhyBlock==NO_ASSIGN)
254 Media.PhyBlock=WriteBlock;
255 return(SMSUCCESS);
258 Clr_D_Bit(Assign[Media.Zone],Media.PhyBlock);
259 Media.PhyBlock=WriteBlock;
261 return(SMSUCCESS);
264 //----- Media_D_WriteSector() ------------------------------------------
265 int Media_D_WriteSector(PFDO_DEVICE_EXTENSION fdoExt, DWORD start,WORD count,BYTE *buf)
267 int i;
268 WORD len, bn;
269 SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
270 ADDRESS_T bb = (ADDRESS_T) &Media;
272 //if (Check_D_MediaPower())
273 // return(ErrCode);
275 //if (Check_D_MediaFmt(fdoExt))
276 // return(ErrCode);
278 //if (Check_D_MediaWP())
279 // return(ErrCode);
281 if (Conv_D_MediaAddr(fdoExt, start))
282 return(ErrCode);
284 //ENE_Print("Media_D_WriteSector --- Sector = %x\n", Media.Sector);
285 if (Check_D_FirstSect())
287 if (Media_D_CopyBlockHead(fdoExt))
289 ErrCode = ERR_WriteFault;
290 return(ErrCode);
294 while(1)
296 if (!Check_D_FirstSect())
298 if (Assign_D_WriteBlock())
299 return(ErrCode);
302 len = Ssfdc.MaxSectors - Media.Sector;
303 if (count > len)
304 bn = len;
305 else
306 bn = count;
307 //for(i=0;i<SECTSIZE;i++)
308 // SectBuf[i]=*buf++;
310 //if (Media_D_WriteOneSect(fdoExt, SectBuf))
311 if (Media_D_WriteOneSect(fdoExt, bn, buf))
313 ErrCode = ERR_WriteFault;
314 return(ErrCode);
317 Media.Sector += bn - 1;
319 if (!Check_D_LastSect())
321 if (Release_D_ReadBlock(fdoExt))
323 { if (ErrCode==ERR_HwError)
325 ErrCode = ERR_WriteFault;
326 return(ErrCode);
331 count -= bn;
333 if (count<=0)
334 break;
336 buf += bn * SECTSIZE;
338 //if (--count<=0)
339 // break;
341 if (Inc_D_MediaAddr(fdoExt))
342 return(ErrCode);
345 if (!Check_D_LastSect())
346 return(NO_ERROR);
348 if (Inc_D_MediaAddr(fdoExt))
349 return(ErrCode);
351 if (Media_D_CopyBlockTail(fdoExt))
353 ErrCode = ERR_WriteFault;
354 return(ErrCode);
357 return(NO_ERROR);
360 ////----- Media_D_EraseBlock() -------------------------------------------
361 //int Media_D_EraseBlock(PFDO_DEVICE_EXTENSION fdoExt, DWORD start,WORD count)
363 // if (Check_D_MediaPower())
364 // return(ErrCode);
366 // if (Check_D_MediaFmt(fdoExt))
367 // return(ErrCode);
369 // if (Check_D_MediaWP())
370 // return(ErrCode);
372 // if (Conv_D_MediaAddr(start))
373 // return(ErrCode);
375 // while(Check_D_FirstSect()) {
376 // if (Inc_D_MediaAddr(fdoExt))
377 // return(ErrCode);
379 // if (--count<=0)
380 // return(NO_ERROR);
381 // }
383 // while(1) {
384 // if (!Check_D_LastSect())
385 // if (Media_D_EraseOneBlock())
386 // if (ErrCode==ERR_HwError)
387 // {
388 // ErrCode = ERR_WriteFault;
389 // return(ErrCode);
390 // }
392 // if (Inc_D_MediaAddr(fdoExt))
393 // return(ErrCode);
395 // if (--count<=0)
396 // return(NO_ERROR);
397 // }
400 ////----- Media_D_EraseAll() ---------------------------------------------
401 //int Media_D_EraseAll(PFDO_DEVICE_EXTENSION fdoExt)
403 // if (Check_D_MediaPower())
404 // return(ErrCode);
406 // if (Check_D_MediaFmtForEraseAll(fdoExt))
407 // return(ErrCode);
409 // if (Check_D_MediaWP())
410 // return(ErrCode);
412 // if (Media_D_EraseAllBlock())
413 // return(ErrCode);
415 // return(NO_ERROR);
418 //SmartMedia Write Function for One Sector Write Mode
419 //----- Media_D_OneSectWriteStart() ------------------------------------
420 int Media_D_OneSectWriteStart(PFDO_DEVICE_EXTENSION fdoExt,DWORD start,BYTE *buf)
422 // int i;
423 // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
424 // ADDRESS_T bb = (ADDRESS_T) &Media;
426 // //if (Check_D_MediaPower())
427 // // return(ErrCode);
428 // //if (Check_D_MediaFmt(fdoExt))
429 // // return(ErrCode);
430 // //if (Check_D_MediaWP())
431 // // return(ErrCode);
432 // if (Conv_D_MediaAddr(fdoExt, start))
433 // return(ErrCode);
435 // if (Check_D_FirstSect())
436 // if (Media_D_CopyBlockHead(fdoExt))
437 // {
438 // ErrCode = ERR_WriteFault;
439 // return(ErrCode);
440 // }
442 // if (!Check_D_FirstSect())
443 // if (Assign_D_WriteBlock())
444 // return(ErrCode);
446 // //for(i=0;i<SECTSIZE;i++)
447 // // SectBuf[i]=*buf++;
449 // //if (Media_D_WriteOneSect(fdoExt, SectBuf))
450 // if (Media_D_WriteOneSect(fdoExt, buf))
451 // {
452 // ErrCode = ERR_WriteFault;
453 // return(ErrCode);
454 // }
456 // if (!Check_D_LastSect())
457 // {
458 // if (Release_D_ReadBlock(fdoExt))
459 // if (ErrCode==ERR_HwError)
460 // {
461 // ErrCode = ERR_WriteFault;
462 // return(ErrCode);
463 // }
464 // }
466 return(NO_ERROR);
469 //----- Media_D_OneSectWriteNext() -------------------------------------
470 int Media_D_OneSectWriteNext(PFDO_DEVICE_EXTENSION fdoExt, BYTE *buf)
472 // int i;
473 // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
474 // ADDRESS_T bb = (ADDRESS_T) &Media;
476 // if (Inc_D_MediaAddr(fdoExt))
477 // return(ErrCode);
479 // if (!Check_D_FirstSect())
480 // if (Assign_D_WriteBlock())
481 // return(ErrCode);
483 // //for(i=0;i<SECTSIZE;i++)
484 // // SectBuf[i]=*buf++;
486 // //if (Media_D_WriteOneSect(fdoExt, SectBuf))
487 // if (Media_D_WriteOneSect(fdoExt, buf))
488 // {
489 // ErrCode = ERR_WriteFault;
490 // return(ErrCode);
491 // }
493 // if (!Check_D_LastSect())
494 // {
495 // if (Release_D_ReadBlock(fdoExt))
496 // if (ErrCode==ERR_HwError)
497 // {
498 // ErrCode = ERR_WriteFault;
499 // return(ErrCode);
500 // }
501 // }
503 return(NO_ERROR);
506 //----- Media_D_OneSectWriteFlush() ------------------------------------
507 int Media_D_OneSectWriteFlush(PFDO_DEVICE_EXTENSION fdoExt)
509 if (!Check_D_LastSect())
510 return(NO_ERROR);
512 if (Inc_D_MediaAddr(fdoExt))
513 return(ErrCode);
515 if (Media_D_CopyBlockTail(fdoExt))
517 ErrCode = ERR_WriteFault;
518 return(ErrCode);
521 return(NO_ERROR);
524 ////LED Tern On/Off Subroutine
525 ////----- SM_EnableLED() -----------------------------------------------
526 //void SM_EnableLED(PFDO_DEVICE_EXTENSION fdoExt, BOOLEAN enable)
528 // if (fdoExt->Drive_IsSWLED)
529 // {
530 // if (enable)
531 // Led_D_TernOn();
532 // else
533 // Led_D_TernOff();
534 // }
537 ////----- Led_D_TernOn() -------------------------------------------------
538 //void Led_D_TernOn(void)
540 // if (Check_D_CardStsChg())
541 // MediaChange=ERROR;
543 // Cnt_D_LedOn();
546 ////----- Led_D_TernOff() ------------------------------------------------
547 //void Led_D_TernOff(void)
549 // if (Check_D_CardStsChg())
550 // MediaChange=ERROR;
552 // Cnt_D_LedOff();
555 ////SmartMedia Logical Format Subroutine
556 ////----- Check_D_LogCHS() -----------------------------------------------
557 //int Check_D_LogCHS(WORD *c,BYTE *h,BYTE *s)
559 // switch(Ssfdc.Model) {
560 // case SSFDC1MB: *c=125; *h= 4; *s= 4; break;
561 // case SSFDC2MB: *c=125; *h= 4; *s= 8; break;
562 // case SSFDC4MB: *c=250; *h= 4; *s= 8; break;
563 // case SSFDC8MB: *c=250; *h= 4; *s=16; break;
564 // case SSFDC16MB: *c=500; *h= 4; *s=16; break;
565 // case SSFDC32MB: *c=500; *h= 8; *s=16; break;
566 // case SSFDC64MB: *c=500; *h= 8; *s=32; break;
567 // case SSFDC128MB: *c=500; *h=16; *s=32; break;
568 // default: *c= 0; *h= 0; *s= 0; ErrCode = ERR_NoSmartMedia; return(ERROR);
569 // }
571 // return(SMSUCCESS);
574 ////Power Control & Media Exist Check Subroutine
575 ////----- Initialize_D_Media() -------------------------------------------
576 //void Initialize_D_Media(void)
578 // ErrCode = NO_ERROR;
579 // MediaChange = ERROR;
580 // SectCopyMode = COMPLETED;
581 // Cnt_D_Reset();
584 ////----- PowerOff_D_Media() ---------------------------------------------
585 //void PowerOff_D_Media(void)
587 // Cnt_D_PowerOff();
590 ////----- Check_D_MediaPower() -------------------------------------------
591 //int Check_D_MediaPower(void)
593 // //usleep(56*1024);
594 // if (Check_D_CardStsChg())
595 // MediaChange = ERROR;
596 // //usleep(56*1024);
597 // if ((!Check_D_CntPower())&&(!MediaChange)) // ¦³ power & Media ¨S³Q change, «h return success
598 // return(SMSUCCESS);
599 // //usleep(56*1024);
601 // if (Check_D_CardExist()) // Check if card is not exist, return err
602 // {
603 // ErrCode = ERR_NoSmartMedia;
604 // MediaChange = ERROR;
605 // return(ERROR);
606 // }
607 // //usleep(56*1024);
608 // if (Cnt_D_PowerOn())
609 // {
610 // ErrCode = ERR_NoSmartMedia;
611 // MediaChange = ERROR;
612 // return(ERROR);
613 // }
614 // //usleep(56*1024);
615 // Ssfdc_D_Reset(fdoExt);
616 // //usleep(56*1024);
617 // return(SMSUCCESS);
620 ////-----Check_D_MediaExist() --------------------------------------------
621 //int Check_D_MediaExist(void)
623 // if (Check_D_CardStsChg())
624 // MediaChange = ERROR;
626 // if (!Check_D_CardExist())
627 // {
628 // if (!MediaChange)
629 // return(SMSUCCESS);
631 // ErrCode = ERR_ChangedMedia;
632 // return(ERROR);
633 // }
635 // ErrCode = ERR_NoSmartMedia;
637 // return(ERROR);
640 ////----- Check_D_MediaWP() ----------------------------------------------
641 //int Check_D_MediaWP(void)
643 // if (Ssfdc.Attribute &MWP)
644 // {
645 // ErrCode = ERR_WrtProtect;
646 // return(ERROR);
647 // }
649 // return(SMSUCCESS);
652 //SmartMedia Physical Format Test Subroutine
653 //----- Check_D_MediaFmt() ---------------------------------------------
654 int Check_D_MediaFmt(struct us_data *us)
656 pr_info("Check_D_MediaFmt\n");
657 //ULONG i,j, result=FALSE, zone,block;
659 //usleep(56*1024);
660 if (!MediaChange)
661 return(SMSUCCESS);
663 MediaChange = ERROR;
664 SectCopyMode = COMPLETED;
666 //usleep(56*1024);
667 if (Set_D_PhyFmtValue(us))
669 ErrCode = ERR_UnknownMedia;
670 return(ERROR);
673 //usleep(56*1024);
674 if (Search_D_CIS(us))
676 ErrCode = ERR_IllegalFmt;
677 return(ERROR);
681 MediaChange = SMSUCCESS;
682 return(SMSUCCESS);
685 ////----- Check_D_BlockIsFull() ----------------------------------
686 //void Check_D_BlockIsFull()
688 // ULONG i, block;
690 // if (IsXDCompliance || IsSSFDCCompliance)
691 // {
692 // // If the blocks are full then return write-protect.
693 // block = Ssfdc.MaxBlocks/8;
694 // for (Media.Zone=0; Media.Zone<Ssfdc.MaxZones; Media.Zone++)
695 // {
696 // if (Log2Phy[Media.Zone]==NULL)
697 // {
698 // if (Make_D_LogTable())
699 // {
700 // ErrCode = ERR_IllegalFmt;
701 // return;
702 // }
703 // }
705 // for (i=0; i<block; i++)
706 // {
707 // if (Assign[Media.Zone][i] != 0xFF)
708 // return;
709 // }
710 // }
711 // Ssfdc.Attribute |= WP;
712 // }
716 ////----- Check_D_MediaFmtForEraseAll() ----------------------------------
717 //int Check_D_MediaFmtForEraseAll(PFDO_DEVICE_EXTENSION fdoExt)
719 // MediaChange = ERROR;
720 // SectCopyMode = COMPLETED;
722 // if (Set_D_PhyFmtValue(fdoExt))
723 // {
724 // ErrCode = ERR_UnknownMedia;
725 // return(ERROR);
726 // }
728 // if (Search_D_CIS(fdoExt))
729 // {
730 // ErrCode = ERR_IllegalFmt;
731 // return(ERROR);
732 // }
734 // return(SMSUCCESS);
737 //SmartMedia Physical Address Control Subroutine
738 //----- Conv_D_MediaAddr() ---------------------------------------------
739 int Conv_D_MediaAddr(struct us_data *us, DWORD addr)
741 DWORD temp;
742 //ULONG zz;
743 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
744 //ADDRESS_T bb = (ADDRESS_T) &Media;
746 temp = addr/Ssfdc.MaxSectors;
747 Media.Zone = (BYTE) (temp/Ssfdc.MaxLogBlocks);
749 if (Log2Phy[Media.Zone]==NULL)
751 if (Make_D_LogTable(us))
753 ErrCode = ERR_IllegalFmt;
754 return(ERROR);
758 Media.Sector = (BYTE) (addr%Ssfdc.MaxSectors);
759 Media.LogBlock = (WORD) (temp%Ssfdc.MaxLogBlocks);
761 if (Media.Zone<Ssfdc.MaxZones)
763 Clr_D_RedundantData(Redundant);
764 Set_D_LogBlockAddr(Redundant);
765 Media.PhyBlock = Log2Phy[Media.Zone][Media.LogBlock];
766 return(SMSUCCESS);
769 ErrCode = ERR_OutOfLBA;
770 return(ERROR);
773 //----- Inc_D_MediaAddr() ----------------------------------------------
774 int Inc_D_MediaAddr(struct us_data *us)
776 WORD LogBlock = Media.LogBlock;
777 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
778 //ADDRESS_T bb = (ADDRESS_T) &Media;
780 if (++Media.Sector<Ssfdc.MaxSectors)
781 return(SMSUCCESS);
783 if (Log2Phy[Media.Zone]==NULL)
785 if (Make_D_LogTable(us))
787 ErrCode = ERR_IllegalFmt;
788 return(ERROR);
792 Media.Sector=0;
793 Media.LogBlock = LogBlock;
795 if (++Media.LogBlock<Ssfdc.MaxLogBlocks)
797 Clr_D_RedundantData(Redundant);
798 Set_D_LogBlockAddr(Redundant);
799 Media.PhyBlock=Log2Phy[Media.Zone][Media.LogBlock];
800 return(SMSUCCESS);
803 Media.LogBlock=0;
805 if (++Media.Zone<Ssfdc.MaxZones)
807 if (Log2Phy[Media.Zone]==NULL)
809 if (Make_D_LogTable(us))
811 ErrCode = ERR_IllegalFmt;
812 return(ERROR);
816 Media.LogBlock = 0;
818 Clr_D_RedundantData(Redundant);
819 Set_D_LogBlockAddr(Redundant);
820 Media.PhyBlock=Log2Phy[Media.Zone][Media.LogBlock];
821 return(SMSUCCESS);
824 Media.Zone=0;
825 ErrCode = ERR_OutOfLBA;
827 return(ERROR);
830 //----- Check_D_FirstSect() --------------------------------------------
831 int Check_D_FirstSect(void)
833 SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
834 ADDRESS_T bb = (ADDRESS_T) &Media;
836 if (!Media.Sector)
837 return(SMSUCCESS);
839 return(ERROR);
842 //----- Check_D_LastSect() ---------------------------------------------
843 int Check_D_LastSect(void)
845 SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
846 ADDRESS_T bb = (ADDRESS_T) &Media;
848 if (Media.Sector<(Ssfdc.MaxSectors-1))
849 return(ERROR);
851 return(SMSUCCESS);
854 //SmartMedia Read/Write Subroutine with Retry
855 //----- Media_D_ReadOneSect() ------------------------------------------
856 int Media_D_ReadOneSect(struct us_data *us, WORD count, BYTE *buf)
858 DWORD err, retry;
860 if (!Read_D_PhyOneSect(us, count, buf))
861 return(SMSUCCESS);
862 if (ErrCode==ERR_HwError)
863 return(ERROR);
864 if (ErrCode==ERR_DataStatus)
865 return(ERROR);
867 #ifdef RDERR_REASSIGN
868 if (Ssfdc.Attribute &MWP)
870 if (ErrCode==ERR_CorReadErr)
871 return(SMSUCCESS);
872 return(ERROR);
875 err=ErrCode;
876 for(retry=0; retry<2; retry++)
878 if (Copy_D_BlockAll(us, (err==ERR_EccReadErr)?REQ_FAIL:REQ_ERASE))
880 if (ErrCode==ERR_HwError)
881 return(ERROR);
882 continue;
885 ErrCode = err;
886 if (ErrCode==ERR_CorReadErr)
887 return(SMSUCCESS);
888 return(ERROR);
891 MediaChange = ERROR;
892 #else
893 if (ErrCode==ERR_CorReadErr) return(SMSUCCESS);
894 #endif
896 return(ERROR);
899 //----- Media_D_WriteOneSect() -----------------------------------------
900 int Media_D_WriteOneSect(PFDO_DEVICE_EXTENSION fdoExt, WORD count, BYTE *buf)
902 DWORD retry;
903 SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
904 ADDRESS_T bb = (ADDRESS_T) &Media;
906 if (!Write_D_PhyOneSect(fdoExt, count, buf))
907 return(SMSUCCESS);
908 if (ErrCode==ERR_HwError)
909 return(ERROR);
911 for(retry=1; retry<2; retry++)
913 if (Reassign_D_BlockHead(fdoExt))
915 if (ErrCode==ERR_HwError)
916 return(ERROR);
917 continue;
920 if (!Write_D_PhyOneSect(fdoExt, count, buf))
921 return(SMSUCCESS);
922 if (ErrCode==ERR_HwError)
923 return(ERROR);
926 if (Release_D_WriteBlock(fdoExt))
927 return(ERROR);
929 ErrCode = ERR_WriteFault;
930 MediaChange = ERROR;
931 return(ERROR);
934 //SmartMedia Data Copy Subroutine with Retry
935 //----- Media_D_CopyBlockHead() ----------------------------------------
936 int Media_D_CopyBlockHead(PFDO_DEVICE_EXTENSION fdoExt)
938 DWORD retry;
940 for(retry=0; retry<2; retry++)
942 if (!Copy_D_BlockHead(fdoExt))
943 return(SMSUCCESS);
944 if (ErrCode==ERR_HwError)
945 return(ERROR);
948 MediaChange = ERROR;
949 return(ERROR);
952 //----- Media_D_CopyBlockTail() ----------------------------------------
953 int Media_D_CopyBlockTail(PFDO_DEVICE_EXTENSION fdoExt)
955 DWORD retry;
957 if (!Copy_D_BlockTail(fdoExt))
958 return(SMSUCCESS);
959 if (ErrCode==ERR_HwError)
960 return(ERROR);
962 for(retry=1; retry<2; retry++)
964 if (Reassign_D_BlockHead(fdoExt))
966 if (ErrCode==ERR_HwError)
967 return(ERROR);
968 continue;
971 if (!Copy_D_BlockTail(fdoExt))
972 return(SMSUCCESS);
973 if (ErrCode==ERR_HwError)
974 return(ERROR);
977 if (Release_D_WriteBlock(fdoExt))
978 return(ERROR);
980 ErrCode = ERR_WriteFault;
981 MediaChange = ERROR;
982 return(ERROR);
985 ////----- Media_D_EraseOneBlock() ----------------------------------------
986 //int Media_D_EraseOneBlock(void)
988 // WORD LogBlock = Media.LogBlock;
989 // WORD PhyBlock = Media.PhyBlock;
990 // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
991 // ADDRESS_T bb = (ADDRESS_T) &Media;
993 // if (Media.PhyBlock==NO_ASSIGN)
994 // return(SMSUCCESS);
996 // if (Log2Phy[Media.Zone]==NULL)
997 // {
998 // if (Make_D_LogTable())
999 // {
1000 // ErrCode = ERR_IllegalFmt;
1001 // return(ERROR);
1002 // }
1003 // }
1004 // Media.LogBlock = LogBlock;
1005 // Media.PhyBlock = PhyBlock;
1007 // Log2Phy[Media.Zone][Media.LogBlock]=NO_ASSIGN;
1009 // if (Erase_D_PhyOneBlock(fdoExt))
1010 // {
1011 // if (ErrCode==ERR_HwError)
1012 // return(ERROR);
1013 // if (MarkFail_D_PhyOneBlock())
1014 // return(ERROR);
1016 // ErrCode = ERR_WriteFault;
1017 // return(ERROR);
1018 // }
1020 // Clr_D_Bit(Assign[Media.Zone],Media.PhyBlock);
1021 // Media.PhyBlock=NO_ASSIGN;
1022 // return(SMSUCCESS);
1025 ////SmartMedia Erase Subroutine
1026 ////----- Media_D_EraseAllBlock() ----------------------------------------
1027 //int Media_D_EraseAllBlock(void)
1029 // WORD cis=0;
1031 // SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1032 // ADDRESS_T bb = (ADDRESS_T) &Media;
1034 // MediaChange = ERROR;
1035 // Media.Sector = 0;
1037 // for(Media.Zone=0; Media.Zone<Ssfdc.MaxZones; Media.Zone++)
1038 // for(Media.PhyBlock=0; Media.PhyBlock<Ssfdc.MaxBlocks; Media.PhyBlock++) {
1039 // if (Ssfdc_D_ReadRedtData(Redundant))
1040 // {
1041 // Ssfdc_D_Reset(fdoExt);
1042 // return(ERROR);
1043 // }
1045 // Ssfdc_D_Reset(fdoExt);
1046 // if (!Check_D_FailBlock(Redundant))
1047 // {
1048 // if (cis)
1049 // {
1050 // if (Ssfdc_D_EraseBlock(fdoExt))
1051 // {
1052 // ErrCode = ERR_HwError;
1053 // return(ERROR);
1054 // }
1056 // if (Ssfdc_D_CheckStatus())
1057 // {
1058 // if (MarkFail_D_PhyOneBlock())
1059 // return(ERROR);
1060 // }
1062 // continue;
1063 // }
1065 // if (Media.PhyBlock!=CisArea.PhyBlock)
1066 // {
1067 // ErrCode = ERR_IllegalFmt;
1068 // return(ERROR);
1069 // }
1071 // cis++;
1072 // }
1074 // }
1075 // return(SMSUCCESS);
1078 //SmartMedia Physical Sector Data Copy Subroutine
1079 //----- Copy_D_BlockAll() ----------------------------------------------
1080 int Copy_D_BlockAll(struct us_data *us, DWORD mode)
1082 BYTE sect;
1083 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1084 //ADDRESS_T bb = (ADDRESS_T) &Media;
1086 sect=Media.Sector;
1088 if (Assign_D_WriteBlock())
1089 return(ERROR);
1090 if (mode==REQ_FAIL)
1091 SectCopyMode=REQ_FAIL;
1093 for(Media.Sector=0; Media.Sector<Ssfdc.MaxSectors; Media.Sector++)
1095 if (Copy_D_PhyOneSect(us))
1097 if (ErrCode==ERR_HwError)
1098 return(ERROR);
1099 if (Release_D_WriteBlock(us))
1100 return(ERROR);
1102 ErrCode = ERR_WriteFault;
1103 Media.PhyBlock=ReadBlock;
1104 Media.Sector=sect;
1106 return(ERROR);
1110 if (Release_D_ReadBlock(us))
1111 return(ERROR);
1113 Media.PhyBlock=WriteBlock;
1114 Media.Sector=sect;
1115 return(SMSUCCESS);
1118 //----- Copy_D_BlockHead() ---------------------------------------------
1119 int Copy_D_BlockHead(PFDO_DEVICE_EXTENSION fdoExt)
1121 BYTE sect;
1122 SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1123 ADDRESS_T bb = (ADDRESS_T) &Media;
1125 sect=Media.Sector;
1126 if (Assign_D_WriteBlock())
1127 return(ERROR);
1129 for(Media.Sector=0; Media.Sector<sect; Media.Sector++)
1131 if (Copy_D_PhyOneSect(fdoExt))
1133 if (ErrCode==ERR_HwError)
1134 return(ERROR);
1135 if (Release_D_WriteBlock(fdoExt))
1136 return(ERROR);
1138 ErrCode = ERR_WriteFault;
1139 Media.PhyBlock=ReadBlock;
1140 Media.Sector=sect;
1142 return(ERROR);
1146 Media.PhyBlock=WriteBlock;
1147 Media.Sector=sect;
1148 return(SMSUCCESS);
1151 //----- Copy_D_BlockTail() ---------------------------------------------
1152 int Copy_D_BlockTail(PFDO_DEVICE_EXTENSION fdoExt)
1154 BYTE sect;
1155 SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1156 ADDRESS_T bb = (ADDRESS_T) &Media;
1158 for(sect=Media.Sector; Media.Sector<Ssfdc.MaxSectors; Media.Sector++)
1160 if (Copy_D_PhyOneSect(fdoExt))
1162 if (ErrCode==ERR_HwError)
1163 return(ERROR);
1165 Media.PhyBlock=WriteBlock;
1166 Media.Sector=sect;
1168 return(ERROR);
1172 if (Release_D_ReadBlock(fdoExt))
1173 return(ERROR);
1175 Media.PhyBlock=WriteBlock;
1176 Media.Sector=sect;
1177 return(SMSUCCESS);
1180 //----- Reassign_D_BlockHead() -----------------------------------------
1181 int Reassign_D_BlockHead(PFDO_DEVICE_EXTENSION fdoExt)
1183 DWORD mode;
1184 WORD block;
1185 BYTE sect;
1186 SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1187 ADDRESS_T bb = (ADDRESS_T) &Media;
1189 mode=SectCopyMode;
1190 block=ReadBlock;
1191 sect=Media.Sector;
1193 if (Assign_D_WriteBlock())
1194 return(ERROR);
1196 SectCopyMode=REQ_FAIL;
1198 for(Media.Sector=0; Media.Sector<sect; Media.Sector++)
1200 if (Copy_D_PhyOneSect(fdoExt))
1202 if (ErrCode==ERR_HwError)
1203 return(ERROR);
1204 if (Release_D_WriteBlock(fdoExt))
1205 return(ERROR);
1207 ErrCode = ERR_WriteFault;
1208 SectCopyMode=mode;
1209 WriteBlock=ReadBlock;
1210 ReadBlock=block;
1211 Media.Sector=sect;
1212 Media.PhyBlock=WriteBlock;
1214 return(ERROR);
1218 if (Release_D_ReadBlock(fdoExt))
1219 return(ERROR);
1221 SectCopyMode=mode;
1222 ReadBlock=block;
1223 Media.Sector=sect;
1224 Media.PhyBlock=WriteBlock;
1225 return(SMSUCCESS);
1228 //SmartMedia Physical Block Assign/Release Subroutine
1229 //----- Assign_D_WriteBlock() ------------------------------------------
1230 int Assign_D_WriteBlock(void)
1232 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1233 //ADDRESS_T bb = (ADDRESS_T) &Media;
1234 ReadBlock=Media.PhyBlock;
1236 for(WriteBlock=AssignStart[Media.Zone]; WriteBlock<Ssfdc.MaxBlocks; WriteBlock++)
1238 if (!Chk_D_Bit(Assign[Media.Zone],WriteBlock))
1240 Set_D_Bit(Assign[Media.Zone],WriteBlock);
1241 AssignStart[Media.Zone]=WriteBlock+1;
1242 Media.PhyBlock=WriteBlock;
1243 SectCopyMode=REQ_ERASE;
1244 //ErrXDCode = NO_ERROR;
1245 return(SMSUCCESS);
1249 for(WriteBlock=0; WriteBlock<AssignStart[Media.Zone]; WriteBlock++)
1251 if (!Chk_D_Bit(Assign[Media.Zone],WriteBlock))
1253 Set_D_Bit(Assign[Media.Zone],WriteBlock);
1254 AssignStart[Media.Zone]=WriteBlock+1;
1255 Media.PhyBlock=WriteBlock;
1256 SectCopyMode=REQ_ERASE;
1257 //ErrXDCode = NO_ERROR;
1258 return(SMSUCCESS);
1262 WriteBlock=NO_ASSIGN;
1263 ErrCode = ERR_WriteFault;
1264 // For xD test
1265 //Ssfdc.Attribute |= WP;
1266 //ErrXDCode = ERR_WrtProtect;
1267 return(ERROR);
1270 //----- Release_D_ReadBlock() ------------------------------------------
1271 int Release_D_ReadBlock(struct us_data *us)
1273 DWORD mode;
1274 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1275 //ADDRESS_T bb = (ADDRESS_T) &Media;
1277 mode=SectCopyMode;
1278 SectCopyMode=COMPLETED;
1280 if (mode==COMPLETED)
1281 return(SMSUCCESS);
1283 Log2Phy[Media.Zone][Media.LogBlock]=WriteBlock;
1284 Media.PhyBlock=ReadBlock;
1286 if (Media.PhyBlock==NO_ASSIGN)
1288 Media.PhyBlock=WriteBlock;
1289 return(SMSUCCESS);
1292 if (mode==REQ_ERASE)
1294 if (Erase_D_PhyOneBlock(us))
1296 if (ErrCode==ERR_HwError) return(ERROR);
1297 if (MarkFail_D_PhyOneBlock(us)) return(ERROR);
1299 else
1300 Clr_D_Bit(Assign[Media.Zone],Media.PhyBlock);
1302 else if (MarkFail_D_PhyOneBlock(us))
1303 return(ERROR);
1305 Media.PhyBlock=WriteBlock;
1306 return(SMSUCCESS);
1309 //----- Release_D_WriteBlock() -----------------------------------------
1310 int Release_D_WriteBlock(struct us_data *us)
1312 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1313 //ADDRESS_T bb = (ADDRESS_T) &Media;
1314 SectCopyMode=COMPLETED;
1315 Media.PhyBlock=WriteBlock;
1317 if (MarkFail_D_PhyOneBlock(us))
1318 return(ERROR);
1320 Media.PhyBlock=ReadBlock;
1321 return(SMSUCCESS);
1324 //SmartMedia Physical Sector Data Copy Subroutine
1325 //----- Copy_D_PhyOneSect() --------------------------------------------
1326 int Copy_D_PhyOneSect(struct us_data *us)
1328 int i;
1329 DWORD err, retry;
1330 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1331 //ADDRESS_T bb = (ADDRESS_T) &Media;
1333 /* pr_info("Copy_D_PhyOneSect --- Secotr = %x\n", Media.Sector); */
1334 if (ReadBlock!=NO_ASSIGN)
1336 Media.PhyBlock=ReadBlock;
1337 for(retry=0; retry<2; retry++)
1339 if (retry!=0)
1341 Ssfdc_D_Reset(us);
1342 if (Ssfdc_D_ReadCisSect(us,WorkBuf,WorkRedund))
1343 { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); }
1345 if (Check_D_CISdata(WorkBuf,WorkRedund))
1346 { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); }
1349 if (Ssfdc_D_ReadSect(us,WorkBuf,WorkRedund))
1350 { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); }
1351 if (Check_D_DataStatus(WorkRedund))
1352 { err=ERROR; break; }
1353 if (!Check_D_ReadError(WorkRedund))
1354 { err=SMSUCCESS; break; }
1355 if (!Check_D_Correct(WorkBuf,WorkRedund))
1356 { err=SMSUCCESS; break; }
1358 err=ERROR;
1359 SectCopyMode=REQ_FAIL;
1362 else
1364 err=SMSUCCESS;
1365 for(i=0; i<SECTSIZE; i++)
1366 WorkBuf[i]=DUMMY_DATA;
1367 Clr_D_RedundantData(WorkRedund);
1370 Set_D_LogBlockAddr(WorkRedund);
1371 if (err==ERROR)
1373 Set_D_RightECC(WorkRedund);
1374 Set_D_DataStaus(WorkRedund);
1377 Media.PhyBlock=WriteBlock;
1379 if (Ssfdc_D_WriteSectForCopy(us, WorkBuf, WorkRedund))
1380 { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); }
1381 if (Ssfdc_D_CheckStatus())
1382 { ErrCode = ERR_WriteFault; return(ERROR); }
1384 Media.PhyBlock=ReadBlock;
1385 return(SMSUCCESS);
1388 //SmartMedia Physical Sector Read/Write/Erase Subroutine
1389 //----- Read_D_PhyOneSect() --------------------------------------------
1390 int Read_D_PhyOneSect(struct us_data *us, WORD count, BYTE *buf)
1392 int i;
1393 DWORD retry;
1394 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1395 //ADDRESS_T bb = (ADDRESS_T) &Media;
1397 if (Media.PhyBlock==NO_ASSIGN)
1399 for(i=0; i<SECTSIZE; i++)
1400 *buf++=DUMMY_DATA;
1401 return(SMSUCCESS);
1404 for(retry=0; retry<2; retry++)
1406 if (retry!=0)
1408 Ssfdc_D_Reset(us);
1410 if (Ssfdc_D_ReadCisSect(us,WorkBuf,WorkRedund))
1411 { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); }
1412 if (Check_D_CISdata(WorkBuf,WorkRedund))
1413 { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); }
1416 //if (Ssfdc_D_ReadSect(fdoExt,buf,Redundant))
1417 if (Ssfdc_D_ReadBlock(us,count,buf,Redundant))
1418 { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); }
1419 if (Check_D_DataStatus(Redundant))
1420 { ErrCode = ERR_DataStatus; return(ERROR); }
1422 if (!Check_D_ReadError(Redundant))
1423 return(SMSUCCESS);
1425 if (!Check_D_Correct(buf,Redundant))
1426 { ErrCode = ERR_CorReadErr; return(ERROR); }
1429 ErrCode = ERR_EccReadErr;
1430 return(ERROR);
1433 //----- Write_D_PhyOneSect() -------------------------------------------
1434 int Write_D_PhyOneSect(PFDO_DEVICE_EXTENSION fdoExt, WORD count, BYTE *buf)
1436 SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1437 ADDRESS_T bb = (ADDRESS_T) &Media;
1439 //if (Ssfdc_D_WriteSect(fdoExt,buf,Redundant))
1440 if (Ssfdc_D_WriteBlock(fdoExt,count,buf,Redundant))
1441 { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); }
1442 if (Ssfdc_D_CheckStatus())
1443 { ErrCode = ERR_WriteFault; return(ERROR); }
1445 return(SMSUCCESS);
1448 //----- Erase_D_PhyOneBlock() ------------------------------------------
1449 int Erase_D_PhyOneBlock(struct us_data *us)
1451 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1452 //ADDRESS_T bb = (ADDRESS_T) &Media;
1454 if (Ssfdc_D_EraseBlock(us))
1455 { ErrCode = ERR_HwError; MediaChange=ERROR; return(ERROR); }
1456 if (Ssfdc_D_CheckStatus())
1457 { ErrCode = ERR_WriteFault; return(ERROR); }
1459 return(SMSUCCESS);
1462 //SmartMedia Physical Format Check Local Subroutine
1463 //----- Set_D_PhyFmtValue() --------------------------------------------
1464 int Set_D_PhyFmtValue(struct us_data *us)
1466 // PPDO_DEVICE_EXTENSION pdoExt;
1467 // BYTE idcode[4];
1468 // DWORD UserDefData_1, UserDefData_2, Data, mask;
1470 // //if (!fdoExt->ChildDeviceObject) return(ERROR);
1471 // //pdoExt = fdoExt->ChildDeviceObject->DeviceExtension;
1473 // Ssfdc_D_ReadID(idcode, READ_ID_1);
1475 //if (Set_D_SsfdcModel(idcode[1]))
1476 if (Set_D_SsfdcModel(us->SM_DeviceID))
1477 return(ERROR);
1479 // //Use Multi-function pin to differentiate SM and xD.
1480 // UserDefData_1 = ReadPCIReg(fdoExt->BusID, fdoExt->DevID, fdoExt->FuncID, PCI_REG_USER_DEF) & 0x80;
1481 // if (UserDefData_1)
1482 // {
1483 // if ( READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x80 ) fdoExt->DiskType = DISKTYPE_XD;
1484 // if ( READ_PORT_BYTE(SM_REG_INT_STATUS) & 0x40 ) fdoExt->DiskType = DISKTYPE_SM;
1486 // if ( IsXDCompliance && (fdoExt->DiskType == DISKTYPE_XD) )
1487 // {
1488 // Ssfdc_D_ReadID(idcode, READ_ID_3);
1489 // if (idcode[2] != 0xB5)
1490 // return(ERROR);
1491 // }
1492 // }
1494 // //Use GPIO to differentiate SM and xD.
1495 // UserDefData_2 = ReadPCIReg(fdoExt->BusID, fdoExt->DevID, fdoExt->FuncID, PCI_REG_USER_DEF) >> 8;
1496 // if ( UserDefData_2 )
1497 // {
1498 // Data = ReadPCIReg(fdoExt->BusID, fdoExt->DevID, 0, 0xAC);
1500 // mask = 1 << (UserDefData_2-1);
1501 // // 1 : xD , 0 : SM
1502 // if ( Data & mask)
1503 // fdoExt->DiskType = DISKTYPE_XD;
1504 // else
1505 // fdoExt->DiskType = DISKTYPE_SM;
1507 // if ( IsXDCompliance && (fdoExt->DiskType == DISKTYPE_XD) )
1508 // {
1509 // Ssfdc_D_ReadID(idcode, READ_ID_3);
1510 // if (idcode[2] != 0xB5)
1511 // return(ERROR);
1512 // }
1513 // }
1515 // if ( !(UserDefData_1 | UserDefData_2) )
1516 // {
1517 // // Use UserDefine Register to differentiate SM and xD.
1518 // Ssfdc_D_ReadID(idcode, READ_ID_3);
1520 // if (idcode[2] == 0xB5)
1521 // fdoExt->DiskType = DISKTYPE_XD;
1522 // else
1523 // {
1524 // if (!IsXDCompliance)
1525 // fdoExt->DiskType = DISKTYPE_SM;
1526 // else
1527 // return(ERROR);
1528 // }
1530 // if (fdoExt->UserDef_DiskType == 0x04) fdoExt->DiskType = DISKTYPE_XD;
1531 // if (fdoExt->UserDef_DiskType == 0x08) fdoExt->DiskType = DISKTYPE_SM;
1532 // }
1534 // if (!fdoExt->UserDef_DisableWP)
1535 // {
1536 // if (fdoExt->DiskType == DISKTYPE_SM)
1537 // {
1538 // if (Check_D_SsfdcWP())
1539 // Ssfdc.Attribute|=WP;
1540 // }
1541 // }
1543 return(SMSUCCESS);
1546 //----- Search_D_CIS() -------------------------------------------------
1547 int Search_D_CIS(struct us_data *us)
1549 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1550 //ADDRESS_T bb = (ADDRESS_T) &Media;
1552 Media.Zone=0; Media.Sector=0;
1554 for (Media.PhyBlock=0; Media.PhyBlock<(Ssfdc.MaxBlocks-Ssfdc.MaxLogBlocks-1); Media.PhyBlock++)
1556 if (Ssfdc_D_ReadRedtData(us, Redundant))
1558 Ssfdc_D_Reset(us);
1559 return(ERROR);
1562 if (!Check_D_FailBlock(Redundant))
1563 break;
1566 if (Media.PhyBlock==(Ssfdc.MaxBlocks-Ssfdc.MaxLogBlocks-1))
1568 Ssfdc_D_Reset(us);
1569 return(ERROR);
1572 while (Media.Sector<CIS_SEARCH_SECT)
1574 if (Media.Sector)
1576 if (Ssfdc_D_ReadRedtData(us, Redundant))
1578 Ssfdc_D_Reset(us);
1579 return(ERROR);
1582 if (!Check_D_DataStatus(Redundant))
1584 if (Ssfdc_D_ReadSect(us,WorkBuf,Redundant))
1586 Ssfdc_D_Reset(us);
1587 return(ERROR);
1590 if (Check_D_CISdata(WorkBuf,Redundant))
1592 Ssfdc_D_Reset(us);
1593 return(ERROR);
1596 CisArea.PhyBlock=Media.PhyBlock;
1597 CisArea.Sector=Media.Sector;
1598 Ssfdc_D_Reset(us);
1599 return(SMSUCCESS);
1602 Media.Sector++;
1605 Ssfdc_D_Reset(us);
1606 return(ERROR);
1609 //----- Make_D_LogTable() ----------------------------------------------
1610 int Make_D_LogTable(struct us_data *us)
1612 WORD phyblock,logblock;
1613 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1614 //ADDRESS_T bb = (ADDRESS_T) &Media;
1616 if (Log2Phy[Media.Zone]==NULL)
1618 Log2Phy[Media.Zone] = kmalloc(MAX_LOGBLOCK*sizeof(WORD), GFP_KERNEL);
1619 /* pr_info("ExAllocatePool Zone = %x, Addr = %x\n",
1620 Media.Zone, Log2Phy[Media.Zone]); */
1621 if (Log2Phy[Media.Zone]==NULL)
1622 return(ERROR);
1625 Media.Sector=0;
1627 //for(Media.Zone=0; Media.Zone<MAX_ZONENUM; Media.Zone++)
1628 //for(Media.Zone=0; Media.Zone<Ssfdc.MaxZones; Media.Zone++)
1630 /* pr_info("Make_D_LogTable --- MediaZone = 0x%x\n",
1631 Media.Zone); */
1632 for(Media.LogBlock=0; Media.LogBlock<Ssfdc.MaxLogBlocks; Media.LogBlock++)
1633 Log2Phy[Media.Zone][Media.LogBlock]=NO_ASSIGN;
1635 for(Media.PhyBlock=0; Media.PhyBlock<(MAX_BLOCKNUM/8); Media.PhyBlock++)
1636 Assign[Media.Zone][Media.PhyBlock]=0x00;
1638 for(Media.PhyBlock=0; Media.PhyBlock<Ssfdc.MaxBlocks; Media.PhyBlock++)
1640 if ((!Media.Zone) && (Media.PhyBlock<=CisArea.PhyBlock))
1642 Set_D_Bit(Assign[Media.Zone],Media.PhyBlock);
1643 continue;
1646 if (Ssfdc_D_ReadRedtData(us, Redundant))
1647 { Ssfdc_D_Reset(us); return(ERROR); }
1649 if (!Check_D_DataBlank(Redundant))
1650 continue;
1652 Set_D_Bit(Assign[Media.Zone],Media.PhyBlock);
1654 if (Check_D_FailBlock(Redundant))
1655 continue;
1657 //if (Check_D_DataStatus(Redundant))
1658 // continue;
1660 if (Load_D_LogBlockAddr(Redundant))
1661 continue;
1663 if (Media.LogBlock>=Ssfdc.MaxLogBlocks)
1664 continue;
1666 if (Log2Phy[Media.Zone][Media.LogBlock]==NO_ASSIGN)
1668 Log2Phy[Media.Zone][Media.LogBlock]=Media.PhyBlock;
1669 continue;
1672 phyblock = Media.PhyBlock;
1673 logblock = Media.LogBlock;
1674 Media.Sector = (BYTE)(Ssfdc.MaxSectors-1);
1676 if (Ssfdc_D_ReadRedtData(us, Redundant))
1677 { Ssfdc_D_Reset(us); return(ERROR); }
1679 if (!Load_D_LogBlockAddr(Redundant))
1681 if (Media.LogBlock==logblock)
1683 Media.PhyBlock=Log2Phy[Media.Zone][logblock];
1685 if (Ssfdc_D_ReadRedtData(us, Redundant))
1686 { Ssfdc_D_Reset(us); return(ERROR); }
1688 Media.PhyBlock=phyblock;
1690 if (!Load_D_LogBlockAddr(Redundant))
1692 if (Media.LogBlock!=logblock)
1694 Media.PhyBlock=Log2Phy[Media.Zone][logblock];
1695 Log2Phy[Media.Zone][logblock]=phyblock;
1698 else
1700 Media.PhyBlock=Log2Phy[Media.Zone][logblock];
1701 Log2Phy[Media.Zone][logblock]=phyblock;
1706 Media.Sector=0;
1708 // here Not yet
1709 //#ifdef L2P_ERR_ERASE
1710 // if (!(Ssfdc.Attribute &MWP))
1711 // {
1712 // Ssfdc_D_Reset(fdoExt);
1713 // if (Ssfdc_D_EraseBlock(fdoExt))
1714 // return(ERROR);
1716 // if (Ssfdc_D_CheckStatus())
1717 // {
1718 // if (MarkFail_D_PhyOneBlock())
1719 // return(ERROR);
1720 // }
1721 // else
1722 // Clr_D_Bit(Assign[Media.Zone],Media.PhyBlock);
1723 // }
1724 //#else
1725 // Ssfdc.Attribute|=MWP;
1726 //#endif
1727 Media.PhyBlock=phyblock;
1729 } // End for (Media.PhyBlock<Ssfdc.MaxBlocks)
1731 AssignStart[Media.Zone]=0;
1733 } // End for (Media.Zone<MAX_ZONENUM)
1735 Ssfdc_D_Reset(us);
1736 return(SMSUCCESS);
1739 //----- MarkFail_D_PhyOneBlock() ---------------------------------------
1740 int MarkFail_D_PhyOneBlock(struct us_data *us)
1742 BYTE sect;
1743 //SSFDCTYPE_T aa = (SSFDCTYPE_T ) &Ssfdc;
1744 //ADDRESS_T bb = (ADDRESS_T) &Media;
1746 sect=Media.Sector;
1747 Set_D_FailBlock(WorkRedund);
1748 //Ssfdc_D_WriteRedtMode();
1750 for(Media.Sector=0; Media.Sector<Ssfdc.MaxSectors; Media.Sector++)
1752 if (Ssfdc_D_WriteRedtData(us, WorkRedund))
1754 Ssfdc_D_Reset(us);
1755 Media.Sector = sect;
1756 ErrCode = ERR_HwError;
1757 MediaChange = ERROR;
1758 return(ERROR);
1759 } // NO Status Check
1762 Ssfdc_D_Reset(us);
1763 Media.Sector=sect;
1764 return(SMSUCCESS);
1768 ////----- SM_Init() ----------------------------------------------------
1769 //void SM_Init(void)
1771 // _Hw_D_ClrIntCardChg();
1772 // _Hw_D_SetIntMask();
1773 // // For DMA Interrupt
1774 // _Hw_D_ClrDMAIntCardChg();
1775 // _Hw_D_SetDMAIntMask();
1778 ////----- Media_D_EraseAllRedtData() -----------------------------------
1779 //int Media_D_EraseAllRedtData(DWORD Index, BOOLEAN CheckBlock)
1781 // BYTE i;
1783 // if (Check_D_MediaPower())
1784 // return(ErrCode);
1786 // if (Check_D_MediaWP())
1787 // return(ErrCode);
1789 // for (i=0; i<REDTSIZE; i++)
1790 // WorkRedund[i] = 0xFF;
1792 // Media.Zone = (BYTE)Index;
1793 // for (Media.PhyBlock=0; Media.PhyBlock<Ssfdc.MaxBlocks; Media.PhyBlock++)
1794 // {
1795 // if ((!Media.Zone) && (Media.PhyBlock<=CisArea.PhyBlock))
1796 // continue;
1798 // if (Ssfdc_D_EraseBlock(fdoExt))
1799 // {
1800 // ErrCode = ERR_HwError;
1801 // return(ERROR);
1802 // }
1804 // for(Media.Sector=0; Media.Sector<Ssfdc.MaxSectors; Media.Sector++)
1805 // {
1806 // Ssfdc_D_WriteRedtMode();
1808 // if (Ssfdc_D_WriteRedtData(WorkRedund))
1809 // {
1810 // Ssfdc_D_Reset(fdoExt);
1811 // ErrCode = ERR_HwError;
1812 // MediaChange = ERROR;
1813 // return(ERROR);
1814 // } // NO Status Check
1815 // }
1817 // Ssfdc_D_Reset(fdoExt);
1818 // }
1820 // Ssfdc_D_Reset(fdoExt);
1822 // return(SMSUCCESS);
1825 ////----- Media_D_GetMediaInfo() ---------------------------------------
1826 //DWORD Media_D_GetMediaInfo(PFDO_DEVICE_EXTENSION fdoExt, PIOCTL_MEDIA_INFO_IN pParamIn, PIOCTL_MEDIA_INFO_OUT pParamOut)
1828 // pParamOut->ErrCode = STATUS_CMD_FAIL;
1830 // Init_D_SmartMedia();
1832 // if (Check_D_MediaPower())
1833 // return (ErrCode==ERR_NoSmartMedia) ? STATUS_CMD_NO_MEDIA : STATUS_CMD_FAIL;
1835 // if (Set_D_PhyFmtValue(fdoExt))
1836 // return STATUS_CMD_FAIL;
1838 // //usleep(56*1024);
1839 // if (Search_D_CIS(fdoExt))
1840 // return STATUS_CMD_FAIL;
1842 // if (Check_D_MediaWP())
1843 // return STATUS_CMD_MEDIA_WP;
1845 // pParamOut->PageSize = Ssfdc.MaxSectors;
1846 // pParamOut->BlockSize = Ssfdc.MaxBlocks;
1847 // pParamOut->ZoneSize = Ssfdc.MaxZones;
1849 // return STATUS_CMD_SUCCESS;
1850 //}*/