Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#include <linux/slab.h>
2#include "usb.h"
3#include "scsiglue.h"
4#include "smcommon.h"
5#include "smil.h"
6
7static int Conv_D_MediaAddr(struct us_data *, DWORD);
8static int Inc_D_MediaAddr(struct us_data *);
9static int Media_D_ReadOneSect(struct us_data *, WORD, BYTE *);
10
11static int Copy_D_BlockAll(struct us_data *, DWORD);
12
13static int Assign_D_WriteBlock(void);
14static int Release_D_ReadBlock(struct us_data *);
15static int Release_D_WriteBlock(struct us_data *);
16static int Release_D_CopySector(struct us_data *);
17
18static int Copy_D_PhyOneSect(struct us_data *);
19static int Read_D_PhyOneSect(struct us_data *, WORD, BYTE *);
20static int Erase_D_PhyOneBlock(struct us_data *);
21
22static int Set_D_PhyFmtValue(struct us_data *);
23static int Search_D_CIS(struct us_data *);
24static int Make_D_LogTable(struct us_data *);
25
26static int MarkFail_D_PhyOneBlock(struct us_data *);
27
28static DWORD ErrCode;
29static BYTE WorkBuf[SECTSIZE];
30static BYTE Redundant[REDTSIZE];
31static BYTE WorkRedund[REDTSIZE];
32/* 128 x 1000, Log2Phy[MAX_ZONENUM][MAX_LOGBLOCK]; */
33static WORD *Log2Phy[MAX_ZONENUM];
34static BYTE Assign[MAX_ZONENUM][MAX_BLOCKNUM / 8];
35static WORD AssignStart[MAX_ZONENUM];
36WORD ReadBlock;
37WORD WriteBlock;
38DWORD MediaChange;
39static DWORD SectCopyMode;
40
41/* BIT Control Macro */
42static BYTE BitData[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
43#define Set_D_Bit(a, b) (a[(BYTE)((b) / 8)] |= BitData[(b) % 8])
44#define Clr_D_Bit(a, b) (a[(BYTE)((b) / 8)] &= ~BitData[(b) % 8])
45#define Chk_D_Bit(a, b) (a[(BYTE)((b) / 8)] & BitData[(b) % 8])
46
47/* ----- SM_FreeMem() ------------------------------------------------- */
48int SM_FreeMem(void)
49{
50 int i;
51
52 pr_info("SM_FreeMem start\n");
53 for (i = 0; i < MAX_ZONENUM; i++) {
54 if (Log2Phy[i] != NULL) {
55 pr_info("Free Zone = %x, Addr = %p\n", i, Log2Phy[i]);
56 kfree(Log2Phy[i]);
57 Log2Phy[i] = NULL;
58 }
59 }
60 return NO_ERROR;
61}
62
63/* SmartMedia Read/Write/Erase Function */
64/* ----- Media_D_ReadSector() ------------------------------------------- */
65int Media_D_ReadSector(struct us_data *us, DWORD start, WORD count, BYTE *buf)
66{
67 WORD len, bn;
68
69 if (Conv_D_MediaAddr(us, start))
70 return ErrCode;
71
72 while (1) {
73 len = Ssfdc.MaxSectors - Media.Sector;
74 if (count > len)
75 bn = len;
76 else
77 bn = count;
78
79 if (Media_D_ReadOneSect(us, bn, buf)) {
80 ErrCode = ERR_EccReadErr;
81 return ErrCode;
82 }
83
84 Media.Sector += bn;
85 count -= bn;
86
87 if (count <= 0)
88 break;
89
90 buf += bn * SECTSIZE;
91
92 if (Inc_D_MediaAddr(us))
93 return ErrCode;
94 }
95
96 return NO_ERROR;
97}
98/* here */
99/* ----- Media_D_CopySector() ------------------------------------------ */
100int Media_D_CopySector(struct us_data *us, DWORD start, WORD count, BYTE *buf)
101{
102 WORD len, bn;
103
104 /* pr_info("Media_D_CopySector !!!\n"); */
105 if (Conv_D_MediaAddr(us, start))
106 return ErrCode;
107
108 while (1) {
109 if (Assign_D_WriteBlock())
110 return ERROR;
111
112 len = Ssfdc.MaxSectors - Media.Sector;
113 if (count > len)
114 bn = len;
115 else
116 bn = count;
117
118 if (Ssfdc_D_CopyBlock(us, bn, buf, Redundant)) {
119 ErrCode = ERR_WriteFault;
120 return ErrCode;
121 }
122
123 Media.Sector = 0x1F;
124 if (Release_D_CopySector(us)) {
125 if (ErrCode == ERR_HwError) {
126 ErrCode = ERR_WriteFault;
127 return ErrCode;
128 }
129 }
130 count -= bn;
131
132 if (count <= 0)
133 break;
134
135 buf += bn * SECTSIZE;
136
137 if (Inc_D_MediaAddr(us))
138 return ErrCode;
139
140 }
141 return NO_ERROR;
142}
143
144/* ----- Release_D_CopySector() ------------------------------------------ */
145static int Release_D_CopySector(struct us_data *us)
146{
147 Log2Phy[Media.Zone][Media.LogBlock] = WriteBlock;
148 Media.PhyBlock = ReadBlock;
149
150 if (Media.PhyBlock == NO_ASSIGN) {
151 Media.PhyBlock = WriteBlock;
152 return SMSUCCESS;
153 }
154
155 Clr_D_Bit(Assign[Media.Zone], Media.PhyBlock);
156 Media.PhyBlock = WriteBlock;
157
158 return SMSUCCESS;
159}
160
161/* SmartMedia Physical Format Test Subroutine */
162/* ----- Check_D_MediaFmt() --------------------------------------------- */
163int Check_D_MediaFmt(struct us_data *us)
164{
165 pr_info("Check_D_MediaFmt\n");
166
167 if (!MediaChange)
168 return SMSUCCESS;
169
170 MediaChange = ERROR;
171 SectCopyMode = COMPLETED;
172
173 if (Set_D_PhyFmtValue(us)) {
174 ErrCode = ERR_UnknownMedia;
175 return ERROR;
176 }
177
178 if (Search_D_CIS(us)) {
179 ErrCode = ERR_IllegalFmt;
180 return ERROR;
181 }
182
183 MediaChange = SMSUCCESS;
184 return SMSUCCESS;
185}
186
187/* SmartMedia Physical Address Control Subroutine */
188/* ----- Conv_D_MediaAddr() --------------------------------------------- */
189static int Conv_D_MediaAddr(struct us_data *us, DWORD addr)
190{
191 DWORD temp;
192
193 temp = addr / Ssfdc.MaxSectors;
194 Media.Zone = (BYTE) (temp / Ssfdc.MaxLogBlocks);
195
196 if (Log2Phy[Media.Zone] == NULL) {
197 if (Make_D_LogTable(us)) {
198 ErrCode = ERR_IllegalFmt;
199 return ERROR;
200 }
201 }
202
203 Media.Sector = (BYTE) (addr % Ssfdc.MaxSectors);
204 Media.LogBlock = (WORD) (temp % Ssfdc.MaxLogBlocks);
205
206 if (Media.Zone < Ssfdc.MaxZones) {
207 Clr_D_RedundantData(Redundant);
208 Set_D_LogBlockAddr(Redundant);
209 Media.PhyBlock = Log2Phy[Media.Zone][Media.LogBlock];
210 return SMSUCCESS;
211 }
212
213 ErrCode = ERR_OutOfLBA;
214 return ERROR;
215}
216
217/* ----- Inc_D_MediaAddr() ---------------------------------------------- */
218static int Inc_D_MediaAddr(struct us_data *us)
219{
220 WORD LogBlock = Media.LogBlock;
221
222 if (++Media.Sector < Ssfdc.MaxSectors)
223 return SMSUCCESS;
224
225 if (Log2Phy[Media.Zone] == NULL) {
226 if (Make_D_LogTable(us)) {
227 ErrCode = ERR_IllegalFmt;
228 return ERROR;
229 }
230 }
231
232 Media.Sector = 0;
233 Media.LogBlock = LogBlock;
234
235 if (++Media.LogBlock < Ssfdc.MaxLogBlocks) {
236 Clr_D_RedundantData(Redundant);
237 Set_D_LogBlockAddr(Redundant);
238 Media.PhyBlock = Log2Phy[Media.Zone][Media.LogBlock];
239 return SMSUCCESS;
240 }
241
242 Media.LogBlock = 0;
243
244 if (++Media.Zone < Ssfdc.MaxZones) {
245 if (Log2Phy[Media.Zone] == NULL) {
246 if (Make_D_LogTable(us)) {
247 ErrCode = ERR_IllegalFmt;
248 return ERROR;
249 }
250 }
251
252 Media.LogBlock = 0;
253
254 Clr_D_RedundantData(Redundant);
255 Set_D_LogBlockAddr(Redundant);
256 Media.PhyBlock = Log2Phy[Media.Zone][Media.LogBlock];
257 return SMSUCCESS;
258 }
259
260 Media.Zone = 0;
261 ErrCode = ERR_OutOfLBA;
262
263 return ERROR;
264}
265
266/* SmartMedia Read/Write Subroutine with Retry */
267/* ----- Media_D_ReadOneSect() ------------------------------------------ */
268static int Media_D_ReadOneSect(struct us_data *us, WORD count, BYTE *buf)
269{
270 DWORD err, retry;
271
272 if (!Read_D_PhyOneSect(us, count, buf))
273 return SMSUCCESS;
274 if (ErrCode == ERR_HwError)
275 return ERROR;
276 if (ErrCode == ERR_DataStatus)
277 return ERROR;
278
279#ifdef RDERR_REASSIGN
280 if (Ssfdc.Attribute & MWP) {
281 if (ErrCode == ERR_CorReadErr)
282 return SMSUCCESS;
283 return ERROR;
284 }
285
286 err = ErrCode;
287 for (retry = 0; retry < 2; retry++) {
288 if (Copy_D_BlockAll(us,
289 (err == ERR_EccReadErr) ? REQ_FAIL : REQ_ERASE)) {
290 if (ErrCode == ERR_HwError)
291 return ERROR;
292 continue;
293 }
294
295 ErrCode = err;
296 if (ErrCode == ERR_CorReadErr)
297 return SMSUCCESS;
298 return ERROR;
299 }
300
301 MediaChange = ERROR;
302#else
303 if (ErrCode == ERR_CorReadErr)
304 return SMSUCCESS;
305#endif
306
307 return ERROR;
308}
309
310/* SmartMedia Physical Sector Data Copy Subroutine */
311/* ----- Copy_D_BlockAll() ---------------------------------------------- */
312static int Copy_D_BlockAll(struct us_data *us, DWORD mode)
313{
314 BYTE sect;
315
316 sect = Media.Sector;
317
318 if (Assign_D_WriteBlock())
319 return ERROR;
320 if (mode == REQ_FAIL)
321 SectCopyMode = REQ_FAIL;
322
323 for (Media.Sector = 0; Media.Sector < Ssfdc.MaxSectors;
324 Media.Sector++) {
325 if (Copy_D_PhyOneSect(us)) {
326 if (ErrCode == ERR_HwError)
327 return ERROR;
328 if (Release_D_WriteBlock(us))
329 return ERROR;
330
331 ErrCode = ERR_WriteFault;
332 Media.PhyBlock = ReadBlock;
333 Media.Sector = sect;
334
335 return ERROR;
336 }
337 }
338
339 if (Release_D_ReadBlock(us))
340 return ERROR;
341
342 Media.PhyBlock = WriteBlock;
343 Media.Sector = sect;
344 return SMSUCCESS;
345}
346
347/* SmartMedia Physical Block Assign/Release Subroutine */
348/* ----- Assign_D_WriteBlock() ------------------------------------------ */
349static int Assign_D_WriteBlock(void)
350{
351 ReadBlock = Media.PhyBlock;
352
353 for (WriteBlock = AssignStart[Media.Zone];
354 WriteBlock < Ssfdc.MaxBlocks; WriteBlock++) {
355 if (!Chk_D_Bit(Assign[Media.Zone], WriteBlock)) {
356 Set_D_Bit(Assign[Media.Zone], WriteBlock);
357 AssignStart[Media.Zone] = WriteBlock + 1;
358 Media.PhyBlock = WriteBlock;
359 SectCopyMode = REQ_ERASE;
360 return SMSUCCESS;
361 }
362 }
363
364 for (WriteBlock = 0;
365 WriteBlock < AssignStart[Media.Zone]; WriteBlock++) {
366 if (!Chk_D_Bit(Assign[Media.Zone], WriteBlock)) {
367 Set_D_Bit(Assign[Media.Zone], WriteBlock);
368 AssignStart[Media.Zone] = WriteBlock + 1;
369 Media.PhyBlock = WriteBlock;
370 SectCopyMode = REQ_ERASE;
371 return SMSUCCESS;
372 }
373 }
374
375 WriteBlock = NO_ASSIGN;
376 ErrCode = ERR_WriteFault;
377
378 return ERROR;
379}
380
381/* ----- Release_D_ReadBlock() ------------------------------------------ */
382static int Release_D_ReadBlock(struct us_data *us)
383{
384 DWORD mode;
385
386 mode = SectCopyMode;
387 SectCopyMode = COMPLETED;
388
389 if (mode == COMPLETED)
390 return SMSUCCESS;
391
392 Log2Phy[Media.Zone][Media.LogBlock] = WriteBlock;
393 Media.PhyBlock = ReadBlock;
394
395 if (Media.PhyBlock == NO_ASSIGN) {
396 Media.PhyBlock = WriteBlock;
397 return SMSUCCESS;
398 }
399
400 if (mode == REQ_ERASE) {
401 if (Erase_D_PhyOneBlock(us)) {
402 if (ErrCode == ERR_HwError)
403 return ERROR;
404 if (MarkFail_D_PhyOneBlock(us))
405 return ERROR;
406 } else
407 Clr_D_Bit(Assign[Media.Zone], Media.PhyBlock);
408 } else if (MarkFail_D_PhyOneBlock(us))
409 return ERROR;
410
411 Media.PhyBlock = WriteBlock;
412 return SMSUCCESS;
413}
414
415/* ----- Release_D_WriteBlock() ----------------------------------------- */
416static int Release_D_WriteBlock(struct us_data *us)
417{
418 SectCopyMode = COMPLETED;
419 Media.PhyBlock = WriteBlock;
420
421 if (MarkFail_D_PhyOneBlock(us))
422 return ERROR;
423
424 Media.PhyBlock = ReadBlock;
425 return SMSUCCESS;
426}
427
428/* SmartMedia Physical Sector Data Copy Subroutine */
429/* ----- Copy_D_PhyOneSect() -------------------------------------------- */
430static int Copy_D_PhyOneSect(struct us_data *us)
431{
432 int i;
433 DWORD err, retry;
434
435 /* pr_info("Copy_D_PhyOneSect --- Sector = %x\n", Media.Sector); */
436 if (ReadBlock != NO_ASSIGN) {
437 Media.PhyBlock = ReadBlock;
438 for (retry = 0; retry < 2; retry++) {
439 if (retry != 0) {
440 Ssfdc_D_Reset(us);
441 if (Ssfdc_D_ReadCisSect(us, WorkBuf,
442 WorkRedund)) {
443 ErrCode = ERR_HwError;
444 MediaChange = ERROR;
445 return ERROR;
446 }
447
448 if (Check_D_CISdata(WorkBuf, WorkRedund)) {
449 ErrCode = ERR_HwError;
450 MediaChange = ERROR;
451 return ERROR;
452 }
453 }
454
455 if (Ssfdc_D_ReadSect(us, WorkBuf, WorkRedund)) {
456 ErrCode = ERR_HwError;
457 MediaChange = ERROR;
458 return ERROR;
459 }
460 if (Check_D_DataStatus(WorkRedund)) {
461 err = ERROR;
462 break;
463 }
464 if (!Check_D_ReadError(WorkRedund)) {
465 err = SMSUCCESS;
466 break;
467 }
468 if (!Check_D_Correct(WorkBuf, WorkRedund)) {
469 err = SMSUCCESS;
470 break;
471 }
472
473 err = ERROR;
474 SectCopyMode = REQ_FAIL;
475 }
476 } else {
477 err = SMSUCCESS;
478 for (i = 0; i < SECTSIZE; i++)
479 WorkBuf[i] = DUMMY_DATA;
480 Clr_D_RedundantData(WorkRedund);
481 }
482
483 Set_D_LogBlockAddr(WorkRedund);
484 if (err == ERROR) {
485 Set_D_RightECC(WorkRedund);
486 Set_D_DataStaus(WorkRedund);
487 }
488
489 Media.PhyBlock = WriteBlock;
490
491 if (Ssfdc_D_WriteSectForCopy(us, WorkBuf, WorkRedund)) {
492 ErrCode = ERR_HwError;
493 MediaChange = ERROR;
494 return ERROR;
495 }
496 if (Ssfdc_D_CheckStatus()) {
497 ErrCode = ERR_WriteFault;
498 return ERROR;
499 }
500
501 Media.PhyBlock = ReadBlock;
502 return SMSUCCESS;
503}
504
505/* SmartMedia Physical Sector Read/Write/Erase Subroutine */
506/* ----- Read_D_PhyOneSect() -------------------------------------------- */
507static int Read_D_PhyOneSect(struct us_data *us, WORD count, BYTE *buf)
508{
509 int i;
510 DWORD retry;
511
512 if (Media.PhyBlock == NO_ASSIGN) {
513 for (i = 0; i < SECTSIZE; i++)
514 *buf++ = DUMMY_DATA;
515 return SMSUCCESS;
516 }
517
518 for (retry = 0; retry < 2; retry++) {
519 if (retry != 0) {
520 Ssfdc_D_Reset(us);
521
522 if (Ssfdc_D_ReadCisSect(us, WorkBuf, WorkRedund)) {
523 ErrCode = ERR_HwError;
524 MediaChange = ERROR;
525 return ERROR;
526 }
527 if (Check_D_CISdata(WorkBuf, WorkRedund)) {
528 ErrCode = ERR_HwError;
529 MediaChange = ERROR;
530 return ERROR;
531 }
532 }
533
534 if (Ssfdc_D_ReadBlock(us, count, buf, Redundant)) {
535 ErrCode = ERR_HwError;
536 MediaChange = ERROR;
537 return ERROR;
538 }
539 if (Check_D_DataStatus(Redundant)) {
540 ErrCode = ERR_DataStatus;
541 return ERROR;
542 }
543
544 if (!Check_D_ReadError(Redundant))
545 return SMSUCCESS;
546
547 if (!Check_D_Correct(buf, Redundant)) {
548 ErrCode = ERR_CorReadErr;
549 return ERROR;
550 }
551 }
552
553 ErrCode = ERR_EccReadErr;
554 return ERROR;
555}
556
557/* ----- Erase_D_PhyOneBlock() ------------------------------------------ */
558static int Erase_D_PhyOneBlock(struct us_data *us)
559{
560 if (Ssfdc_D_EraseBlock(us)) {
561 ErrCode = ERR_HwError;
562 MediaChange = ERROR;
563 return ERROR;
564 }
565 if (Ssfdc_D_CheckStatus()) {
566 ErrCode = ERR_WriteFault;
567 return ERROR;
568 }
569
570 return SMSUCCESS;
571}
572
573/* SmartMedia Physical Format Check Local Subroutine */
574/* ----- Set_D_PhyFmtValue() -------------------------------------------- */
575static int Set_D_PhyFmtValue(struct us_data *us)
576{
577 if (Set_D_SsfdcModel(us->SM_DeviceID))
578 return ERROR;
579
580 return SMSUCCESS;
581}
582
583/* ----- Search_D_CIS() ------------------------------------------------- */
584static int Search_D_CIS(struct us_data *us)
585{
586 Media.Zone = 0;
587 Media.Sector = 0;
588
589 for (Media.PhyBlock = 0;
590 Media.PhyBlock < (Ssfdc.MaxBlocks - Ssfdc.MaxLogBlocks - 1);
591 Media.PhyBlock++) {
592 if (Ssfdc_D_ReadRedtData(us, Redundant)) {
593 Ssfdc_D_Reset(us);
594 return ERROR;
595 }
596
597 if (!Check_D_FailBlock(Redundant))
598 break;
599 }
600
601 if (Media.PhyBlock == (Ssfdc.MaxBlocks - Ssfdc.MaxLogBlocks - 1)) {
602 Ssfdc_D_Reset(us);
603 return ERROR;
604 }
605
606 while (Media.Sector < CIS_SEARCH_SECT) {
607 if (Media.Sector) {
608 if (Ssfdc_D_ReadRedtData(us, Redundant)) {
609 Ssfdc_D_Reset(us);
610 return ERROR;
611 }
612 }
613 if (!Check_D_DataStatus(Redundant)) {
614 if (Ssfdc_D_ReadSect(us, WorkBuf, Redundant)) {
615 Ssfdc_D_Reset(us);
616 return ERROR;
617 }
618
619 if (Check_D_CISdata(WorkBuf, Redundant)) {
620 Ssfdc_D_Reset(us);
621 return ERROR;
622 }
623
624 CisArea.PhyBlock = Media.PhyBlock;
625 CisArea.Sector = Media.Sector;
626 Ssfdc_D_Reset(us);
627 return SMSUCCESS;
628 }
629
630 Media.Sector++;
631 }
632
633 Ssfdc_D_Reset(us);
634 return ERROR;
635}
636
637/* ----- Make_D_LogTable() ---------------------------------------------- */
638static int Make_D_LogTable(struct us_data *us)
639{
640 WORD phyblock, logblock;
641
642 if (Log2Phy[Media.Zone] == NULL) {
643 Log2Phy[Media.Zone] = kmalloc(MAX_LOGBLOCK * sizeof(WORD),
644 GFP_KERNEL);
645 /* pr_info("ExAllocatePool Zone = %x, Addr = %x\n",
646 Media.Zone, Log2Phy[Media.Zone]); */
647 if (Log2Phy[Media.Zone] == NULL)
648 return ERROR;
649 }
650
651 Media.Sector = 0;
652
653 /* pr_info("Make_D_LogTable --- MediaZone = 0x%x\n",
654 Media.Zone); */
655 for (Media.LogBlock = 0; Media.LogBlock < Ssfdc.MaxLogBlocks;
656 Media.LogBlock++)
657 Log2Phy[Media.Zone][Media.LogBlock] = NO_ASSIGN;
658
659 for (Media.PhyBlock = 0; Media.PhyBlock < (MAX_BLOCKNUM / 8);
660 Media.PhyBlock++)
661 Assign[Media.Zone][Media.PhyBlock] = 0x00;
662
663 for (Media.PhyBlock = 0; Media.PhyBlock < Ssfdc.MaxBlocks;
664 Media.PhyBlock++) {
665 if ((!Media.Zone) && (Media.PhyBlock <= CisArea.PhyBlock)) {
666 Set_D_Bit(Assign[Media.Zone], Media.PhyBlock);
667 continue;
668 }
669
670 if (Ssfdc_D_ReadRedtData(us, Redundant)) {
671 Ssfdc_D_Reset(us);
672 return ERROR;
673 }
674
675 if (!Check_D_DataBlank(Redundant))
676 continue;
677
678 Set_D_Bit(Assign[Media.Zone], Media.PhyBlock);
679
680 if (Check_D_FailBlock(Redundant))
681 continue;
682
683 if (Load_D_LogBlockAddr(Redundant))
684 continue;
685
686 if (Media.LogBlock >= Ssfdc.MaxLogBlocks)
687 continue;
688
689 if (Log2Phy[Media.Zone][Media.LogBlock] == NO_ASSIGN) {
690 Log2Phy[Media.Zone][Media.LogBlock] = Media.PhyBlock;
691 continue;
692 }
693
694 phyblock = Media.PhyBlock;
695 logblock = Media.LogBlock;
696 Media.Sector = (BYTE)(Ssfdc.MaxSectors - 1);
697
698 if (Ssfdc_D_ReadRedtData(us, Redundant)) {
699 Ssfdc_D_Reset(us);
700 return ERROR;
701 }
702
703 if (!Load_D_LogBlockAddr(Redundant) &&
704 (Media.LogBlock == logblock)) {
705 Media.PhyBlock = Log2Phy[Media.Zone][logblock];
706
707 if (Ssfdc_D_ReadRedtData(us, Redundant)) {
708 Ssfdc_D_Reset(us);
709 return ERROR;
710 }
711
712 Media.PhyBlock = phyblock;
713
714 if (!Load_D_LogBlockAddr(Redundant)) {
715 if (Media.LogBlock != logblock) {
716 Media.PhyBlock =
717 Log2Phy[Media.Zone][logblock];
718 Log2Phy[Media.Zone][logblock] =
719 phyblock;
720 }
721 } else {
722 Media.PhyBlock = Log2Phy[Media.Zone][logblock];
723 Log2Phy[Media.Zone][logblock] = phyblock;
724 }
725 }
726
727 Media.Sector = 0;
728 Media.PhyBlock = phyblock;
729
730 AssignStart[Media.Zone] = 0;
731
732 } /* End for (Media.Zone<MAX_ZONENUM) */
733
734 Ssfdc_D_Reset(us);
735 return SMSUCCESS;
736}
737
738/* ----- MarkFail_D_PhyOneBlock() --------------------------------------- */
739static int MarkFail_D_PhyOneBlock(struct us_data *us)
740{
741 BYTE sect;
742
743 sect = Media.Sector;
744 Set_D_FailBlock(WorkRedund);
745
746 for (Media.Sector = 0; Media.Sector < Ssfdc.MaxSectors;
747 Media.Sector++) {
748 if (Ssfdc_D_WriteRedtData(us, WorkRedund)) {
749 Ssfdc_D_Reset(us);
750 Media.Sector = sect;
751 ErrCode = ERR_HwError;
752 MediaChange = ERROR;
753 return ERROR;
754 } /* NO Status Check */
755 }
756
757 Ssfdc_D_Reset(us);
758 Media.Sector = sect;
759 return SMSUCCESS;
760}