Commit | Line | Data |
---|---|---|
126bb03b AC |
1 | #include <linux/slab.h> |
2 | #include "usb.h" | |
3 | #include "scsiglue.h" | |
4 | #include "transport.h" | |
126bb03b | 5 | |
126bb03b AC |
6 | #include "smcommon.h" |
7 | #include "smil.h" | |
8 | ||
50d487e3 RP |
9 | void _Set_D_SsfdcRdCmd(BYTE); |
10 | void _Set_D_SsfdcRdAddr(BYTE); | |
11 | void _Set_D_SsfdcRdChip(void); | |
12 | void _Set_D_SsfdcRdStandby(void); | |
13 | void _Start_D_SsfdcRdHwECC(void); | |
14 | void _Stop_D_SsfdcRdHwECC(void); | |
15 | void _Load_D_SsfdcRdHwECC(BYTE); | |
16 | void _Set_D_SsfdcWrCmd(BYTE); | |
17 | void _Set_D_SsfdcWrAddr(BYTE); | |
18 | void _Set_D_SsfdcWrBlock(void); | |
19 | void _Set_D_SsfdcWrStandby(void); | |
20 | void _Start_D_SsfdcWrHwECC(void); | |
21 | void _Load_D_SsfdcWrHwECC(BYTE); | |
22 | int _Check_D_SsfdcBusy(WORD); | |
23 | int _Check_D_SsfdcStatus(void); | |
24 | void _Reset_D_SsfdcErr(void); | |
25 | void _Read_D_SsfdcBuf(BYTE *); | |
26 | void _Write_D_SsfdcBuf(BYTE *); | |
27 | void _Read_D_SsfdcByte(BYTE *); | |
28 | void _ReadRedt_D_SsfdcBuf(BYTE *); | |
29 | void _WriteRedt_D_SsfdcBuf(BYTE *); | |
30 | BYTE _Check_D_DevCode(BYTE); | |
31 | ||
32 | void _Set_D_ECCdata(BYTE, BYTE *); | |
33 | void _Calc_D_ECCdata(BYTE *); | |
126bb03b | 34 | |
74a5e01e | 35 | |
126bb03b AC |
36 | struct SSFDCTYPE Ssfdc; |
37 | struct ADDRESS Media; | |
38 | struct CIS_AREA CisArea; | |
39 | ||
d8aba9d5 | 40 | static BYTE EccBuf[6]; |
126bb03b | 41 | extern PBYTE SMHostAddr; |
126bb03b AC |
42 | extern DWORD ErrXDCode; |
43 | ||
44 | extern WORD ReadBlock; | |
45 | extern WORD WriteBlock; | |
46 | ||
74a5e01e | 47 | |
126bb03b | 48 | |
50d487e3 RP |
49 | #define EVEN 0 /* Even Page for 256byte/page */ |
50 | #define ODD 1 /* Odd Page for 256byte/page */ | |
126bb03b AC |
51 | |
52 | ||
50d487e3 RP |
53 | /* SmartMedia Redundant buffer data Control Subroutine |
54 | *----- Check_D_DataBlank() -------------------------------------------- | |
55 | */ | |
126bb03b AC |
56 | int Check_D_DataBlank(BYTE *redundant) |
57 | { | |
58 | char i; | |
59 | ||
50d487e3 RP |
60 | for (i = 0; i < REDTSIZE; i++) |
61 | if (*redundant++ != 0xFF) | |
62 | return ERROR; | |
126bb03b | 63 | |
50d487e3 | 64 | return SMSUCCESS; |
126bb03b AC |
65 | } |
66 | ||
50d487e3 | 67 | /* ----- Check_D_FailBlock() -------------------------------------------- */ |
126bb03b AC |
68 | int Check_D_FailBlock(BYTE *redundant) |
69 | { | |
50d487e3 | 70 | redundant += REDT_BLOCK; |
126bb03b | 71 | |
50d487e3 RP |
72 | if (*redundant == 0xFF) |
73 | return SMSUCCESS; | |
126bb03b | 74 | if (!*redundant) |
50d487e3 RP |
75 | return ERROR; |
76 | if (hweight8(*redundant) < 7) | |
77 | return ERROR; | |
126bb03b | 78 | |
50d487e3 | 79 | return SMSUCCESS; |
126bb03b AC |
80 | } |
81 | ||
50d487e3 | 82 | /* ----- Check_D_DataStatus() ------------------------------------------- */ |
126bb03b AC |
83 | int Check_D_DataStatus(BYTE *redundant) |
84 | { | |
50d487e3 | 85 | redundant += REDT_DATA; |
126bb03b | 86 | |
50d487e3 RP |
87 | if (*redundant == 0xFF) |
88 | return SMSUCCESS; | |
89 | if (!*redundant) { | |
126bb03b | 90 | ErrXDCode = ERR_DataStatus; |
50d487e3 RP |
91 | return ERROR; |
92 | } else | |
126bb03b AC |
93 | ErrXDCode = NO_ERROR; |
94 | ||
50d487e3 RP |
95 | if (hweight8(*redundant) < 5) |
96 | return ERROR; | |
126bb03b | 97 | |
50d487e3 | 98 | return SMSUCCESS; |
126bb03b AC |
99 | } |
100 | ||
50d487e3 | 101 | /* ----- Load_D_LogBlockAddr() ------------------------------------------ */ |
126bb03b AC |
102 | int Load_D_LogBlockAddr(BYTE *redundant) |
103 | { | |
50d487e3 | 104 | WORD addr1, addr2; |
126bb03b | 105 | |
b9594b81 AG |
106 | addr1 = (WORD)*(redundant + REDT_ADDR1H)*0x0100 + |
107 | (WORD)*(redundant + REDT_ADDR1L); | |
108 | addr2 = (WORD)*(redundant + REDT_ADDR2H)*0x0100 + | |
109 | (WORD)*(redundant + REDT_ADDR2L); | |
126bb03b | 110 | |
50d487e3 RP |
111 | if (addr1 == addr2) |
112 | if ((addr1 & 0xF000) == 0x1000) { | |
113 | Media.LogBlock = (addr1 & 0x0FFF) / 2; | |
114 | return SMSUCCESS; | |
115 | } | |
126bb03b | 116 | |
50d487e3 RP |
117 | if (hweight16((WORD)(addr1^addr2)) != 0x01) |
118 | return ERROR; | |
126bb03b | 119 | |
50d487e3 RP |
120 | if ((addr1 & 0xF000) == 0x1000) |
121 | if (!(hweight16(addr1) & 0x01)) { | |
122 | Media.LogBlock = (addr1 & 0x0FFF) / 2; | |
123 | return SMSUCCESS; | |
124 | } | |
126bb03b | 125 | |
50d487e3 RP |
126 | if ((addr2 & 0xF000) == 0x1000) |
127 | if (!(hweight16(addr2) & 0x01)) { | |
128 | Media.LogBlock = (addr2 & 0x0FFF) / 2; | |
129 | return SMSUCCESS; | |
130 | } | |
126bb03b | 131 | |
50d487e3 | 132 | return ERROR; |
126bb03b AC |
133 | } |
134 | ||
50d487e3 | 135 | /* ----- Clr_D_RedundantData() ------------------------------------------ */ |
126bb03b AC |
136 | void Clr_D_RedundantData(BYTE *redundant) |
137 | { | |
138 | char i; | |
139 | ||
50d487e3 RP |
140 | for (i = 0; i < REDTSIZE; i++) |
141 | *(redundant + i) = 0xFF; | |
126bb03b AC |
142 | } |
143 | ||
50d487e3 | 144 | /* ----- Set_D_LogBlockAddr() ------------------------------------------- */ |
126bb03b AC |
145 | void Set_D_LogBlockAddr(BYTE *redundant) |
146 | { | |
147 | WORD addr; | |
148 | ||
50d487e3 RP |
149 | *(redundant + REDT_BLOCK) = 0xFF; |
150 | *(redundant + REDT_DATA) = 0xFF; | |
151 | addr = Media.LogBlock*2 + 0x1000; | |
126bb03b | 152 | |
50d487e3 | 153 | if ((hweight16(addr) % 2)) |
126bb03b AC |
154 | addr++; |
155 | ||
b9594b81 AG |
156 | *(redundant + REDT_ADDR1H) = *(redundant + REDT_ADDR2H) = |
157 | (BYTE)(addr / 0x0100); | |
50d487e3 | 158 | *(redundant + REDT_ADDR1L) = *(redundant + REDT_ADDR2L) = (BYTE)addr; |
126bb03b AC |
159 | } |
160 | ||
50d487e3 | 161 | /*----- Set_D_FailBlock() ---------------------------------------------- */ |
126bb03b AC |
162 | void Set_D_FailBlock(BYTE *redundant) |
163 | { | |
50d487e3 RP |
164 | char i; |
165 | for (i = 0; i < REDTSIZE; i++) | |
166 | *redundant++ = (BYTE)((i == REDT_BLOCK) ? 0xF0 : 0xFF); | |
126bb03b AC |
167 | } |
168 | ||
50d487e3 | 169 | /* ----- Set_D_DataStaus() ---------------------------------------------- */ |
126bb03b AC |
170 | void Set_D_DataStaus(BYTE *redundant) |
171 | { | |
50d487e3 RP |
172 | redundant += REDT_DATA; |
173 | *redundant = 0x00; | |
126bb03b AC |
174 | } |
175 | ||
50d487e3 RP |
176 | /* SmartMedia Function Command Subroutine |
177 | * 6250 CMD 6 | |
178 | */ | |
179 | /* ----- Ssfdc_D_Reset() ------------------------------------------------ */ | |
126bb03b AC |
180 | void Ssfdc_D_Reset(struct us_data *us) |
181 | { | |
126bb03b | 182 | return; |
126bb03b AC |
183 | } |
184 | ||
50d487e3 RP |
185 | /* ----- Ssfdc_D_ReadCisSect() ------------------------------------------ */ |
186 | int Ssfdc_D_ReadCisSect(struct us_data *us, BYTE *buf, BYTE *redundant) | |
126bb03b | 187 | { |
50d487e3 | 188 | BYTE zone, sector; |
126bb03b | 189 | WORD block; |
126bb03b | 190 | |
50d487e3 RP |
191 | zone = Media.Zone; block = Media.PhyBlock; sector = Media.Sector; |
192 | Media.Zone = 0; | |
193 | Media.PhyBlock = CisArea.PhyBlock; | |
194 | Media.Sector = CisArea.Sector; | |
126bb03b | 195 | |
50d487e3 | 196 | if (Ssfdc_D_ReadSect(us, buf, redundant)) { |
b9594b81 AG |
197 | Media.Zone = zone; |
198 | Media.PhyBlock = block; | |
199 | Media.Sector = sector; | |
50d487e3 | 200 | return ERROR; |
126bb03b AC |
201 | } |
202 | ||
50d487e3 RP |
203 | Media.Zone = zone; Media.PhyBlock = block; Media.Sector = sector; |
204 | return SMSUCCESS; | |
126bb03b | 205 | } |
74a5e01e | 206 | |
50d487e3 RP |
207 | /* 6250 CMD 1 */ |
208 | /* ----- Ssfdc_D_ReadSect() --------------------------------------------- */ | |
209 | int Ssfdc_D_ReadSect(struct us_data *us, BYTE *buf, BYTE *redundant) | |
126bb03b AC |
210 | { |
211 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; | |
212 | int result; | |
213 | WORD addr; | |
214 | ||
215 | result = ENE_LoadBinCode(us, SM_RW_PATTERN); | |
50d487e3 | 216 | if (result != USB_STOR_XFER_GOOD) { |
126bb03b AC |
217 | printk("Load SM RW Code Fail !!\n"); |
218 | return USB_STOR_TRANSPORT_ERROR; | |
219 | } | |
220 | ||
50d487e3 RP |
221 | addr = (WORD)Media.Zone*Ssfdc.MaxBlocks + Media.PhyBlock; |
222 | addr = addr*(WORD)Ssfdc.MaxSectors + Media.Sector; | |
126bb03b | 223 | |
50d487e3 | 224 | /* Read sect data */ |
307ae1d3 | 225 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
126bb03b AC |
226 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
227 | bcb->DataTransferLength = 0x200; | |
228 | bcb->Flags = 0x80; | |
229 | bcb->CDB[0] = 0xF1; | |
230 | bcb->CDB[1] = 0x02; | |
231 | bcb->CDB[4] = (BYTE)addr; | |
50d487e3 RP |
232 | bcb->CDB[3] = (BYTE)(addr / 0x0100); |
233 | bcb->CDB[2] = Media.Zone / 2; | |
126bb03b AC |
234 | |
235 | result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0); | |
236 | if (result != USB_STOR_XFER_GOOD) | |
237 | return USB_STOR_TRANSPORT_ERROR; | |
238 | ||
50d487e3 | 239 | /* Read redundant */ |
307ae1d3 | 240 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
126bb03b AC |
241 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
242 | bcb->DataTransferLength = 0x10; | |
243 | bcb->Flags = 0x80; | |
244 | bcb->CDB[0] = 0xF1; | |
245 | bcb->CDB[1] = 0x03; | |
246 | bcb->CDB[4] = (BYTE)addr; | |
50d487e3 RP |
247 | bcb->CDB[3] = (BYTE)(addr / 0x0100); |
248 | bcb->CDB[2] = Media.Zone / 2; | |
126bb03b AC |
249 | bcb->CDB[8] = 0; |
250 | bcb->CDB[9] = 1; | |
251 | ||
252 | result = ENE_SendScsiCmd(us, FDIR_READ, redundant, 0); | |
253 | if (result != USB_STOR_XFER_GOOD) | |
254 | return USB_STOR_TRANSPORT_ERROR; | |
255 | ||
256 | return USB_STOR_TRANSPORT_GOOD; | |
257 | } | |
258 | ||
50d487e3 | 259 | /* ----- Ssfdc_D_ReadBlock() --------------------------------------------- */ |
b9594b81 AG |
260 | int Ssfdc_D_ReadBlock(struct us_data *us, WORD count, BYTE *buf, |
261 | BYTE *redundant) | |
126bb03b AC |
262 | { |
263 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; | |
264 | int result; | |
265 | WORD addr; | |
266 | ||
126bb03b | 267 | result = ENE_LoadBinCode(us, SM_RW_PATTERN); |
50d487e3 | 268 | if (result != USB_STOR_XFER_GOOD) { |
126bb03b AC |
269 | printk("Load SM RW Code Fail !!\n"); |
270 | return USB_STOR_TRANSPORT_ERROR; | |
271 | } | |
272 | ||
50d487e3 RP |
273 | addr = (WORD)Media.Zone*Ssfdc.MaxBlocks + Media.PhyBlock; |
274 | addr = addr*(WORD)Ssfdc.MaxSectors + Media.Sector; | |
126bb03b | 275 | |
50d487e3 | 276 | /* Read sect data */ |
307ae1d3 | 277 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
126bb03b AC |
278 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
279 | bcb->DataTransferLength = 0x200*count; | |
280 | bcb->Flags = 0x80; | |
281 | bcb->CDB[0] = 0xF1; | |
282 | bcb->CDB[1] = 0x02; | |
283 | bcb->CDB[4] = (BYTE)addr; | |
50d487e3 RP |
284 | bcb->CDB[3] = (BYTE)(addr / 0x0100); |
285 | bcb->CDB[2] = Media.Zone / 2; | |
126bb03b AC |
286 | |
287 | result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0); | |
288 | if (result != USB_STOR_XFER_GOOD) | |
289 | return USB_STOR_TRANSPORT_ERROR; | |
290 | ||
50d487e3 | 291 | /* Read redundant */ |
307ae1d3 | 292 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
126bb03b AC |
293 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
294 | bcb->DataTransferLength = 0x10; | |
295 | bcb->Flags = 0x80; | |
296 | bcb->CDB[0] = 0xF1; | |
297 | bcb->CDB[1] = 0x03; | |
298 | bcb->CDB[4] = (BYTE)addr; | |
50d487e3 RP |
299 | bcb->CDB[3] = (BYTE)(addr / 0x0100); |
300 | bcb->CDB[2] = Media.Zone / 2; | |
126bb03b AC |
301 | bcb->CDB[8] = 0; |
302 | bcb->CDB[9] = 1; | |
303 | ||
304 | result = ENE_SendScsiCmd(us, FDIR_READ, redundant, 0); | |
305 | if (result != USB_STOR_XFER_GOOD) | |
306 | return USB_STOR_TRANSPORT_ERROR; | |
307 | ||
308 | return USB_STOR_TRANSPORT_GOOD; | |
309 | } | |
126bb03b | 310 | |
74a5e01e | 311 | |
50d487e3 | 312 | /* ----- Ssfdc_D_CopyBlock() -------------------------------------------- */ |
b9594b81 AG |
313 | int Ssfdc_D_CopyBlock(struct us_data *us, WORD count, BYTE *buf, |
314 | BYTE *redundant) | |
126bb03b AC |
315 | { |
316 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; | |
317 | int result; | |
126bb03b AC |
318 | WORD ReadAddr, WriteAddr; |
319 | ||
126bb03b | 320 | result = ENE_LoadBinCode(us, SM_RW_PATTERN); |
50d487e3 | 321 | if (result != USB_STOR_XFER_GOOD) { |
126bb03b AC |
322 | printk("Load SM RW Code Fail !!\n"); |
323 | return USB_STOR_TRANSPORT_ERROR; | |
324 | } | |
325 | ||
50d487e3 | 326 | ReadAddr = (WORD)Media.Zone*Ssfdc.MaxBlocks + ReadBlock; |
126bb03b | 327 | ReadAddr = ReadAddr*(WORD)Ssfdc.MaxSectors; |
50d487e3 | 328 | WriteAddr = (WORD)Media.Zone*Ssfdc.MaxBlocks + WriteBlock; |
126bb03b AC |
329 | WriteAddr = WriteAddr*(WORD)Ssfdc.MaxSectors; |
330 | ||
50d487e3 | 331 | /* Write sect data */ |
307ae1d3 | 332 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
126bb03b AC |
333 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
334 | bcb->DataTransferLength = 0x200*count; | |
335 | bcb->Flags = 0x00; | |
336 | bcb->CDB[0] = 0xF0; | |
337 | bcb->CDB[1] = 0x08; | |
338 | bcb->CDB[7] = (BYTE)WriteAddr; | |
50d487e3 RP |
339 | bcb->CDB[6] = (BYTE)(WriteAddr / 0x0100); |
340 | bcb->CDB[5] = Media.Zone / 2; | |
341 | bcb->CDB[8] = *(redundant + REDT_ADDR1H); | |
342 | bcb->CDB[9] = *(redundant + REDT_ADDR1L); | |
126bb03b AC |
343 | bcb->CDB[10] = Media.Sector; |
344 | ||
50d487e3 | 345 | if (ReadBlock != NO_ASSIGN) { |
126bb03b | 346 | bcb->CDB[4] = (BYTE)ReadAddr; |
50d487e3 RP |
347 | bcb->CDB[3] = (BYTE)(ReadAddr / 0x0100); |
348 | bcb->CDB[2] = Media.Zone / 2; | |
349 | } else | |
126bb03b AC |
350 | bcb->CDB[11] = 1; |
351 | ||
352 | result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0); | |
353 | if (result != USB_STOR_XFER_GOOD) | |
354 | return USB_STOR_TRANSPORT_ERROR; | |
355 | ||
356 | return USB_STOR_TRANSPORT_GOOD; | |
357 | } | |
126bb03b | 358 | |
50d487e3 | 359 | /* ----- Ssfdc_D_WriteSectForCopy() ------------------------------------- */ |
126bb03b AC |
360 | int Ssfdc_D_WriteSectForCopy(struct us_data *us, BYTE *buf, BYTE *redundant) |
361 | { | |
362 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; | |
363 | int result; | |
50d487e3 | 364 | WORD addr; |
126bb03b | 365 | |
126bb03b | 366 | result = ENE_LoadBinCode(us, SM_RW_PATTERN); |
50d487e3 | 367 | if (result != USB_STOR_XFER_GOOD) { |
126bb03b AC |
368 | printk("Load SM RW Code Fail !!\n"); |
369 | return USB_STOR_TRANSPORT_ERROR; | |
370 | } | |
371 | ||
372 | ||
50d487e3 RP |
373 | addr = (WORD)Media.Zone*Ssfdc.MaxBlocks + Media.PhyBlock; |
374 | addr = addr*(WORD)Ssfdc.MaxSectors + Media.Sector; | |
126bb03b | 375 | |
50d487e3 | 376 | /* Write sect data */ |
307ae1d3 | 377 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
126bb03b AC |
378 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
379 | bcb->DataTransferLength = 0x200; | |
380 | bcb->Flags = 0x00; | |
381 | bcb->CDB[0] = 0xF0; | |
382 | bcb->CDB[1] = 0x04; | |
383 | bcb->CDB[7] = (BYTE)addr; | |
50d487e3 RP |
384 | bcb->CDB[6] = (BYTE)(addr / 0x0100); |
385 | bcb->CDB[5] = Media.Zone / 2; | |
386 | bcb->CDB[8] = *(redundant + REDT_ADDR1H); | |
387 | bcb->CDB[9] = *(redundant + REDT_ADDR1L); | |
126bb03b AC |
388 | |
389 | result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0); | |
390 | if (result != USB_STOR_XFER_GOOD) | |
391 | return USB_STOR_TRANSPORT_ERROR; | |
392 | ||
393 | return USB_STOR_TRANSPORT_GOOD; | |
394 | } | |
395 | ||
50d487e3 RP |
396 | /* 6250 CMD 5 */ |
397 | /* ----- Ssfdc_D_EraseBlock() ------------------------------------------- */ | |
126bb03b AC |
398 | int Ssfdc_D_EraseBlock(struct us_data *us) |
399 | { | |
400 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; | |
401 | int result; | |
402 | WORD addr; | |
403 | ||
404 | result = ENE_LoadBinCode(us, SM_RW_PATTERN); | |
50d487e3 | 405 | if (result != USB_STOR_XFER_GOOD) { |
126bb03b AC |
406 | printk("Load SM RW Code Fail !!\n"); |
407 | return USB_STOR_TRANSPORT_ERROR; | |
408 | } | |
409 | ||
50d487e3 RP |
410 | addr = (WORD)Media.Zone*Ssfdc.MaxBlocks + Media.PhyBlock; |
411 | addr = addr*(WORD)Ssfdc.MaxSectors; | |
126bb03b | 412 | |
307ae1d3 | 413 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
126bb03b AC |
414 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
415 | bcb->DataTransferLength = 0x200; | |
416 | bcb->Flags = 0x80; | |
417 | bcb->CDB[0] = 0xF2; | |
418 | bcb->CDB[1] = 0x06; | |
419 | bcb->CDB[7] = (BYTE)addr; | |
50d487e3 RP |
420 | bcb->CDB[6] = (BYTE)(addr / 0x0100); |
421 | bcb->CDB[5] = Media.Zone / 2; | |
126bb03b AC |
422 | |
423 | result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0); | |
424 | if (result != USB_STOR_XFER_GOOD) | |
425 | return USB_STOR_TRANSPORT_ERROR; | |
426 | ||
427 | return USB_STOR_TRANSPORT_GOOD; | |
428 | } | |
429 | ||
50d487e3 RP |
430 | /* 6250 CMD 2 */ |
431 | /*----- Ssfdc_D_ReadRedtData() ----------------------------------------- */ | |
126bb03b AC |
432 | int Ssfdc_D_ReadRedtData(struct us_data *us, BYTE *redundant) |
433 | { | |
434 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; | |
435 | int result; | |
436 | WORD addr; | |
50d487e3 | 437 | BYTE *buf; |
126bb03b AC |
438 | |
439 | result = ENE_LoadBinCode(us, SM_RW_PATTERN); | |
50d487e3 | 440 | if (result != USB_STOR_XFER_GOOD) { |
126bb03b AC |
441 | printk("Load SM RW Code Fail !!\n"); |
442 | return USB_STOR_TRANSPORT_ERROR; | |
443 | } | |
444 | ||
50d487e3 RP |
445 | addr = (WORD)Media.Zone*Ssfdc.MaxBlocks + Media.PhyBlock; |
446 | addr = addr*(WORD)Ssfdc.MaxSectors + Media.Sector; | |
126bb03b | 447 | |
307ae1d3 | 448 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
126bb03b AC |
449 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
450 | bcb->DataTransferLength = 0x10; | |
451 | bcb->Flags = 0x80; | |
452 | bcb->CDB[0] = 0xF1; | |
453 | bcb->CDB[1] = 0x03; | |
454 | bcb->CDB[4] = (BYTE)addr; | |
50d487e3 RP |
455 | bcb->CDB[3] = (BYTE)(addr / 0x0100); |
456 | bcb->CDB[2] = Media.Zone / 2; | |
126bb03b AC |
457 | bcb->CDB[8] = 0; |
458 | bcb->CDB[9] = 1; | |
459 | ||
460 | buf = kmalloc(0x10, GFP_KERNEL); | |
126bb03b AC |
461 | result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0); |
462 | memcpy(redundant, buf, 0x10); | |
463 | kfree(buf); | |
464 | if (result != USB_STOR_XFER_GOOD) | |
465 | return USB_STOR_TRANSPORT_ERROR; | |
466 | ||
467 | return USB_STOR_TRANSPORT_GOOD; | |
468 | } | |
469 | ||
50d487e3 RP |
470 | /* 6250 CMD 4 */ |
471 | /* ----- Ssfdc_D_WriteRedtData() ---------------------------------------- */ | |
126bb03b AC |
472 | int Ssfdc_D_WriteRedtData(struct us_data *us, BYTE *redundant) |
473 | { | |
474 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; | |
475 | int result; | |
126bb03b AC |
476 | WORD addr; |
477 | ||
478 | result = ENE_LoadBinCode(us, SM_RW_PATTERN); | |
50d487e3 | 479 | if (result != USB_STOR_XFER_GOOD) { |
126bb03b AC |
480 | printk("Load SM RW Code Fail !!\n"); |
481 | return USB_STOR_TRANSPORT_ERROR; | |
482 | } | |
483 | ||
50d487e3 RP |
484 | addr = (WORD)Media.Zone*Ssfdc.MaxBlocks + Media.PhyBlock; |
485 | addr = addr*(WORD)Ssfdc.MaxSectors + Media.Sector; | |
126bb03b | 486 | |
307ae1d3 | 487 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
126bb03b AC |
488 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
489 | bcb->DataTransferLength = 0x10; | |
490 | bcb->Flags = 0x80; | |
491 | bcb->CDB[0] = 0xF2; | |
492 | bcb->CDB[1] = 0x05; | |
493 | bcb->CDB[7] = (BYTE)addr; | |
50d487e3 RP |
494 | bcb->CDB[6] = (BYTE)(addr / 0x0100); |
495 | bcb->CDB[5] = Media.Zone / 2; | |
496 | bcb->CDB[8] = *(redundant + REDT_ADDR1H); | |
497 | bcb->CDB[9] = *(redundant + REDT_ADDR1L); | |
126bb03b AC |
498 | |
499 | result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0); | |
500 | if (result != USB_STOR_XFER_GOOD) | |
501 | return USB_STOR_TRANSPORT_ERROR; | |
502 | ||
503 | return USB_STOR_TRANSPORT_GOOD; | |
504 | } | |
505 | ||
50d487e3 | 506 | /* ----- Ssfdc_D_CheckStatus() ------------------------------------------ */ |
126bb03b AC |
507 | int Ssfdc_D_CheckStatus(void) |
508 | { | |
50d487e3 | 509 | return SMSUCCESS; |
126bb03b | 510 | } |
74a5e01e RP |
511 | |
512 | ||
513 | ||
50d487e3 RP |
514 | /* SmartMedia ID Code Check & Mode Set Subroutine |
515 | * ----- Set_D_SsfdcModel() --------------------------------------------- | |
516 | */ | |
126bb03b AC |
517 | int Set_D_SsfdcModel(BYTE dcode) |
518 | { | |
50d487e3 RP |
519 | switch (_Check_D_DevCode(dcode)) { |
520 | case SSFDC1MB: | |
521 | Ssfdc.Model = SSFDC1MB; | |
522 | Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS256; | |
523 | Ssfdc.MaxZones = 1; | |
524 | Ssfdc.MaxBlocks = 256; | |
525 | Ssfdc.MaxLogBlocks = 250; | |
526 | Ssfdc.MaxSectors = 8; | |
527 | break; | |
528 | case SSFDC2MB: | |
529 | Ssfdc.Model = SSFDC2MB; | |
530 | Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS256; | |
531 | Ssfdc.MaxZones = 1; | |
532 | Ssfdc.MaxBlocks = 512; | |
533 | Ssfdc.MaxLogBlocks = 500; | |
534 | Ssfdc.MaxSectors = 8; | |
535 | break; | |
536 | case SSFDC4MB: | |
537 | Ssfdc.Model = SSFDC4MB; | |
538 | Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS512; | |
539 | Ssfdc.MaxZones = 1; | |
540 | Ssfdc.MaxBlocks = 512; | |
541 | Ssfdc.MaxLogBlocks = 500; | |
542 | Ssfdc.MaxSectors = 16; | |
543 | break; | |
544 | case SSFDC8MB: | |
545 | Ssfdc.Model = SSFDC8MB; | |
546 | Ssfdc.Attribute = FLASH | AD3CYC | BS16 | PS512; | |
547 | Ssfdc.MaxZones = 1; | |
548 | Ssfdc.MaxBlocks = 1024; | |
549 | Ssfdc.MaxLogBlocks = 1000; | |
550 | Ssfdc.MaxSectors = 16; | |
551 | break; | |
552 | case SSFDC16MB: | |
553 | Ssfdc.Model = SSFDC16MB; | |
554 | Ssfdc.Attribute = FLASH | AD3CYC | BS32 | PS512; | |
555 | Ssfdc.MaxZones = 1; | |
556 | Ssfdc.MaxBlocks = 1024; | |
557 | Ssfdc.MaxLogBlocks = 1000; | |
558 | Ssfdc.MaxSectors = 32; | |
559 | break; | |
560 | case SSFDC32MB: | |
561 | Ssfdc.Model = SSFDC32MB; | |
562 | Ssfdc.Attribute = FLASH | AD3CYC | BS32 | PS512; | |
563 | Ssfdc.MaxZones = 2; | |
564 | Ssfdc.MaxBlocks = 1024; | |
565 | Ssfdc.MaxLogBlocks = 1000; | |
566 | Ssfdc.MaxSectors = 32; | |
567 | break; | |
568 | case SSFDC64MB: | |
569 | Ssfdc.Model = SSFDC64MB; | |
570 | Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; | |
571 | Ssfdc.MaxZones = 4; | |
572 | Ssfdc.MaxBlocks = 1024; | |
573 | Ssfdc.MaxLogBlocks = 1000; | |
574 | Ssfdc.MaxSectors = 32; | |
575 | break; | |
576 | case SSFDC128MB: | |
577 | Ssfdc.Model = SSFDC128MB; | |
578 | Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; | |
579 | Ssfdc.MaxZones = 8; | |
580 | Ssfdc.MaxBlocks = 1024; | |
581 | Ssfdc.MaxLogBlocks = 1000; | |
582 | Ssfdc.MaxSectors = 32; | |
583 | break; | |
584 | case SSFDC256MB: | |
585 | Ssfdc.Model = SSFDC256MB; | |
586 | Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; | |
587 | Ssfdc.MaxZones = 16; | |
588 | Ssfdc.MaxBlocks = 1024; | |
589 | Ssfdc.MaxLogBlocks = 1000; | |
590 | Ssfdc.MaxSectors = 32; | |
591 | break; | |
592 | case SSFDC512MB: | |
593 | Ssfdc.Model = SSFDC512MB; | |
594 | Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; | |
595 | Ssfdc.MaxZones = 32; | |
596 | Ssfdc.MaxBlocks = 1024; | |
597 | Ssfdc.MaxLogBlocks = 1000; | |
598 | Ssfdc.MaxSectors = 32; | |
599 | break; | |
600 | case SSFDC1GB: | |
601 | Ssfdc.Model = SSFDC1GB; | |
602 | Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; | |
603 | Ssfdc.MaxZones = 64; | |
604 | Ssfdc.MaxBlocks = 1024; | |
605 | Ssfdc.MaxLogBlocks = 1000; | |
606 | Ssfdc.MaxSectors = 32; | |
607 | break; | |
608 | case SSFDC2GB: | |
609 | Ssfdc.Model = SSFDC2GB; | |
610 | Ssfdc.Attribute = FLASH | AD4CYC | BS32 | PS512; | |
611 | Ssfdc.MaxZones = 128; | |
612 | Ssfdc.MaxBlocks = 1024; | |
613 | Ssfdc.MaxLogBlocks = 1000; | |
614 | Ssfdc.MaxSectors = 32; | |
615 | break; | |
616 | default: | |
617 | Ssfdc.Model = NOSSFDC; | |
618 | return ERROR; | |
619 | } | |
620 | ||
5a5097a4 | 621 | return SMSUCCESS; |
126bb03b AC |
622 | } |
623 | ||
50d487e3 | 624 | /* ----- _Check_D_DevCode() --------------------------------------------- */ |
126bb03b AC |
625 | BYTE _Check_D_DevCode(BYTE dcode) |
626 | { | |
50d487e3 RP |
627 | switch (dcode) { |
628 | case 0x6E: | |
629 | case 0xE8: | |
630 | case 0xEC: return SSFDC1MB; /* 8Mbit (1M) NAND */ | |
631 | case 0x64: | |
632 | case 0xEA: return SSFDC2MB; /* 16Mbit (2M) NAND */ | |
633 | case 0x6B: | |
634 | case 0xE3: | |
635 | case 0xE5: return SSFDC4MB; /* 32Mbit (4M) NAND */ | |
636 | case 0xE6: return SSFDC8MB; /* 64Mbit (8M) NAND */ | |
637 | case 0x73: return SSFDC16MB; /* 128Mbit (16M)NAND */ | |
638 | case 0x75: return SSFDC32MB; /* 256Mbit (32M)NAND */ | |
639 | case 0x76: return SSFDC64MB; /* 512Mbit (64M)NAND */ | |
640 | case 0x79: return SSFDC128MB; /* 1Gbit(128M)NAND */ | |
641 | case 0x71: return SSFDC256MB; | |
642 | case 0xDC: return SSFDC512MB; | |
643 | case 0xD3: return SSFDC1GB; | |
644 | case 0xD5: return SSFDC2GB; | |
645 | default: return NOSSFDC; | |
646 | } | |
126bb03b | 647 | } |
74a5e01e RP |
648 | |
649 | ||
650 | ||
651 | ||
50d487e3 RP |
652 | /* SmartMedia ECC Control Subroutine |
653 | * ----- Check_D_ReadError() ---------------------------------------------- | |
654 | */ | |
126bb03b AC |
655 | int Check_D_ReadError(BYTE *redundant) |
656 | { | |
fb03d4fc | 657 | return SMSUCCESS; |
126bb03b AC |
658 | } |
659 | ||
50d487e3 RP |
660 | /* ----- Check_D_Correct() ---------------------------------------------- */ |
661 | int Check_D_Correct(BYTE *buf, BYTE *redundant) | |
126bb03b | 662 | { |
fb03d4fc | 663 | return SMSUCCESS; |
126bb03b AC |
664 | } |
665 | ||
50d487e3 | 666 | /* ----- Check_D_CISdata() ---------------------------------------------- */ |
126bb03b AC |
667 | int Check_D_CISdata(BYTE *buf, BYTE *redundant) |
668 | { | |
1b5b4e17 JMC |
669 | BYTE cis[] = {0x01, 0x03, 0xD9, 0x01, 0xFF, 0x18, 0x02, |
670 | 0xDF, 0x01, 0x20}; | |
671 | ||
672 | int cis_len = sizeof(cis); | |
126bb03b | 673 | |
1b5b4e17 | 674 | if (!IsSSFDCCompliance && !IsXDCompliance) |
fb03d4fc | 675 | return SMSUCCESS; |
126bb03b | 676 | |
1b5b4e17 JMC |
677 | if (!memcmp(redundant + 0x0D, EccBuf, 3)) |
678 | return memcmp(buf, cis, cis_len); | |
126bb03b | 679 | |
1b5b4e17 JMC |
680 | if (!_Correct_D_SwECC(buf, redundant + 0x0D, EccBuf)) |
681 | return memcmp(buf, cis, cis_len); | |
126bb03b | 682 | |
1b5b4e17 JMC |
683 | buf += 0x100; |
684 | if (!memcmp(redundant + 0x08, EccBuf + 0x03, 3)) | |
685 | return memcmp(buf, cis, cis_len); | |
126bb03b | 686 | |
1b5b4e17 JMC |
687 | if (!_Correct_D_SwECC(buf, redundant + 0x08, EccBuf + 0x03)) |
688 | return memcmp(buf, cis, cis_len); | |
126bb03b | 689 | |
1b5b4e17 | 690 | return ERROR; |
126bb03b AC |
691 | } |
692 | ||
50d487e3 | 693 | /* ----- Set_D_RightECC() ---------------------------------------------- */ |
126bb03b AC |
694 | void Set_D_RightECC(BYTE *redundant) |
695 | { | |
5a5097a4 AG |
696 | /* Driver ECC Check */ |
697 | return; | |
126bb03b | 698 | } |
126bb03b | 699 | |
74a5e01e | 700 |