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