cafe_ecc.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381
  1. /* Error correction for CAFÉ NAND controller
  2. *
  3. * © 2006 Marvell, Inc.
  4. * Author: Tom Chiou
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc., 59
  18. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/errno.h>
  23. static unsigned short gf4096_mul(unsigned short, unsigned short);
  24. static unsigned short gf64_mul(unsigned short, unsigned short);
  25. static unsigned short gf4096_inv(unsigned short);
  26. static unsigned short err_pos(unsigned short);
  27. static void find_4bit_err_coefs(unsigned short, unsigned short, unsigned short,
  28. unsigned short, unsigned short, unsigned short,
  29. unsigned short, unsigned short, unsigned short *);
  30. static void zero_4x5_col3(unsigned short[4][5]);
  31. static void zero_4x5_col2(unsigned short[4][5]);
  32. static void zero_4x5_col1(unsigned short[4][5]);
  33. static void swap_4x5_rows(unsigned short[4][5], int, int, int);
  34. static void swap_2x3_rows(unsigned short m[2][3]);
  35. static void solve_4x5(unsigned short m[4][5], unsigned short *, int *);
  36. static void sort_coefs(int *, unsigned short *, int);
  37. static void find_4bit_err_pats(unsigned short, unsigned short, unsigned short,
  38. unsigned short, unsigned short, unsigned short,
  39. unsigned short, unsigned short, unsigned short *);
  40. static void find_3bit_err_coefs(unsigned short, unsigned short, unsigned short,
  41. unsigned short, unsigned short, unsigned short,
  42. unsigned short *);
  43. static void zero_3x4_col2(unsigned short[3][4]);
  44. static void zero_3x4_col1(unsigned short[3][4]);
  45. static void swap_3x4_rows(unsigned short[3][4], int, int, int);
  46. static void solve_3x4(unsigned short[3][4], unsigned short *, int *);
  47. static void find_3bit_err_pats(unsigned short, unsigned short, unsigned short,
  48. unsigned short, unsigned short, unsigned short,
  49. unsigned short *);
  50. static void find_2bit_err_pats(unsigned short, unsigned short, unsigned short,
  51. unsigned short, unsigned short *);
  52. static void find_2x2_soln(unsigned short, unsigned short, unsigned short,
  53. unsigned short, unsigned short, unsigned short,
  54. unsigned short *);
  55. static void solve_2x3(unsigned short[2][3], unsigned short *);
  56. static int chk_no_err_only(unsigned short *, unsigned short *);
  57. static int chk_1_err_only(unsigned short *, unsigned short *);
  58. static int chk_2_err_only(unsigned short *, unsigned short *);
  59. static int chk_3_err_only(unsigned short *, unsigned short *);
  60. static int chk_4_err_only(unsigned short *, unsigned short *);
  61. static unsigned short gf64_mul(unsigned short a, unsigned short b)
  62. {
  63. unsigned short tmp1, tmp2, tmp3, tmp4, tmp5;
  64. unsigned short c_bit0, c_bit1, c_bit2, c_bit3, c_bit4, c_bit5, c;
  65. tmp1 = ((a) ^ (a >> 5));
  66. tmp2 = ((a >> 4) ^ (a >> 5));
  67. tmp3 = ((a >> 3) ^ (a >> 4));
  68. tmp4 = ((a >> 2) ^ (a >> 3));
  69. tmp5 = ((a >> 1) ^ (a >> 2));
  70. c_bit0 = ((a & b) ^ ((a >> 5) & (b >> 1)) ^ ((a >> 4) & (b >> 2)) ^
  71. ((a >> 3) & (b >> 3)) ^ ((a >> 2) & (b >> 4)) ^ ((a >> 1) & (b >> 5))) & 0x1;
  72. c_bit1 = (((a >> 1) & b) ^ (tmp1 & (b >> 1)) ^ (tmp2 & (b >> 2)) ^
  73. (tmp3 & (b >> 3)) ^ (tmp4 & (b >> 4)) ^ (tmp5 & (b >> 5))) & 0x1;
  74. c_bit2 = (((a >> 2) & b) ^ ((a >> 1) & (b >> 1)) ^ (tmp1 & (b >> 2)) ^
  75. (tmp2 & (b >> 3)) ^ (tmp3 & (b >> 4)) ^ (tmp4 & (b >> 5))) & 0x1;
  76. c_bit3 = (((a >> 3) & b) ^ ((a >> 2) & (b >> 1)) ^ ((a >> 1) & (b >> 2)) ^
  77. (tmp1 & (b >> 3)) ^ (tmp2 & (b >> 4)) ^ (tmp3 & (b >> 5))) & 0x1;
  78. c_bit4 = (((a >> 4) & b) ^ ((a >> 3) & (b >> 1)) ^ ((a >> 2) & (b >> 2)) ^
  79. ((a >> 1) & (b >> 3)) ^ (tmp1 & (b >> 4)) ^ (tmp2 & (b >> 5))) & 0x1;
  80. c_bit5 = (((a >> 5) & b) ^ ((a >> 4) & (b >> 1)) ^ ((a >> 3) & (b >> 2)) ^
  81. ((a >> 2) & (b >> 3)) ^ ((a >> 1) & (b >> 4)) ^ (tmp1 & (b >> 5))) & 0x1;
  82. c = c_bit0 | (c_bit1 << 1) | (c_bit2 << 2) | (c_bit3 << 3) | (c_bit4 << 4) | (c_bit5 << 5);
  83. return c;
  84. }
  85. static unsigned short gf4096_mul(unsigned short a, unsigned short b)
  86. {
  87. unsigned short ah, al, bh, bl, alxah, blxbh, ablh, albl, ahbh, ahbhB, c;
  88. ah = (a >> 6) & 0x3f;
  89. al = a & 0x3f;
  90. bh = (b >> 6) & 0x3f;
  91. bl = b & 0x3f;
  92. alxah = al ^ ah;
  93. blxbh = bl ^ bh;
  94. ablh = gf64_mul(alxah, blxbh);
  95. albl = gf64_mul(al, bl);
  96. ahbh = gf64_mul(ah, bh);
  97. ahbhB = ((ahbh & 0x1) << 5) |
  98. ((ahbh & 0x20) >> 1) |
  99. ((ahbh & 0x10) >> 1) | ((ahbh & 0x8) >> 1) | ((ahbh & 0x4) >> 1) | (((ahbh >> 1) ^ ahbh) & 0x1);
  100. c = ((ablh ^ albl) << 6) | (ahbhB ^ albl);
  101. return c;
  102. }
  103. static void find_2bit_err_pats(unsigned short s0, unsigned short s1, unsigned short r0, unsigned short r1, unsigned short *pats)
  104. {
  105. find_2x2_soln(0x1, 0x1, r0, r1, s0, s1, pats);
  106. }
  107. static void find_3bit_err_coefs(unsigned short s0, unsigned short s1,
  108. unsigned short s2, unsigned short s3, unsigned short s4, unsigned short s5, unsigned short *coefs)
  109. {
  110. unsigned short m[3][4];
  111. int row_order[3];
  112. row_order[0] = 0;
  113. row_order[1] = 1;
  114. row_order[2] = 2;
  115. m[0][0] = s2;
  116. m[0][1] = s1;
  117. m[0][2] = s0;
  118. m[0][3] = s3;
  119. m[1][0] = s3;
  120. m[1][1] = s2;
  121. m[1][2] = s1;
  122. m[1][3] = s4;
  123. m[2][0] = s4;
  124. m[2][1] = s3;
  125. m[2][2] = s2;
  126. m[2][3] = s5;
  127. if (m[0][2] != 0x0) {
  128. zero_3x4_col2(m);
  129. } else if (m[1][2] != 0x0) {
  130. swap_3x4_rows(m, 0, 1, 4);
  131. zero_3x4_col2(m);
  132. } else if (m[2][2] != 0x0) {
  133. swap_3x4_rows(m, 0, 2, 4);
  134. zero_3x4_col2(m);
  135. } else {
  136. printk(KERN_ERR "Error: find_3bit_err_coefs, s0,s1,s2 all zeros!\n");
  137. }
  138. if (m[1][1] != 0x0) {
  139. zero_3x4_col1(m);
  140. } else if (m[2][1] != 0x0) {
  141. swap_3x4_rows(m, 1, 2, 4);
  142. zero_3x4_col1(m);
  143. } else {
  144. printk(KERN_ERR "Error: find_3bit_err_coefs, cannot resolve col 1!\n");
  145. }
  146. /* solve coefs */
  147. solve_3x4(m, coefs, row_order);
  148. }
  149. static void zero_3x4_col2(unsigned short m[3][4])
  150. {
  151. unsigned short minv1, minv2;
  152. minv1 = gf4096_mul(m[1][2], gf4096_inv(m[0][2]));
  153. minv2 = gf4096_mul(m[2][2], gf4096_inv(m[0][2]));
  154. m[1][0] = m[1][0] ^ gf4096_mul(m[0][0], minv1);
  155. m[1][1] = m[1][1] ^ gf4096_mul(m[0][1], minv1);
  156. m[1][3] = m[1][3] ^ gf4096_mul(m[0][3], minv1);
  157. m[2][0] = m[2][0] ^ gf4096_mul(m[0][0], minv2);
  158. m[2][1] = m[2][1] ^ gf4096_mul(m[0][1], minv2);
  159. m[2][3] = m[2][3] ^ gf4096_mul(m[0][3], minv2);
  160. }
  161. static void zero_3x4_col1(unsigned short m[3][4])
  162. {
  163. unsigned short minv;
  164. minv = gf4096_mul(m[2][1], gf4096_inv(m[1][1]));
  165. m[2][0] = m[2][0] ^ gf4096_mul(m[1][0], minv);
  166. m[2][3] = m[2][3] ^ gf4096_mul(m[1][3], minv);
  167. }
  168. static void swap_3x4_rows(unsigned short m[3][4], int i, int j, int col_width)
  169. {
  170. unsigned short tmp0;
  171. int cnt;
  172. for (cnt = 0; cnt < col_width; cnt++) {
  173. tmp0 = m[i][cnt];
  174. m[i][cnt] = m[j][cnt];
  175. m[j][cnt] = tmp0;
  176. }
  177. }
  178. static void solve_3x4(unsigned short m[3][4], unsigned short *coefs, int *row_order)
  179. {
  180. unsigned short tmp[3];
  181. tmp[0] = gf4096_mul(m[2][3], gf4096_inv(m[2][0]));
  182. tmp[1] = gf4096_mul((gf4096_mul(tmp[0], m[1][0]) ^ m[1][3]), gf4096_inv(m[1][1]));
  183. tmp[2] = gf4096_mul((gf4096_mul(tmp[0], m[0][0]) ^ gf4096_mul(tmp[1], m[0][1]) ^ m[0][3]), gf4096_inv(m[0][2]));
  184. sort_coefs(row_order, tmp, 3);
  185. coefs[0] = tmp[0];
  186. coefs[1] = tmp[1];
  187. coefs[2] = tmp[2];
  188. }
  189. static void find_3bit_err_pats(unsigned short s0, unsigned short s1,
  190. unsigned short s2, unsigned short r0,
  191. unsigned short r1, unsigned short r2,
  192. unsigned short *pats)
  193. {
  194. find_2x2_soln(r0 ^ r2, r1 ^ r2,
  195. gf4096_mul(r0, r0 ^ r2), gf4096_mul(r1, r1 ^ r2),
  196. gf4096_mul(s0, r2) ^ s1, gf4096_mul(s1, r2) ^ s2, pats);
  197. pats[2] = s0 ^ pats[0] ^ pats[1];
  198. }
  199. static void find_4bit_err_coefs(unsigned short s0, unsigned short s1,
  200. unsigned short s2, unsigned short s3,
  201. unsigned short s4, unsigned short s5,
  202. unsigned short s6, unsigned short s7,
  203. unsigned short *coefs)
  204. {
  205. unsigned short m[4][5];
  206. int row_order[4];
  207. row_order[0] = 0;
  208. row_order[1] = 1;
  209. row_order[2] = 2;
  210. row_order[3] = 3;
  211. m[0][0] = s3;
  212. m[0][1] = s2;
  213. m[0][2] = s1;
  214. m[0][3] = s0;
  215. m[0][4] = s4;
  216. m[1][0] = s4;
  217. m[1][1] = s3;
  218. m[1][2] = s2;
  219. m[1][3] = s1;
  220. m[1][4] = s5;
  221. m[2][0] = s5;
  222. m[2][1] = s4;
  223. m[2][2] = s3;
  224. m[2][3] = s2;
  225. m[2][4] = s6;
  226. m[3][0] = s6;
  227. m[3][1] = s5;
  228. m[3][2] = s4;
  229. m[3][3] = s3;
  230. m[3][4] = s7;
  231. if (m[0][3] != 0x0) {
  232. zero_4x5_col3(m);
  233. } else if (m[1][3] != 0x0) {
  234. swap_4x5_rows(m, 0, 1, 5);
  235. zero_4x5_col3(m);
  236. } else if (m[2][3] != 0x0) {
  237. swap_4x5_rows(m, 0, 2, 5);
  238. zero_4x5_col3(m);
  239. } else if (m[3][3] != 0x0) {
  240. swap_4x5_rows(m, 0, 3, 5);
  241. zero_4x5_col3(m);
  242. } else {
  243. printk(KERN_ERR "Error: find_4bit_err_coefs, s0,s1,s2,s3 all zeros!\n");
  244. }
  245. if (m[1][2] != 0x0) {
  246. zero_4x5_col2(m);
  247. } else if (m[2][2] != 0x0) {
  248. swap_4x5_rows(m, 1, 2, 5);
  249. zero_4x5_col2(m);
  250. } else if (m[3][2] != 0x0) {
  251. swap_4x5_rows(m, 1, 3, 5);
  252. zero_4x5_col2(m);
  253. } else {
  254. printk(KERN_ERR "Error: find_4bit_err_coefs, cannot resolve col 2!\n");
  255. }
  256. if (m[2][1] != 0x0) {
  257. zero_4x5_col1(m);
  258. } else if (m[3][1] != 0x0) {
  259. swap_4x5_rows(m, 2, 3, 5);
  260. zero_4x5_col1(m);
  261. } else {
  262. printk(KERN_ERR "Error: find_4bit_err_coefs, cannot resolve col 1!\n");
  263. }
  264. solve_4x5(m, coefs, row_order);
  265. }
  266. static void zero_4x5_col3(unsigned short m[4][5])
  267. {
  268. unsigned short minv1, minv2, minv3;
  269. minv1 = gf4096_mul(m[1][3], gf4096_inv(m[0][3]));
  270. minv2 = gf4096_mul(m[2][3], gf4096_inv(m[0][3]));
  271. minv3 = gf4096_mul(m[3][3], gf4096_inv(m[0][3]));
  272. m[1][0] = m[1][0] ^ gf4096_mul(m[0][0], minv1);
  273. m[1][1] = m[1][1] ^ gf4096_mul(m[0][1], minv1);
  274. m[1][2] = m[1][2] ^ gf4096_mul(m[0][2], minv1);
  275. m[1][4] = m[1][4] ^ gf4096_mul(m[0][4], minv1);
  276. m[2][0] = m[2][0] ^ gf4096_mul(m[0][0], minv2);
  277. m[2][1] = m[2][1] ^ gf4096_mul(m[0][1], minv2);
  278. m[2][2] = m[2][2] ^ gf4096_mul(m[0][2], minv2);
  279. m[2][4] = m[2][4] ^ gf4096_mul(m[0][4], minv2);
  280. m[3][0] = m[3][0] ^ gf4096_mul(m[0][0], minv3);
  281. m[3][1] = m[3][1] ^ gf4096_mul(m[0][1], minv3);
  282. m[3][2] = m[3][2] ^ gf4096_mul(m[0][2], minv3);
  283. m[3][4] = m[3][4] ^ gf4096_mul(m[0][4], minv3);
  284. }
  285. static void zero_4x5_col2(unsigned short m[4][5])
  286. {
  287. unsigned short minv2, minv3;
  288. minv2 = gf4096_mul(m[2][2], gf4096_inv(m[1][2]));
  289. minv3 = gf4096_mul(m[3][2], gf4096_inv(m[1][2]));
  290. m[2][0] = m[2][0] ^ gf4096_mul(m[1][0], minv2);
  291. m[2][1] = m[2][1] ^ gf4096_mul(m[1][1], minv2);
  292. m[2][4] = m[2][4] ^ gf4096_mul(m[1][4], minv2);
  293. m[3][0] = m[3][0] ^ gf4096_mul(m[1][0], minv3);
  294. m[3][1] = m[3][1] ^ gf4096_mul(m[1][1], minv3);
  295. m[3][4] = m[3][4] ^ gf4096_mul(m[1][4], minv3);
  296. }
  297. static void zero_4x5_col1(unsigned short m[4][5])
  298. {
  299. unsigned short minv;
  300. minv = gf4096_mul(m[3][1], gf4096_inv(m[2][1]));
  301. m[3][0] = m[3][0] ^ gf4096_mul(m[2][0], minv);
  302. m[3][4] = m[3][4] ^ gf4096_mul(m[2][4], minv);
  303. }
  304. static void swap_4x5_rows(unsigned short m[4][5], int i, int j, int col_width)
  305. {
  306. unsigned short tmp0;
  307. int cnt;
  308. for (cnt = 0; cnt < col_width; cnt++) {
  309. tmp0 = m[i][cnt];
  310. m[i][cnt] = m[j][cnt];
  311. m[j][cnt] = tmp0;
  312. }
  313. }
  314. static void solve_4x5(unsigned short m[4][5], unsigned short *coefs, int *row_order)
  315. {
  316. unsigned short tmp[4];
  317. tmp[0] = gf4096_mul(m[3][4], gf4096_inv(m[3][0]));
  318. tmp[1] = gf4096_mul((gf4096_mul(tmp[0], m[2][0]) ^ m[2][4]), gf4096_inv(m[2][1]));
  319. tmp[2] = gf4096_mul((gf4096_mul(tmp[0], m[1][0]) ^ gf4096_mul(tmp[1], m[1][1]) ^ m[1][4]), gf4096_inv(m[1][2]));
  320. tmp[3] = gf4096_mul((gf4096_mul(tmp[0], m[0][0]) ^
  321. gf4096_mul(tmp[1], m[0][1]) ^ gf4096_mul(tmp[2], m[0][2]) ^ m[0][4]), gf4096_inv(m[0][3]));
  322. sort_coefs(row_order, tmp, 4);
  323. coefs[0] = tmp[0];
  324. coefs[1] = tmp[1];
  325. coefs[2] = tmp[2];
  326. coefs[3] = tmp[3];
  327. }
  328. static void sort_coefs(int *order, unsigned short *soln, int len)
  329. {
  330. int cnt, start_cnt, least_ord, least_cnt;
  331. unsigned short tmp0;
  332. for (start_cnt = 0; start_cnt < len; start_cnt++) {
  333. for (cnt = start_cnt; cnt < len; cnt++) {
  334. if (cnt == start_cnt) {
  335. least_ord = order[cnt];
  336. least_cnt = start_cnt;
  337. } else {
  338. if (least_ord > order[cnt]) {
  339. least_ord = order[cnt];
  340. least_cnt = cnt;
  341. }
  342. }
  343. }
  344. if (least_cnt != start_cnt) {
  345. tmp0 = order[least_cnt];
  346. order[least_cnt] = order[start_cnt];
  347. order[start_cnt] = tmp0;
  348. tmp0 = soln[least_cnt];
  349. soln[least_cnt] = soln[start_cnt];
  350. soln[start_cnt] = tmp0;
  351. }
  352. }
  353. }
  354. static void find_4bit_err_pats(unsigned short s0, unsigned short s1,
  355. unsigned short s2, unsigned short s3,
  356. unsigned short z1, unsigned short z2,
  357. unsigned short z3, unsigned short z4,
  358. unsigned short *pats)
  359. {
  360. unsigned short z4_z1, z3z4_z3z3, z4_z2, s0z4_s1, z1z4_z1z1,
  361. z4_z3, z2z4_z2z2, s1z4_s2, z3z3z4_z3z3z3, z1z1z4_z1z1z1, z2z2z4_z2z2z2, s2z4_s3;
  362. unsigned short tmp0, tmp1, tmp2, tmp3;
  363. z4_z1 = z4 ^ z1;
  364. z3z4_z3z3 = gf4096_mul(z3, z4) ^ gf4096_mul(z3, z3);
  365. z4_z2 = z4 ^ z2;
  366. s0z4_s1 = gf4096_mul(s0, z4) ^ s1;
  367. z1z4_z1z1 = gf4096_mul(z1, z4) ^ gf4096_mul(z1, z1);
  368. z4_z3 = z4 ^ z3;
  369. z2z4_z2z2 = gf4096_mul(z2, z4) ^ gf4096_mul(z2, z2);
  370. s1z4_s2 = gf4096_mul(s1, z4) ^ s2;
  371. z3z3z4_z3z3z3 = gf4096_mul(gf4096_mul(z3, z3), z4) ^ gf4096_mul(gf4096_mul(z3, z3), z3);
  372. z1z1z4_z1z1z1 = gf4096_mul(gf4096_mul(z1, z1), z4) ^ gf4096_mul(gf4096_mul(z1, z1), z1);
  373. z2z2z4_z2z2z2 = gf4096_mul(gf4096_mul(z2, z2), z4) ^ gf4096_mul(gf4096_mul(z2, z2), z2);
  374. s2z4_s3 = gf4096_mul(s2, z4) ^ s3;
  375. //find err pat 0,1
  376. find_2x2_soln(gf4096_mul(z4_z1, z3z4_z3z3) ^
  377. gf4096_mul(z1z4_z1z1, z4_z3), gf4096_mul(z4_z2,
  378. z3z4_z3z3) ^
  379. gf4096_mul(z2z4_z2z2, z4_z3), gf4096_mul(z1z4_z1z1,
  380. z3z3z4_z3z3z3) ^
  381. gf4096_mul(z1z1z4_z1z1z1, z3z4_z3z3),
  382. gf4096_mul(z2z4_z2z2,
  383. z3z3z4_z3z3z3) ^ gf4096_mul(z2z2z4_z2z2z2,
  384. z3z4_z3z3),
  385. gf4096_mul(s0z4_s1, z3z4_z3z3) ^ gf4096_mul(s1z4_s2,
  386. z4_z3),
  387. gf4096_mul(s1z4_s2, z3z3z4_z3z3z3) ^ gf4096_mul(s2z4_s3, z3z4_z3z3), pats);
  388. tmp0 = pats[0];
  389. tmp1 = pats[1];
  390. tmp2 = pats[0] ^ pats[1] ^ s0;
  391. tmp3 = gf4096_mul(pats[0], z1) ^ gf4096_mul(pats[1], z2) ^ s1;
  392. //find err pat 2,3
  393. find_2x2_soln(0x1, 0x1, z3, z4, tmp2, tmp3, pats);
  394. pats[2] = pats[0];
  395. pats[3] = pats[1];
  396. pats[0] = tmp0;
  397. pats[1] = tmp1;
  398. }
  399. static void find_2x2_soln(unsigned short c00, unsigned short c01,
  400. unsigned short c10, unsigned short c11,
  401. unsigned short lval0, unsigned short lval1,
  402. unsigned short *soln)
  403. {
  404. unsigned short m[2][3];
  405. m[0][0] = c00;
  406. m[0][1] = c01;
  407. m[0][2] = lval0;
  408. m[1][0] = c10;
  409. m[1][1] = c11;
  410. m[1][2] = lval1;
  411. if (m[0][1] != 0x0) {
  412. /* */
  413. } else if (m[1][1] != 0x0) {
  414. swap_2x3_rows(m);
  415. } else {
  416. printk(KERN_ERR "Warning: find_2bit_err_coefs, s0,s1 all zeros!\n");
  417. }
  418. solve_2x3(m, soln);
  419. }
  420. static void swap_2x3_rows(unsigned short m[2][3])
  421. {
  422. unsigned short tmp0;
  423. int cnt;
  424. for (cnt = 0; cnt < 3; cnt++) {
  425. tmp0 = m[0][cnt];
  426. m[0][cnt] = m[1][cnt];
  427. m[1][cnt] = tmp0;
  428. }
  429. }
  430. static void solve_2x3(unsigned short m[2][3], unsigned short *coefs)
  431. {
  432. unsigned short minv;
  433. minv = gf4096_mul(m[1][1], gf4096_inv(m[0][1]));
  434. m[1][0] = m[1][0] ^ gf4096_mul(m[0][0], minv);
  435. m[1][2] = m[1][2] ^ gf4096_mul(m[0][2], minv);
  436. coefs[0] = gf4096_mul(m[1][2], gf4096_inv(m[1][0]));
  437. coefs[1] = gf4096_mul((gf4096_mul(coefs[0], m[0][0]) ^ m[0][2]), gf4096_inv(m[0][1]));
  438. }
  439. static unsigned char gf64_inv[64] = {
  440. 0, 1, 33, 62, 49, 43, 31, 44, 57, 37, 52, 28, 46, 40, 22, 25,
  441. 61, 54, 51, 39, 26, 35, 14, 24, 23, 15, 20, 34, 11, 53, 45, 6,
  442. 63, 2, 27, 21, 56, 9, 50, 19, 13, 47, 48, 5, 7, 30, 12, 41,
  443. 42, 4, 38, 18, 10, 29, 17, 60, 36, 8, 59, 58, 55, 16, 3, 32
  444. };
  445. static unsigned short gf4096_inv(unsigned short din)
  446. {
  447. unsigned short alahxal, ah2B, deno, inv, bl, bh;
  448. unsigned short ah, al, ahxal;
  449. unsigned short dout;
  450. ah = (din >> 6) & 0x3f;
  451. al = din & 0x3f;
  452. ahxal = ah ^ al;
  453. ah2B = (((ah ^ (ah >> 3)) & 0x1) << 5) |
  454. ((ah >> 1) & 0x10) |
  455. ((((ah >> 5) ^ (ah >> 2)) & 0x1) << 3) |
  456. ((ah >> 2) & 0x4) | ((((ah >> 4) ^ (ah >> 1)) & 0x1) << 1) | (ah & 0x1);
  457. alahxal = gf64_mul(ahxal, al);
  458. deno = alahxal ^ ah2B;
  459. inv = gf64_inv[deno];
  460. bl = gf64_mul(inv, ahxal);
  461. bh = gf64_mul(inv, ah);
  462. dout = ((bh & 0x3f) << 6) | (bl & 0x3f);
  463. return (((bh & 0x3f) << 6) | (bl & 0x3f));
  464. }
  465. static unsigned short err_pos_lut[4096] = {
  466. 0xfff, 0x000, 0x451, 0xfff, 0xfff, 0x3cf, 0xfff, 0x041,
  467. 0xfff, 0xfff, 0xfff, 0xfff, 0x28a, 0xfff, 0x492, 0xfff,
  468. 0x145, 0xfff, 0xfff, 0x514, 0xfff, 0x082, 0xfff, 0xfff,
  469. 0xfff, 0x249, 0x38e, 0x410, 0xfff, 0x104, 0x208, 0x1c7,
  470. 0xfff, 0xfff, 0xfff, 0xfff, 0x2cb, 0xfff, 0xfff, 0xfff,
  471. 0x0c3, 0x34d, 0x4d3, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  472. 0xfff, 0xfff, 0xfff, 0x186, 0xfff, 0xfff, 0xfff, 0xfff,
  473. 0xfff, 0x30c, 0x555, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  474. 0xfff, 0xfff, 0xfff, 0x166, 0xfff, 0xfff, 0xfff, 0xfff,
  475. 0x385, 0x14e, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4e1,
  476. 0xfff, 0xfff, 0xfff, 0xfff, 0x538, 0xfff, 0x16d, 0xfff,
  477. 0xfff, 0xfff, 0x45b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  478. 0xfff, 0xfff, 0xfff, 0x29c, 0x2cc, 0x30b, 0x2b3, 0xfff,
  479. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0b3, 0xfff, 0x2f7,
  480. 0xfff, 0x32b, 0xfff, 0xfff, 0xfff, 0xfff, 0x0a7, 0xfff,
  481. 0xfff, 0x2da, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  482. 0xfff, 0x07e, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  483. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x11c, 0xfff, 0xfff,
  484. 0xfff, 0xfff, 0xfff, 0x22f, 0xfff, 0x1f4, 0xfff, 0xfff,
  485. 0x2b0, 0x504, 0xfff, 0x114, 0xfff, 0xfff, 0xfff, 0x21d,
  486. 0xfff, 0xfff, 0xfff, 0xfff, 0x00d, 0x3c4, 0x340, 0x10f,
  487. 0xfff, 0xfff, 0x266, 0x02e, 0xfff, 0xfff, 0xfff, 0x4f8,
  488. 0x337, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  489. 0xfff, 0xfff, 0xfff, 0x07b, 0x168, 0xfff, 0xfff, 0x0fe,
  490. 0xfff, 0xfff, 0x51a, 0xfff, 0x458, 0xfff, 0x36d, 0xfff,
  491. 0xfff, 0xfff, 0xfff, 0x073, 0x37d, 0x415, 0x550, 0xfff,
  492. 0xfff, 0xfff, 0x23b, 0x4b4, 0xfff, 0xfff, 0xfff, 0x1a1,
  493. 0xfff, 0xfff, 0x3aa, 0xfff, 0x117, 0x04d, 0x341, 0xfff,
  494. 0xfff, 0xfff, 0xfff, 0x518, 0x03e, 0x0f2, 0xfff, 0xfff,
  495. 0xfff, 0xfff, 0xfff, 0x363, 0xfff, 0x0b9, 0xfff, 0xfff,
  496. 0x241, 0xfff, 0xfff, 0x049, 0xfff, 0xfff, 0xfff, 0xfff,
  497. 0x15f, 0x52d, 0xfff, 0xfff, 0xfff, 0x29e, 0xfff, 0xfff,
  498. 0xfff, 0xfff, 0x4cf, 0x0fc, 0xfff, 0x36f, 0x3d3, 0xfff,
  499. 0x228, 0xfff, 0xfff, 0x45e, 0xfff, 0xfff, 0xfff, 0xfff,
  500. 0x238, 0xfff, 0xfff, 0xfff, 0xfff, 0x47f, 0xfff, 0xfff,
  501. 0x43a, 0x265, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x3e8,
  502. 0xfff, 0xfff, 0x01a, 0xfff, 0xfff, 0xfff, 0xfff, 0x21e,
  503. 0x1fc, 0x40b, 0xfff, 0xfff, 0xfff, 0x2d0, 0x159, 0xfff,
  504. 0xfff, 0x313, 0xfff, 0xfff, 0x05c, 0x4cc, 0xfff, 0xfff,
  505. 0x0f6, 0x3d5, 0xfff, 0xfff, 0xfff, 0x54f, 0xfff, 0xfff,
  506. 0xfff, 0x172, 0x1e4, 0x07c, 0xfff, 0xfff, 0xfff, 0xfff,
  507. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x53c, 0x1ad, 0x535,
  508. 0x19b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  509. 0xfff, 0xfff, 0x092, 0xfff, 0x2be, 0xfff, 0xfff, 0x482,
  510. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0e6, 0xfff, 0xfff,
  511. 0xfff, 0xfff, 0xfff, 0x476, 0xfff, 0x51d, 0xfff, 0xfff,
  512. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  513. 0xfff, 0xfff, 0x342, 0x2b5, 0x22e, 0x09a, 0xfff, 0x08d,
  514. 0x44f, 0x3ed, 0xfff, 0xfff, 0xfff, 0xfff, 0x3d1, 0xfff,
  515. 0xfff, 0x543, 0xfff, 0x48f, 0xfff, 0x3d2, 0xfff, 0x0d5,
  516. 0x113, 0x0ec, 0x427, 0xfff, 0xfff, 0xfff, 0x4c4, 0xfff,
  517. 0xfff, 0x50a, 0xfff, 0x144, 0xfff, 0x105, 0x39f, 0x294,
  518. 0x164, 0xfff, 0x31a, 0xfff, 0xfff, 0x49a, 0xfff, 0x130,
  519. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  520. 0x1be, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  521. 0xfff, 0xfff, 0x49e, 0x371, 0xfff, 0xfff, 0xfff, 0xfff,
  522. 0xfff, 0xfff, 0xfff, 0xfff, 0x0e8, 0x49c, 0x0f4, 0xfff,
  523. 0x338, 0x1a7, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  524. 0xfff, 0x36c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  525. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  526. 0xfff, 0x1ae, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  527. 0xfff, 0x31b, 0xfff, 0xfff, 0x2dd, 0x522, 0xfff, 0xfff,
  528. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2f4,
  529. 0x3c6, 0x30d, 0xfff, 0xfff, 0xfff, 0xfff, 0x34c, 0x18f,
  530. 0x30a, 0xfff, 0x01f, 0x079, 0xfff, 0xfff, 0x54d, 0x46b,
  531. 0x28c, 0x37f, 0xfff, 0xfff, 0xfff, 0xfff, 0x355, 0xfff,
  532. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x14f, 0xfff, 0xfff,
  533. 0xfff, 0xfff, 0xfff, 0x359, 0x3fe, 0x3c5, 0xfff, 0xfff,
  534. 0xfff, 0xfff, 0x423, 0xfff, 0xfff, 0x34a, 0x22c, 0xfff,
  535. 0x25a, 0xfff, 0xfff, 0x4ad, 0xfff, 0x28d, 0xfff, 0xfff,
  536. 0xfff, 0xfff, 0xfff, 0x547, 0xfff, 0xfff, 0xfff, 0xfff,
  537. 0x2e2, 0xfff, 0xfff, 0x1d5, 0xfff, 0x2a8, 0xfff, 0xfff,
  538. 0x03f, 0xfff, 0xfff, 0xfff, 0xfff, 0x3eb, 0x0fa, 0xfff,
  539. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x55b, 0xfff,
  540. 0x08e, 0xfff, 0x3ae, 0xfff, 0x3a4, 0xfff, 0x282, 0x158,
  541. 0xfff, 0x382, 0xfff, 0xfff, 0x499, 0xfff, 0xfff, 0x08a,
  542. 0xfff, 0xfff, 0xfff, 0x456, 0x3be, 0xfff, 0x1e2, 0xfff,
  543. 0xfff, 0xfff, 0xfff, 0xfff, 0x559, 0xfff, 0x1a0, 0xfff,
  544. 0xfff, 0x0b4, 0xfff, 0xfff, 0xfff, 0x2df, 0xfff, 0xfff,
  545. 0xfff, 0x07f, 0x4f5, 0xfff, 0xfff, 0x27c, 0x133, 0x017,
  546. 0xfff, 0x3fd, 0xfff, 0xfff, 0xfff, 0x44d, 0x4cd, 0x17a,
  547. 0x0d7, 0x537, 0xfff, 0xfff, 0x353, 0xfff, 0xfff, 0x351,
  548. 0x366, 0xfff, 0x44a, 0xfff, 0x1a6, 0xfff, 0xfff, 0xfff,
  549. 0x291, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1e3,
  550. 0xfff, 0xfff, 0xfff, 0xfff, 0x389, 0xfff, 0x07a, 0xfff,
  551. 0x1b6, 0x2ed, 0xfff, 0xfff, 0xfff, 0xfff, 0x24e, 0x074,
  552. 0xfff, 0xfff, 0x3dc, 0xfff, 0x4e3, 0xfff, 0xfff, 0xfff,
  553. 0xfff, 0x4eb, 0xfff, 0xfff, 0x3b8, 0x4de, 0xfff, 0x19c,
  554. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x262,
  555. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x076, 0x4e8, 0x3da,
  556. 0xfff, 0x531, 0xfff, 0xfff, 0x14a, 0xfff, 0x0a2, 0x433,
  557. 0x3df, 0x1e9, 0xfff, 0xfff, 0xfff, 0xfff, 0x3e7, 0x285,
  558. 0x2d8, 0xfff, 0xfff, 0xfff, 0x349, 0x18d, 0x098, 0xfff,
  559. 0x0df, 0x4bf, 0xfff, 0xfff, 0x0b2, 0xfff, 0x346, 0x24d,
  560. 0xfff, 0xfff, 0xfff, 0x24f, 0x4fa, 0x2f9, 0xfff, 0xfff,
  561. 0x3c9, 0xfff, 0x2b4, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  562. 0xfff, 0x056, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  563. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  564. 0xfff, 0x179, 0xfff, 0x0e9, 0x3f0, 0x33d, 0xfff, 0xfff,
  565. 0xfff, 0xfff, 0xfff, 0x1fd, 0xfff, 0xfff, 0x526, 0xfff,
  566. 0xfff, 0xfff, 0x53d, 0xfff, 0xfff, 0xfff, 0x170, 0x331,
  567. 0xfff, 0x068, 0xfff, 0xfff, 0xfff, 0x3f7, 0xfff, 0x3d8,
  568. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  569. 0xfff, 0x09f, 0x556, 0xfff, 0xfff, 0x02d, 0xfff, 0xfff,
  570. 0x553, 0xfff, 0xfff, 0xfff, 0x1f0, 0xfff, 0xfff, 0x4d6,
  571. 0x41e, 0xfff, 0xfff, 0xfff, 0xfff, 0x4d5, 0xfff, 0xfff,
  572. 0xfff, 0xfff, 0xfff, 0x248, 0xfff, 0xfff, 0xfff, 0x0a3,
  573. 0xfff, 0x217, 0xfff, 0xfff, 0xfff, 0x4f1, 0x209, 0xfff,
  574. 0xfff, 0x475, 0x234, 0x52b, 0x398, 0xfff, 0x08b, 0xfff,
  575. 0xfff, 0xfff, 0xfff, 0x2c2, 0xfff, 0xfff, 0xfff, 0xfff,
  576. 0xfff, 0xfff, 0x268, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  577. 0xfff, 0x4a3, 0xfff, 0x0aa, 0xfff, 0x1d9, 0xfff, 0xfff,
  578. 0xfff, 0xfff, 0x155, 0xfff, 0xfff, 0xfff, 0xfff, 0x0bf,
  579. 0x539, 0xfff, 0xfff, 0x2f1, 0x545, 0xfff, 0xfff, 0xfff,
  580. 0xfff, 0xfff, 0xfff, 0x2a7, 0x06f, 0xfff, 0x378, 0xfff,
  581. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x25e, 0xfff,
  582. 0xfff, 0xfff, 0xfff, 0x15d, 0x02a, 0xfff, 0xfff, 0x0bc,
  583. 0x235, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  584. 0x150, 0xfff, 0x1a9, 0xfff, 0xfff, 0xfff, 0xfff, 0x381,
  585. 0xfff, 0x04e, 0x270, 0x13f, 0xfff, 0xfff, 0x405, 0xfff,
  586. 0x3cd, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  587. 0xfff, 0x2ef, 0xfff, 0x06a, 0xfff, 0xfff, 0xfff, 0x34f,
  588. 0x212, 0xfff, 0xfff, 0x0e2, 0xfff, 0x083, 0x298, 0xfff,
  589. 0xfff, 0xfff, 0x0c2, 0xfff, 0xfff, 0x52e, 0xfff, 0x488,
  590. 0xfff, 0xfff, 0xfff, 0x36b, 0xfff, 0xfff, 0xfff, 0x442,
  591. 0x091, 0xfff, 0x41c, 0xfff, 0xfff, 0x3a5, 0xfff, 0x4e6,
  592. 0xfff, 0xfff, 0x40d, 0x31d, 0xfff, 0xfff, 0xfff, 0x4c1,
  593. 0x053, 0xfff, 0x418, 0x13c, 0xfff, 0x350, 0xfff, 0x0ae,
  594. 0xfff, 0xfff, 0x41f, 0xfff, 0x470, 0xfff, 0x4ca, 0xfff,
  595. 0xfff, 0xfff, 0x02b, 0x450, 0xfff, 0x1f8, 0xfff, 0xfff,
  596. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x293, 0xfff,
  597. 0xfff, 0xfff, 0xfff, 0x411, 0xfff, 0xfff, 0xfff, 0xfff,
  598. 0xfff, 0xfff, 0xfff, 0xfff, 0x0b8, 0xfff, 0xfff, 0xfff,
  599. 0x3e1, 0xfff, 0xfff, 0xfff, 0xfff, 0x43c, 0xfff, 0x2b2,
  600. 0x2ab, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ec,
  601. 0xfff, 0xfff, 0xfff, 0x3f8, 0x034, 0xfff, 0xfff, 0xfff,
  602. 0xfff, 0xfff, 0xfff, 0x11a, 0xfff, 0x541, 0x45c, 0x134,
  603. 0x1cc, 0xfff, 0xfff, 0xfff, 0x469, 0xfff, 0xfff, 0x44b,
  604. 0x161, 0xfff, 0xfff, 0xfff, 0x055, 0xfff, 0xfff, 0xfff,
  605. 0xfff, 0x307, 0xfff, 0xfff, 0xfff, 0xfff, 0x2d1, 0xfff,
  606. 0xfff, 0xfff, 0x124, 0x37b, 0x26b, 0x336, 0xfff, 0xfff,
  607. 0x2e4, 0x3cb, 0xfff, 0xfff, 0x0f8, 0x3c8, 0xfff, 0xfff,
  608. 0xfff, 0x461, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4b5,
  609. 0x2cf, 0xfff, 0xfff, 0xfff, 0x20f, 0xfff, 0x35a, 0xfff,
  610. 0x490, 0xfff, 0x185, 0xfff, 0xfff, 0xfff, 0xfff, 0x42e,
  611. 0xfff, 0xfff, 0xfff, 0xfff, 0x54b, 0xfff, 0xfff, 0xfff,
  612. 0x146, 0xfff, 0x412, 0xfff, 0xfff, 0xfff, 0x1ff, 0xfff,
  613. 0xfff, 0x3e0, 0xfff, 0xfff, 0xfff, 0xfff, 0x2d5, 0xfff,
  614. 0x4df, 0x505, 0xfff, 0x413, 0xfff, 0x1a5, 0xfff, 0x3b2,
  615. 0xfff, 0xfff, 0xfff, 0x35b, 0xfff, 0x116, 0xfff, 0xfff,
  616. 0x171, 0x4d0, 0xfff, 0x154, 0x12d, 0xfff, 0xfff, 0xfff,
  617. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x468, 0x4db, 0xfff,
  618. 0xfff, 0x1df, 0xfff, 0xfff, 0xfff, 0xfff, 0x05a, 0xfff,
  619. 0x0f1, 0x403, 0xfff, 0x22b, 0x2e0, 0xfff, 0xfff, 0xfff,
  620. 0x2b7, 0x373, 0xfff, 0xfff, 0xfff, 0xfff, 0x13e, 0xfff,
  621. 0xfff, 0xfff, 0x0d0, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  622. 0x329, 0x1d2, 0x3fa, 0x047, 0xfff, 0x2f2, 0xfff, 0xfff,
  623. 0x141, 0x0ac, 0x1d7, 0xfff, 0x07d, 0xfff, 0xfff, 0xfff,
  624. 0x1c1, 0xfff, 0x487, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  625. 0xfff, 0xfff, 0xfff, 0x045, 0xfff, 0xfff, 0xfff, 0xfff,
  626. 0x288, 0x0cd, 0xfff, 0xfff, 0xfff, 0xfff, 0x226, 0x1d8,
  627. 0xfff, 0x153, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4cb,
  628. 0x528, 0xfff, 0xfff, 0xfff, 0x20a, 0x343, 0x3a1, 0xfff,
  629. 0xfff, 0xfff, 0x2d7, 0x2d3, 0x1aa, 0x4c5, 0xfff, 0xfff,
  630. 0xfff, 0x42b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  631. 0xfff, 0xfff, 0xfff, 0xfff, 0x3e9, 0xfff, 0x20b, 0x260,
  632. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x37c, 0x2fd,
  633. 0xfff, 0xfff, 0x2c8, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  634. 0xfff, 0x31e, 0xfff, 0x335, 0xfff, 0xfff, 0xfff, 0xfff,
  635. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  636. 0xfff, 0xfff, 0x135, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  637. 0xfff, 0xfff, 0x35c, 0x4dd, 0x129, 0xfff, 0xfff, 0xfff,
  638. 0xfff, 0xfff, 0x1ef, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  639. 0xfff, 0x34e, 0xfff, 0xfff, 0xfff, 0xfff, 0x407, 0xfff,
  640. 0xfff, 0xfff, 0xfff, 0xfff, 0x3ad, 0xfff, 0xfff, 0xfff,
  641. 0x379, 0xfff, 0xfff, 0x1d0, 0x38d, 0xfff, 0xfff, 0x1e8,
  642. 0x184, 0x3c1, 0x1c4, 0xfff, 0x1f9, 0xfff, 0xfff, 0x424,
  643. 0xfff, 0xfff, 0xfff, 0xfff, 0x1d3, 0x0d4, 0xfff, 0x4e9,
  644. 0xfff, 0xfff, 0xfff, 0x530, 0x107, 0xfff, 0x106, 0x04f,
  645. 0xfff, 0xfff, 0x4c7, 0x503, 0xfff, 0xfff, 0xfff, 0xfff,
  646. 0xfff, 0x15c, 0xfff, 0x23f, 0xfff, 0xfff, 0xfff, 0xfff,
  647. 0xfff, 0xfff, 0xfff, 0xfff, 0x4f3, 0xfff, 0xfff, 0x3c7,
  648. 0xfff, 0x278, 0xfff, 0xfff, 0x0a6, 0xfff, 0xfff, 0xfff,
  649. 0x122, 0x1cf, 0xfff, 0x327, 0xfff, 0x2e5, 0xfff, 0x29d,
  650. 0xfff, 0xfff, 0x3f1, 0xfff, 0xfff, 0x48d, 0xfff, 0xfff,
  651. 0xfff, 0xfff, 0x054, 0xfff, 0xfff, 0xfff, 0xfff, 0x178,
  652. 0x27e, 0x4e0, 0x352, 0x02f, 0x09c, 0xfff, 0x2a0, 0xfff,
  653. 0xfff, 0x46a, 0x457, 0xfff, 0xfff, 0x501, 0xfff, 0x2ba,
  654. 0xfff, 0xfff, 0xfff, 0x54e, 0x2e7, 0xfff, 0xfff, 0xfff,
  655. 0xfff, 0xfff, 0x551, 0xfff, 0xfff, 0x1db, 0x2aa, 0xfff,
  656. 0xfff, 0x4bc, 0xfff, 0xfff, 0x395, 0xfff, 0x0de, 0xfff,
  657. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x455, 0xfff, 0x17e,
  658. 0xfff, 0x221, 0x4a7, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  659. 0x388, 0xfff, 0xfff, 0xfff, 0x308, 0xfff, 0xfff, 0xfff,
  660. 0x20e, 0x4b9, 0xfff, 0x273, 0x20c, 0x09e, 0xfff, 0x057,
  661. 0xfff, 0xfff, 0xfff, 0xfff, 0x3f2, 0xfff, 0x1a8, 0x3a6,
  662. 0x14c, 0xfff, 0xfff, 0x071, 0xfff, 0xfff, 0x53a, 0xfff,
  663. 0xfff, 0xfff, 0xfff, 0x109, 0xfff, 0xfff, 0x399, 0xfff,
  664. 0x061, 0x4f0, 0x39e, 0x244, 0xfff, 0x035, 0xfff, 0xfff,
  665. 0x305, 0x47e, 0x297, 0xfff, 0xfff, 0x2b8, 0xfff, 0xfff,
  666. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1bc, 0xfff, 0x2fc,
  667. 0xfff, 0xfff, 0x554, 0xfff, 0xfff, 0xfff, 0xfff, 0x3b6,
  668. 0xfff, 0xfff, 0xfff, 0x515, 0x397, 0xfff, 0xfff, 0x12f,
  669. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4e5,
  670. 0xfff, 0x4fc, 0xfff, 0xfff, 0x05e, 0xfff, 0xfff, 0xfff,
  671. 0xfff, 0xfff, 0x0a8, 0x3af, 0x015, 0xfff, 0xfff, 0xfff,
  672. 0xfff, 0x138, 0xfff, 0xfff, 0xfff, 0x540, 0xfff, 0xfff,
  673. 0xfff, 0x027, 0x523, 0x2f0, 0xfff, 0xfff, 0xfff, 0xfff,
  674. 0xfff, 0xfff, 0x16c, 0xfff, 0x27d, 0xfff, 0xfff, 0xfff,
  675. 0xfff, 0x04c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4dc,
  676. 0xfff, 0xfff, 0x059, 0x301, 0xfff, 0xfff, 0xfff, 0xfff,
  677. 0xfff, 0xfff, 0xfff, 0x1a3, 0xfff, 0x15a, 0xfff, 0xfff,
  678. 0x0a5, 0xfff, 0x435, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  679. 0xfff, 0x051, 0xfff, 0xfff, 0x131, 0xfff, 0x4f4, 0xfff,
  680. 0xfff, 0xfff, 0xfff, 0x441, 0xfff, 0x4fb, 0xfff, 0x03b,
  681. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ed, 0x274,
  682. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0d3, 0x55e, 0x1b3,
  683. 0xfff, 0x0bd, 0xfff, 0xfff, 0xfff, 0xfff, 0x225, 0xfff,
  684. 0xfff, 0xfff, 0xfff, 0xfff, 0x4b7, 0xfff, 0xfff, 0x2ff,
  685. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4c3, 0xfff,
  686. 0x383, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2f6,
  687. 0xfff, 0xfff, 0x1ee, 0xfff, 0x03d, 0xfff, 0xfff, 0xfff,
  688. 0xfff, 0xfff, 0x26f, 0x1dc, 0xfff, 0x0db, 0xfff, 0xfff,
  689. 0xfff, 0xfff, 0xfff, 0x0ce, 0xfff, 0xfff, 0x127, 0x03a,
  690. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x311, 0xfff,
  691. 0xfff, 0x13d, 0x09d, 0x47b, 0x2a6, 0x50d, 0x510, 0x19a,
  692. 0xfff, 0x354, 0x414, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  693. 0xfff, 0xfff, 0x44c, 0x3b0, 0xfff, 0x23d, 0x429, 0xfff,
  694. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  695. 0x4c0, 0x416, 0xfff, 0x05b, 0xfff, 0xfff, 0x137, 0xfff,
  696. 0x25f, 0x49f, 0xfff, 0x279, 0x013, 0xfff, 0xfff, 0xfff,
  697. 0x269, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  698. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x3d0, 0xfff, 0xfff,
  699. 0xfff, 0xfff, 0xfff, 0xfff, 0x077, 0xfff, 0xfff, 0x3fb,
  700. 0xfff, 0xfff, 0xfff, 0xfff, 0x271, 0x3a0, 0xfff, 0xfff,
  701. 0x40f, 0xfff, 0xfff, 0x3de, 0xfff, 0xfff, 0xfff, 0xfff,
  702. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ab, 0x26a,
  703. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x489, 0xfff, 0xfff,
  704. 0x252, 0xfff, 0xfff, 0xfff, 0xfff, 0x1b7, 0x42f, 0xfff,
  705. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x3b7,
  706. 0xfff, 0x2bb, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  707. 0xfff, 0xfff, 0xfff, 0x0f7, 0x01d, 0xfff, 0x067, 0xfff,
  708. 0xfff, 0xfff, 0xfff, 0x4e2, 0xfff, 0xfff, 0x4bb, 0xfff,
  709. 0xfff, 0xfff, 0x17b, 0xfff, 0x0ee, 0xfff, 0xfff, 0xfff,
  710. 0xfff, 0xfff, 0x36e, 0xfff, 0xfff, 0xfff, 0x533, 0xfff,
  711. 0xfff, 0xfff, 0x4d4, 0x356, 0xfff, 0xfff, 0x375, 0xfff,
  712. 0xfff, 0xfff, 0xfff, 0x4a4, 0x513, 0xfff, 0xfff, 0xfff,
  713. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4ff, 0xfff, 0x2af,
  714. 0xfff, 0xfff, 0x026, 0xfff, 0x0ad, 0xfff, 0xfff, 0xfff,
  715. 0xfff, 0x26e, 0xfff, 0xfff, 0xfff, 0xfff, 0x493, 0xfff,
  716. 0x463, 0x4d2, 0x4be, 0xfff, 0xfff, 0xfff, 0xfff, 0x4f2,
  717. 0x0b6, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  718. 0xfff, 0x32d, 0x315, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  719. 0xfff, 0x13a, 0x4a1, 0xfff, 0x27a, 0xfff, 0xfff, 0xfff,
  720. 0x47a, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  721. 0x334, 0xfff, 0xfff, 0xfff, 0xfff, 0x54c, 0xfff, 0xfff,
  722. 0xfff, 0x0c9, 0x007, 0xfff, 0xfff, 0x12e, 0xfff, 0x0ff,
  723. 0xfff, 0xfff, 0x3f5, 0x509, 0xfff, 0xfff, 0xfff, 0xfff,
  724. 0x1c3, 0x2ad, 0xfff, 0xfff, 0x47c, 0x261, 0xfff, 0xfff,
  725. 0xfff, 0xfff, 0xfff, 0x152, 0xfff, 0xfff, 0xfff, 0x339,
  726. 0xfff, 0x243, 0x1c0, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  727. 0x063, 0xfff, 0xfff, 0x254, 0xfff, 0xfff, 0x173, 0xfff,
  728. 0x0c7, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  729. 0xfff, 0x362, 0x259, 0x485, 0x374, 0x0dc, 0x3ab, 0xfff,
  730. 0x1c5, 0x534, 0x544, 0xfff, 0xfff, 0x508, 0xfff, 0x402,
  731. 0x408, 0xfff, 0x0e7, 0xfff, 0xfff, 0x00a, 0x205, 0xfff,
  732. 0xfff, 0x2b9, 0xfff, 0xfff, 0xfff, 0x465, 0xfff, 0xfff,
  733. 0xfff, 0xfff, 0xfff, 0xfff, 0x23a, 0xfff, 0xfff, 0xfff,
  734. 0xfff, 0x147, 0x19d, 0x115, 0x214, 0xfff, 0x090, 0x368,
  735. 0xfff, 0x210, 0xfff, 0xfff, 0x280, 0x52a, 0x163, 0x148,
  736. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x326, 0xfff, 0xfff,
  737. 0xfff, 0xfff, 0xfff, 0x2de, 0xfff, 0xfff, 0xfff, 0xfff,
  738. 0x206, 0x2c1, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  739. 0x189, 0xfff, 0xfff, 0xfff, 0xfff, 0x367, 0xfff, 0x1a4,
  740. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x443, 0xfff, 0x27b,
  741. 0xfff, 0xfff, 0x251, 0x549, 0xfff, 0xfff, 0xfff, 0xfff,
  742. 0xfff, 0xfff, 0x188, 0x04b, 0xfff, 0xfff, 0xfff, 0x31f,
  743. 0x4a6, 0xfff, 0x246, 0x1de, 0x156, 0xfff, 0xfff, 0xfff,
  744. 0x3a9, 0xfff, 0xfff, 0xfff, 0x2fa, 0xfff, 0x128, 0x0d1,
  745. 0x449, 0x255, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  746. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  747. 0xfff, 0xfff, 0xfff, 0xfff, 0x258, 0xfff, 0xfff, 0xfff,
  748. 0x532, 0xfff, 0xfff, 0xfff, 0x303, 0x517, 0xfff, 0xfff,
  749. 0x2a9, 0x24a, 0xfff, 0xfff, 0x231, 0xfff, 0xfff, 0xfff,
  750. 0xfff, 0xfff, 0x4b6, 0x516, 0xfff, 0xfff, 0x0e4, 0x0eb,
  751. 0xfff, 0x4e4, 0xfff, 0x275, 0xfff, 0xfff, 0x031, 0xfff,
  752. 0xfff, 0xfff, 0xfff, 0xfff, 0x025, 0x21a, 0xfff, 0x0cc,
  753. 0x45f, 0x3d9, 0x289, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  754. 0xfff, 0xfff, 0x23e, 0xfff, 0xfff, 0xfff, 0x438, 0x097,
  755. 0x419, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  756. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  757. 0xfff, 0xfff, 0x0a9, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  758. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  759. 0x37e, 0x0e0, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x431,
  760. 0x372, 0xfff, 0xfff, 0xfff, 0x1ba, 0x06e, 0xfff, 0x1b1,
  761. 0xfff, 0xfff, 0x12a, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  762. 0xfff, 0xfff, 0x193, 0xfff, 0xfff, 0xfff, 0xfff, 0x10a,
  763. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x048, 0x1b4,
  764. 0xfff, 0xfff, 0xfff, 0xfff, 0x295, 0x140, 0x108, 0xfff,
  765. 0xfff, 0xfff, 0xfff, 0x16f, 0xfff, 0x0a4, 0x37a, 0xfff,
  766. 0x29a, 0xfff, 0x284, 0xfff, 0xfff, 0xfff, 0xfff, 0x4c6,
  767. 0x2a2, 0x3a3, 0xfff, 0x201, 0xfff, 0xfff, 0xfff, 0x4bd,
  768. 0x005, 0x54a, 0x3b5, 0x204, 0x2ee, 0x11d, 0x436, 0xfff,
  769. 0xfff, 0xfff, 0xfff, 0xfff, 0x3ec, 0xfff, 0xfff, 0xfff,
  770. 0xfff, 0xfff, 0xfff, 0xfff, 0x11f, 0x498, 0x21c, 0xfff,
  771. 0xfff, 0xfff, 0x3d6, 0xfff, 0x4ab, 0xfff, 0x432, 0x2eb,
  772. 0x542, 0x4fd, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  773. 0xfff, 0xfff, 0xfff, 0x4ce, 0xfff, 0xfff, 0x2fb, 0xfff,
  774. 0xfff, 0x2e1, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  775. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1b9, 0x037, 0x0dd,
  776. 0xfff, 0xfff, 0xfff, 0x2bf, 0x521, 0x496, 0x095, 0xfff,
  777. 0xfff, 0x328, 0x070, 0x1bf, 0xfff, 0x393, 0xfff, 0xfff,
  778. 0x102, 0xfff, 0xfff, 0x21b, 0xfff, 0x142, 0x263, 0x519,
  779. 0xfff, 0x2a5, 0x177, 0xfff, 0x14d, 0x471, 0x4ae, 0xfff,
  780. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  781. 0x1f6, 0xfff, 0x481, 0xfff, 0xfff, 0xfff, 0x151, 0xfff,
  782. 0xfff, 0xfff, 0x085, 0x33f, 0xfff, 0xfff, 0xfff, 0x084,
  783. 0xfff, 0xfff, 0xfff, 0x345, 0x3a2, 0xfff, 0xfff, 0x0a0,
  784. 0x0da, 0x024, 0xfff, 0xfff, 0xfff, 0x1bd, 0xfff, 0x55c,
  785. 0x467, 0x445, 0xfff, 0xfff, 0xfff, 0x052, 0xfff, 0xfff,
  786. 0xfff, 0xfff, 0x51e, 0xfff, 0xfff, 0x39d, 0xfff, 0x35f,
  787. 0xfff, 0x376, 0x3ee, 0xfff, 0xfff, 0xfff, 0xfff, 0x448,
  788. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x16a,
  789. 0xfff, 0x036, 0x38f, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  790. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x211,
  791. 0xfff, 0xfff, 0xfff, 0x230, 0xfff, 0xfff, 0x3ba, 0xfff,
  792. 0xfff, 0xfff, 0x3ce, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  793. 0xfff, 0xfff, 0xfff, 0x229, 0xfff, 0x176, 0xfff, 0xfff,
  794. 0xfff, 0xfff, 0xfff, 0x00b, 0xfff, 0x162, 0x018, 0xfff,
  795. 0xfff, 0x233, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  796. 0x400, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  797. 0xfff, 0xfff, 0xfff, 0x12b, 0xfff, 0xfff, 0xfff, 0xfff,
  798. 0xfff, 0x3f4, 0xfff, 0x0f0, 0xfff, 0x1ac, 0xfff, 0xfff,
  799. 0x119, 0xfff, 0x2c0, 0xfff, 0xfff, 0xfff, 0x49b, 0xfff,
  800. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x23c, 0xfff,
  801. 0x4b3, 0x010, 0x064, 0xfff, 0xfff, 0x4ba, 0xfff, 0xfff,
  802. 0xfff, 0xfff, 0xfff, 0x3c2, 0xfff, 0xfff, 0xfff, 0xfff,
  803. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x006, 0x196, 0xfff,
  804. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x100, 0x191, 0xfff,
  805. 0x1ea, 0x29f, 0xfff, 0xfff, 0xfff, 0x276, 0xfff, 0xfff,
  806. 0x2b1, 0x3b9, 0xfff, 0x03c, 0xfff, 0xfff, 0xfff, 0x180,
  807. 0xfff, 0x08f, 0xfff, 0xfff, 0x19e, 0x019, 0xfff, 0x0b0,
  808. 0x0fd, 0x332, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  809. 0xfff, 0x06b, 0x2e8, 0xfff, 0x446, 0xfff, 0xfff, 0x004,
  810. 0x247, 0x197, 0xfff, 0x112, 0x169, 0x292, 0xfff, 0x302,
  811. 0xfff, 0xfff, 0x33b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  812. 0xfff, 0xfff, 0xfff, 0x287, 0x21f, 0xfff, 0x3ea, 0xfff,
  813. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4e7, 0xfff, 0xfff,
  814. 0xfff, 0xfff, 0xfff, 0x3a8, 0xfff, 0xfff, 0x2bc, 0xfff,
  815. 0x484, 0x296, 0xfff, 0x1c9, 0x08c, 0x1e5, 0x48a, 0xfff,
  816. 0x360, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  817. 0x1ca, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  818. 0xfff, 0xfff, 0xfff, 0x10d, 0xfff, 0xfff, 0xfff, 0xfff,
  819. 0xfff, 0xfff, 0x066, 0x2ea, 0x28b, 0x25b, 0xfff, 0x072,
  820. 0xfff, 0xfff, 0xfff, 0xfff, 0x2b6, 0xfff, 0xfff, 0x272,
  821. 0xfff, 0xfff, 0x525, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  822. 0x2ca, 0xfff, 0xfff, 0xfff, 0x299, 0xfff, 0xfff, 0xfff,
  823. 0x558, 0x41a, 0xfff, 0x4f7, 0x557, 0xfff, 0x4a0, 0x344,
  824. 0x12c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x125,
  825. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  826. 0x40e, 0xfff, 0xfff, 0x502, 0xfff, 0x103, 0x3e6, 0xfff,
  827. 0x527, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  828. 0xfff, 0xfff, 0xfff, 0x45d, 0xfff, 0xfff, 0xfff, 0xfff,
  829. 0x44e, 0xfff, 0xfff, 0xfff, 0xfff, 0x0d2, 0x4c9, 0x35e,
  830. 0x459, 0x2d9, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x17d,
  831. 0x0c4, 0xfff, 0xfff, 0xfff, 0x3ac, 0x390, 0x094, 0xfff,
  832. 0x483, 0x0ab, 0xfff, 0x253, 0xfff, 0x391, 0xfff, 0xfff,
  833. 0xfff, 0xfff, 0x123, 0x0ef, 0xfff, 0xfff, 0xfff, 0x330,
  834. 0x38c, 0xfff, 0xfff, 0x2ae, 0xfff, 0xfff, 0xfff, 0x042,
  835. 0x012, 0x06d, 0xfff, 0xfff, 0xfff, 0x32a, 0x3db, 0x364,
  836. 0x2dc, 0xfff, 0x30f, 0x3d7, 0x4a5, 0x050, 0xfff, 0xfff,
  837. 0x029, 0xfff, 0xfff, 0xfff, 0xfff, 0x1d1, 0xfff, 0xfff,
  838. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x480, 0xfff,
  839. 0x4ed, 0x081, 0x0a1, 0xfff, 0xfff, 0xfff, 0x30e, 0x52f,
  840. 0x257, 0xfff, 0xfff, 0x447, 0xfff, 0xfff, 0xfff, 0xfff,
  841. 0xfff, 0xfff, 0xfff, 0x401, 0x3cc, 0xfff, 0xfff, 0x0fb,
  842. 0x2c9, 0x42a, 0x314, 0x33e, 0x3bd, 0x318, 0xfff, 0x10e,
  843. 0x2a1, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x24c,
  844. 0x506, 0xfff, 0x267, 0xfff, 0xfff, 0x219, 0xfff, 0x1eb,
  845. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  846. 0x309, 0x3e2, 0x46c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  847. 0x384, 0xfff, 0xfff, 0xfff, 0xfff, 0x50c, 0xfff, 0x24b,
  848. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x038,
  849. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x194,
  850. 0x143, 0x3e3, 0xfff, 0xfff, 0xfff, 0x4c2, 0xfff, 0xfff,
  851. 0x0e1, 0x25c, 0xfff, 0x237, 0xfff, 0x1fe, 0xfff, 0xfff,
  852. 0xfff, 0x065, 0x2a4, 0xfff, 0x386, 0x55a, 0x11b, 0xfff,
  853. 0xfff, 0x192, 0xfff, 0x183, 0x00e, 0xfff, 0xfff, 0xfff,
  854. 0xfff, 0xfff, 0xfff, 0x4b2, 0x18e, 0xfff, 0xfff, 0xfff,
  855. 0xfff, 0x486, 0x4ef, 0x0c6, 0x380, 0xfff, 0x4a8, 0xfff,
  856. 0x0c5, 0xfff, 0xfff, 0xfff, 0xfff, 0x093, 0x1b8, 0xfff,
  857. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2e6,
  858. 0xfff, 0x0f3, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  859. 0x28e, 0xfff, 0x53b, 0x420, 0x22a, 0x33a, 0xfff, 0x387,
  860. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2a3, 0xfff, 0xfff,
  861. 0xfff, 0x428, 0x500, 0xfff, 0xfff, 0x120, 0x2c6, 0x290,
  862. 0x2f5, 0x0e3, 0xfff, 0x0b7, 0xfff, 0x319, 0x474, 0xfff,
  863. 0xfff, 0xfff, 0x529, 0x014, 0xfff, 0x41b, 0x40a, 0x18b,
  864. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0d9,
  865. 0xfff, 0x38a, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ce, 0xfff,
  866. 0xfff, 0xfff, 0xfff, 0xfff, 0x3b1, 0xfff, 0xfff, 0x05d,
  867. 0x2c4, 0xfff, 0xfff, 0x4af, 0xfff, 0x030, 0xfff, 0xfff,
  868. 0x203, 0xfff, 0x277, 0x256, 0xfff, 0xfff, 0xfff, 0x4f9,
  869. 0xfff, 0x2c7, 0xfff, 0x466, 0x016, 0x1cd, 0xfff, 0x167,
  870. 0xfff, 0xfff, 0x0c8, 0xfff, 0x43d, 0xfff, 0xfff, 0x020,
  871. 0xfff, 0xfff, 0x232, 0x1cb, 0x1e0, 0xfff, 0xfff, 0x347,
  872. 0xfff, 0x478, 0xfff, 0x365, 0xfff, 0xfff, 0xfff, 0xfff,
  873. 0x358, 0xfff, 0x10b, 0xfff, 0x35d, 0xfff, 0xfff, 0xfff,
  874. 0xfff, 0xfff, 0x452, 0x22d, 0xfff, 0xfff, 0x47d, 0xfff,
  875. 0x2f3, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x460, 0xfff,
  876. 0xfff, 0xfff, 0x50b, 0xfff, 0xfff, 0xfff, 0x2ec, 0xfff,
  877. 0xfff, 0xfff, 0xfff, 0xfff, 0x4b1, 0x422, 0xfff, 0xfff,
  878. 0xfff, 0x2d4, 0xfff, 0x239, 0xfff, 0xfff, 0xfff, 0x439,
  879. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  880. 0xfff, 0x491, 0x075, 0xfff, 0xfff, 0xfff, 0x06c, 0xfff,
  881. 0xfff, 0x0f9, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  882. 0xfff, 0x139, 0xfff, 0x4f6, 0xfff, 0xfff, 0x409, 0xfff,
  883. 0xfff, 0x15b, 0xfff, 0xfff, 0x348, 0xfff, 0xfff, 0xfff,
  884. 0xfff, 0x4a2, 0x49d, 0xfff, 0x033, 0x175, 0xfff, 0x039,
  885. 0xfff, 0x312, 0x40c, 0xfff, 0xfff, 0x325, 0xfff, 0xfff,
  886. 0xfff, 0xfff, 0xfff, 0xfff, 0x4aa, 0xfff, 0xfff, 0xfff,
  887. 0xfff, 0xfff, 0xfff, 0x165, 0x3bc, 0x48c, 0x310, 0x096,
  888. 0xfff, 0xfff, 0x250, 0x1a2, 0xfff, 0xfff, 0xfff, 0xfff,
  889. 0x20d, 0x2ac, 0xfff, 0xfff, 0x39b, 0xfff, 0x377, 0xfff,
  890. 0x512, 0x495, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  891. 0xfff, 0xfff, 0xfff, 0xfff, 0x357, 0x4ea, 0xfff, 0xfff,
  892. 0xfff, 0xfff, 0x198, 0xfff, 0xfff, 0xfff, 0x434, 0x04a,
  893. 0xfff, 0xfff, 0xfff, 0xfff, 0x062, 0xfff, 0x1d6, 0x1c8,
  894. 0xfff, 0x1f3, 0x281, 0xfff, 0x462, 0xfff, 0xfff, 0xfff,
  895. 0x4b0, 0xfff, 0x207, 0xfff, 0xfff, 0xfff, 0xfff, 0x3dd,
  896. 0xfff, 0xfff, 0x55d, 0xfff, 0x552, 0x494, 0x1af, 0xfff,
  897. 0xfff, 0xfff, 0xfff, 0xfff, 0x227, 0xfff, 0xfff, 0x069,
  898. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x43e,
  899. 0x0b5, 0xfff, 0x524, 0x2d2, 0xfff, 0xfff, 0xfff, 0x28f,
  900. 0xfff, 0x01b, 0x50e, 0xfff, 0xfff, 0x1bb, 0xfff, 0xfff,
  901. 0x41d, 0xfff, 0x32e, 0x48e, 0xfff, 0x1f7, 0x224, 0xfff,
  902. 0xfff, 0xfff, 0xfff, 0xfff, 0x394, 0xfff, 0xfff, 0xfff,
  903. 0xfff, 0x52c, 0xfff, 0xfff, 0xfff, 0x392, 0xfff, 0x1e7,
  904. 0xfff, 0xfff, 0x3f9, 0x3a7, 0xfff, 0x51f, 0xfff, 0x0bb,
  905. 0x118, 0x3ca, 0xfff, 0x1dd, 0xfff, 0x48b, 0xfff, 0xfff,
  906. 0xfff, 0xfff, 0x50f, 0xfff, 0x0d6, 0xfff, 0x1fa, 0xfff,
  907. 0x11e, 0xfff, 0xfff, 0xfff, 0xfff, 0x4d7, 0xfff, 0x078,
  908. 0x008, 0xfff, 0x25d, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  909. 0x032, 0x33c, 0xfff, 0x4d9, 0x160, 0xfff, 0xfff, 0x300,
  910. 0x0b1, 0xfff, 0x322, 0xfff, 0x4ec, 0xfff, 0xfff, 0x200,
  911. 0x00c, 0x369, 0x473, 0xfff, 0xfff, 0x32c, 0xfff, 0xfff,
  912. 0xfff, 0xfff, 0xfff, 0xfff, 0x53e, 0x3d4, 0x417, 0xfff,
  913. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  914. 0x34b, 0x001, 0x39a, 0x02c, 0xfff, 0xfff, 0x2ce, 0x00f,
  915. 0xfff, 0x0ba, 0xfff, 0xfff, 0xfff, 0xfff, 0x060, 0xfff,
  916. 0x406, 0xfff, 0xfff, 0xfff, 0x4ee, 0x4ac, 0xfff, 0x43f,
  917. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x29b, 0xfff, 0xfff,
  918. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x216,
  919. 0x190, 0xfff, 0x396, 0x464, 0xfff, 0xfff, 0x323, 0xfff,
  920. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2e9, 0xfff, 0x26d,
  921. 0x2cd, 0x040, 0xfff, 0xfff, 0xfff, 0xfff, 0x38b, 0x3c0,
  922. 0xfff, 0xfff, 0xfff, 0x1f2, 0xfff, 0x0ea, 0xfff, 0xfff,
  923. 0x472, 0xfff, 0x1fb, 0xfff, 0xfff, 0x0af, 0x27f, 0xfff,
  924. 0xfff, 0xfff, 0x479, 0x023, 0xfff, 0x0d8, 0x3b3, 0xfff,
  925. 0xfff, 0xfff, 0x121, 0xfff, 0xfff, 0x3bf, 0xfff, 0xfff,
  926. 0x16b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  927. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  928. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  929. 0x45a, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  930. 0xfff, 0x0be, 0xfff, 0xfff, 0xfff, 0x111, 0xfff, 0x220,
  931. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  932. 0xfff, 0xfff, 0x09b, 0x218, 0xfff, 0x022, 0x202, 0xfff,
  933. 0x4c8, 0xfff, 0x0ed, 0xfff, 0xfff, 0x182, 0xfff, 0xfff,
  934. 0xfff, 0x17f, 0x213, 0xfff, 0x321, 0x36a, 0xfff, 0x086,
  935. 0xfff, 0xfff, 0xfff, 0x43b, 0x088, 0xfff, 0xfff, 0xfff,
  936. 0xfff, 0x26c, 0xfff, 0x2f8, 0x3b4, 0xfff, 0xfff, 0xfff,
  937. 0x132, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x333, 0x444,
  938. 0x0c1, 0x4d8, 0x46d, 0x264, 0xfff, 0xfff, 0xfff, 0xfff,
  939. 0x426, 0xfff, 0xfff, 0xfff, 0xfff, 0x2fe, 0xfff, 0xfff,
  940. 0xfff, 0xfff, 0x011, 0xfff, 0x05f, 0xfff, 0xfff, 0xfff,
  941. 0xfff, 0x10c, 0x101, 0xfff, 0xfff, 0xfff, 0xfff, 0x110,
  942. 0xfff, 0x044, 0x304, 0x361, 0x404, 0xfff, 0x51b, 0x099,
  943. 0xfff, 0x440, 0xfff, 0xfff, 0xfff, 0x222, 0xfff, 0xfff,
  944. 0xfff, 0xfff, 0x1b5, 0xfff, 0x136, 0x430, 0xfff, 0x1da,
  945. 0xfff, 0xfff, 0xfff, 0x043, 0xfff, 0x17c, 0xfff, 0xfff,
  946. 0xfff, 0x01c, 0xfff, 0xfff, 0xfff, 0x425, 0x236, 0xfff,
  947. 0x317, 0xfff, 0xfff, 0x437, 0x3fc, 0xfff, 0x1f1, 0xfff,
  948. 0x324, 0xfff, 0xfff, 0x0ca, 0x306, 0xfff, 0x548, 0xfff,
  949. 0x46e, 0xfff, 0xfff, 0xfff, 0x4b8, 0x1c2, 0x286, 0xfff,
  950. 0xfff, 0x087, 0x18a, 0x19f, 0xfff, 0xfff, 0xfff, 0xfff,
  951. 0x18c, 0xfff, 0x215, 0xfff, 0xfff, 0xfff, 0xfff, 0x283,
  952. 0xfff, 0xfff, 0xfff, 0x126, 0xfff, 0xfff, 0x370, 0xfff,
  953. 0x53f, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x31c, 0xfff,
  954. 0x4d1, 0xfff, 0xfff, 0xfff, 0x021, 0xfff, 0x157, 0xfff,
  955. 0xfff, 0x028, 0x16e, 0xfff, 0x421, 0xfff, 0x1c6, 0xfff,
  956. 0xfff, 0x511, 0xfff, 0xfff, 0x39c, 0x46f, 0x1b2, 0xfff,
  957. 0xfff, 0x316, 0xfff, 0xfff, 0x009, 0xfff, 0xfff, 0x195,
  958. 0xfff, 0x240, 0x546, 0xfff, 0xfff, 0x520, 0xfff, 0xfff,
  959. 0xfff, 0xfff, 0xfff, 0xfff, 0x454, 0xfff, 0xfff, 0xfff,
  960. 0x3f3, 0xfff, 0xfff, 0x187, 0xfff, 0x4a9, 0xfff, 0xfff,
  961. 0xfff, 0xfff, 0xfff, 0xfff, 0x51c, 0x453, 0x1e6, 0xfff,
  962. 0xfff, 0xfff, 0x1b0, 0xfff, 0x477, 0xfff, 0xfff, 0xfff,
  963. 0x4fe, 0xfff, 0x32f, 0xfff, 0xfff, 0x15e, 0x1d4, 0xfff,
  964. 0x0e5, 0xfff, 0xfff, 0xfff, 0x242, 0x14b, 0x046, 0xfff,
  965. 0x3f6, 0x3bb, 0x3e4, 0xfff, 0xfff, 0x2e3, 0xfff, 0x245,
  966. 0xfff, 0x149, 0xfff, 0xfff, 0xfff, 0x2db, 0xfff, 0xfff,
  967. 0x181, 0xfff, 0x089, 0x2c5, 0xfff, 0x1f5, 0xfff, 0x2d6,
  968. 0x507, 0xfff, 0x42d, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  969. 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  970. 0x080, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
  971. 0xfff, 0xfff, 0xfff, 0xfff, 0x3c3, 0x320, 0xfff, 0x1e1,
  972. 0xfff, 0x0f5, 0x13b, 0xfff, 0xfff, 0xfff, 0x003, 0x4da,
  973. 0xfff, 0xfff, 0xfff, 0x42c, 0xfff, 0xfff, 0x0cb, 0xfff,
  974. 0x536, 0x2c3, 0xfff, 0xfff, 0xfff, 0xfff, 0x199, 0xfff,
  975. 0xfff, 0x0c0, 0xfff, 0x01e, 0x497, 0xfff, 0xfff, 0x3e5,
  976. 0xfff, 0xfff, 0xfff, 0x0cf, 0xfff, 0x2bd, 0xfff, 0x223,
  977. 0xfff, 0x3ff, 0xfff, 0x058, 0x174, 0x3ef, 0xfff, 0x002
  978. };
  979. static unsigned short err_pos(unsigned short din)
  980. {
  981. BUG_ON(din > 4096);
  982. return err_pos_lut[din];
  983. }
  984. static int chk_no_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
  985. {
  986. if ((chk_syndrome_list[0] | chk_syndrome_list[1] |
  987. chk_syndrome_list[2] | chk_syndrome_list[3] |
  988. chk_syndrome_list[4] | chk_syndrome_list[5] |
  989. chk_syndrome_list[6] | chk_syndrome_list[7]) != 0x0) {
  990. return -EINVAL;
  991. } else {
  992. err_info[0] = 0x0;
  993. return 0;
  994. }
  995. }
  996. static int chk_1_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
  997. {
  998. unsigned short tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
  999. tmp0 = gf4096_mul(chk_syndrome_list[1], gf4096_inv(chk_syndrome_list[0]));
  1000. tmp1 = gf4096_mul(chk_syndrome_list[2], gf4096_inv(chk_syndrome_list[1]));
  1001. tmp2 = gf4096_mul(chk_syndrome_list[3], gf4096_inv(chk_syndrome_list[2]));
  1002. tmp3 = gf4096_mul(chk_syndrome_list[4], gf4096_inv(chk_syndrome_list[3]));
  1003. tmp4 = gf4096_mul(chk_syndrome_list[5], gf4096_inv(chk_syndrome_list[4]));
  1004. tmp5 = gf4096_mul(chk_syndrome_list[6], gf4096_inv(chk_syndrome_list[5]));
  1005. tmp6 = gf4096_mul(chk_syndrome_list[7], gf4096_inv(chk_syndrome_list[6]));
  1006. if ((tmp0 == tmp1) & (tmp1 == tmp2) & (tmp2 == tmp3) & (tmp3 == tmp4) & (tmp4 == tmp5) & (tmp5 == tmp6)) {
  1007. err_info[0] = 0x1; // encode 1-symbol error as 0x1
  1008. err_info[1] = err_pos(tmp0);
  1009. err_info[1] = (unsigned short)(0x55e - err_info[1]);
  1010. err_info[5] = chk_syndrome_list[0];
  1011. return 0;
  1012. } else
  1013. return -EINVAL;
  1014. }
  1015. static int chk_2_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
  1016. {
  1017. unsigned short tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  1018. unsigned short coefs[4];
  1019. unsigned short err_pats[4];
  1020. int found_num_root = 0;
  1021. unsigned short bit2_root0, bit2_root1;
  1022. unsigned short bit2_root0_inv, bit2_root1_inv;
  1023. unsigned short err_loc_eqn, test_root;
  1024. unsigned short bit2_loc0, bit2_loc1;
  1025. unsigned short bit2_pat0, bit2_pat1;
  1026. find_2x2_soln(chk_syndrome_list[1],
  1027. chk_syndrome_list[0],
  1028. chk_syndrome_list[2], chk_syndrome_list[1], chk_syndrome_list[2], chk_syndrome_list[3], coefs);
  1029. for (test_root = 0x1; test_root < 0xfff; test_root++) {
  1030. err_loc_eqn =
  1031. gf4096_mul(coefs[1], gf4096_mul(test_root, test_root)) ^ gf4096_mul(coefs[0], test_root) ^ 0x1;
  1032. if (err_loc_eqn == 0x0) {
  1033. if (found_num_root == 0) {
  1034. bit2_root0 = test_root;
  1035. found_num_root = 1;
  1036. } else if (found_num_root == 1) {
  1037. bit2_root1 = test_root;
  1038. found_num_root = 2;
  1039. break;
  1040. }
  1041. }
  1042. }
  1043. if (found_num_root != 2)
  1044. return -EINVAL;
  1045. else {
  1046. bit2_root0_inv = gf4096_inv(bit2_root0);
  1047. bit2_root1_inv = gf4096_inv(bit2_root1);
  1048. find_2bit_err_pats(chk_syndrome_list[0],
  1049. chk_syndrome_list[1], bit2_root0_inv, bit2_root1_inv, err_pats);
  1050. bit2_pat0 = err_pats[0];
  1051. bit2_pat1 = err_pats[1];
  1052. //for(x+1)
  1053. tmp0 = gf4096_mul(gf4096_mul(bit2_root0_inv, bit2_root0_inv), gf4096_mul(bit2_root0_inv, bit2_root0_inv)); //rinv0^4
  1054. tmp1 = gf4096_mul(bit2_root0_inv, tmp0); //rinv0^5
  1055. tmp2 = gf4096_mul(bit2_root0_inv, tmp1); //rinv0^6
  1056. tmp3 = gf4096_mul(bit2_root0_inv, tmp2); //rinv0^7
  1057. tmp4 = gf4096_mul(gf4096_mul(bit2_root1_inv, bit2_root1_inv), gf4096_mul(bit2_root1_inv, bit2_root1_inv)); //rinv1^4
  1058. tmp5 = gf4096_mul(bit2_root1_inv, tmp4); //rinv1^5
  1059. tmp6 = gf4096_mul(bit2_root1_inv, tmp5); //rinv1^6
  1060. tmp7 = gf4096_mul(bit2_root1_inv, tmp6); //rinv1^7
  1061. //check if only 2-bit error
  1062. if ((chk_syndrome_list[4] ==
  1063. (gf4096_mul(bit2_pat0, tmp0) ^
  1064. gf4096_mul(bit2_pat1,
  1065. tmp4))) & (chk_syndrome_list[5] ==
  1066. (gf4096_mul(bit2_pat0, tmp1) ^
  1067. gf4096_mul(bit2_pat1,
  1068. tmp5))) &
  1069. (chk_syndrome_list[6] ==
  1070. (gf4096_mul(bit2_pat0, tmp2) ^
  1071. gf4096_mul(bit2_pat1,
  1072. tmp6))) & (chk_syndrome_list[7] ==
  1073. (gf4096_mul(bit2_pat0, tmp3) ^ gf4096_mul(bit2_pat1, tmp7)))) {
  1074. if ((err_pos(bit2_root0_inv) == 0xfff) | (err_pos(bit2_root1_inv) == 0xfff)) {
  1075. return -EINVAL;
  1076. } else {
  1077. bit2_loc0 = 0x55e - err_pos(bit2_root0_inv);
  1078. bit2_loc1 = 0x55e - err_pos(bit2_root1_inv);
  1079. err_info[0] = 0x2; // encode 2-symbol error as 0x2
  1080. err_info[1] = bit2_loc0;
  1081. err_info[2] = bit2_loc1;
  1082. err_info[5] = bit2_pat0;
  1083. err_info[6] = bit2_pat1;
  1084. return 0;
  1085. }
  1086. } else
  1087. return -EINVAL;
  1088. }
  1089. }
  1090. static int chk_3_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
  1091. {
  1092. unsigned short tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  1093. unsigned short coefs[4];
  1094. unsigned short err_pats[4];
  1095. int found_num_root = 0;
  1096. unsigned short bit3_root0, bit3_root1, bit3_root2;
  1097. unsigned short bit3_root0_inv, bit3_root1_inv, bit3_root2_inv;
  1098. unsigned short err_loc_eqn, test_root;
  1099. find_3bit_err_coefs(chk_syndrome_list[0], chk_syndrome_list[1],
  1100. chk_syndrome_list[2], chk_syndrome_list[3],
  1101. chk_syndrome_list[4], chk_syndrome_list[5], coefs);
  1102. for (test_root = 0x1; test_root < 0xfff; test_root++) {
  1103. err_loc_eqn = gf4096_mul(coefs[2],
  1104. gf4096_mul(gf4096_mul(test_root, test_root),
  1105. test_root)) ^ gf4096_mul(coefs[1], gf4096_mul(test_root, test_root))
  1106. ^ gf4096_mul(coefs[0], test_root) ^ 0x1;
  1107. if (err_loc_eqn == 0x0) {
  1108. if (found_num_root == 0) {
  1109. bit3_root0 = test_root;
  1110. found_num_root = 1;
  1111. } else if (found_num_root == 1) {
  1112. bit3_root1 = test_root;
  1113. found_num_root = 2;
  1114. } else if (found_num_root == 2) {
  1115. bit3_root2 = test_root;
  1116. found_num_root = 3;
  1117. break;
  1118. }
  1119. }
  1120. }
  1121. if (found_num_root != 3)
  1122. return -EINVAL;
  1123. else {
  1124. bit3_root0_inv = gf4096_inv(bit3_root0);
  1125. bit3_root1_inv = gf4096_inv(bit3_root1);
  1126. bit3_root2_inv = gf4096_inv(bit3_root2);
  1127. find_3bit_err_pats(chk_syndrome_list[0], chk_syndrome_list[1],
  1128. chk_syndrome_list[2], bit3_root0_inv,
  1129. bit3_root1_inv, bit3_root2_inv, err_pats);
  1130. //check if only 3-bit error
  1131. tmp0 = gf4096_mul(bit3_root0_inv, bit3_root0_inv);
  1132. tmp0 = gf4096_mul(tmp0, tmp0);
  1133. tmp0 = gf4096_mul(tmp0, bit3_root0_inv);
  1134. tmp0 = gf4096_mul(tmp0, bit3_root0_inv); //rinv0^6
  1135. tmp1 = gf4096_mul(tmp0, bit3_root0_inv); //rinv0^7
  1136. tmp2 = gf4096_mul(bit3_root1_inv, bit3_root1_inv);
  1137. tmp2 = gf4096_mul(tmp2, tmp2);
  1138. tmp2 = gf4096_mul(tmp2, bit3_root1_inv);
  1139. tmp2 = gf4096_mul(tmp2, bit3_root1_inv); //rinv1^6
  1140. tmp3 = gf4096_mul(tmp2, bit3_root1_inv); //rinv1^7
  1141. tmp4 = gf4096_mul(bit3_root2_inv, bit3_root2_inv);
  1142. tmp4 = gf4096_mul(tmp4, tmp4);
  1143. tmp4 = gf4096_mul(tmp4, bit3_root2_inv);
  1144. tmp4 = gf4096_mul(tmp4, bit3_root2_inv); //rinv2^6
  1145. tmp5 = gf4096_mul(tmp4, bit3_root2_inv); //rinv2^7
  1146. //check if only 3 errors
  1147. if ((chk_syndrome_list[6] == (gf4096_mul(err_pats[0], tmp0) ^
  1148. gf4096_mul(err_pats[1], tmp2) ^
  1149. gf4096_mul(err_pats[2], tmp4))) &
  1150. (chk_syndrome_list[7] == (gf4096_mul(err_pats[0], tmp1) ^
  1151. gf4096_mul(err_pats[1], tmp3) ^ gf4096_mul(err_pats[2], tmp5)))) {
  1152. if ((err_pos(bit3_root0_inv) == 0xfff) |
  1153. (err_pos(bit3_root1_inv) == 0xfff) | (err_pos(bit3_root2_inv) == 0xfff)) {
  1154. return -EINVAL;
  1155. } else {
  1156. err_info[0] = 0x3;
  1157. err_info[1] = (0x55e - err_pos(bit3_root0_inv));
  1158. err_info[2] = (0x55e - err_pos(bit3_root1_inv));
  1159. err_info[3] = (0x55e - err_pos(bit3_root2_inv));
  1160. err_info[5] = err_pats[0];
  1161. err_info[6] = err_pats[1];
  1162. err_info[7] = err_pats[2];
  1163. return 0;
  1164. }
  1165. } else
  1166. return -EINVAL;
  1167. }
  1168. }
  1169. static int chk_4_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
  1170. {
  1171. unsigned short coefs[4];
  1172. unsigned short err_pats[4];
  1173. int found_num_root = 0;
  1174. unsigned short bit4_root0, bit4_root1, bit4_root2, bit4_root3;
  1175. unsigned short bit4_root0_inv, bit4_root1_inv, bit4_root2_inv, bit4_root3_inv;
  1176. unsigned short err_loc_eqn, test_root;
  1177. find_4bit_err_coefs(chk_syndrome_list[0],
  1178. chk_syndrome_list[1],
  1179. chk_syndrome_list[2],
  1180. chk_syndrome_list[3],
  1181. chk_syndrome_list[4],
  1182. chk_syndrome_list[5], chk_syndrome_list[6], chk_syndrome_list[7], coefs);
  1183. for (test_root = 0x1; test_root < 0xfff; test_root++) {
  1184. err_loc_eqn =
  1185. gf4096_mul(coefs[3],
  1186. gf4096_mul(gf4096_mul
  1187. (gf4096_mul(test_root, test_root),
  1188. test_root),
  1189. test_root)) ^ gf4096_mul(coefs[2],
  1190. gf4096_mul
  1191. (gf4096_mul(test_root, test_root), test_root))
  1192. ^ gf4096_mul(coefs[1], gf4096_mul(test_root, test_root)) ^ gf4096_mul(coefs[0], test_root)
  1193. ^ 0x1;
  1194. if (err_loc_eqn == 0x0) {
  1195. if (found_num_root == 0) {
  1196. bit4_root0 = test_root;
  1197. found_num_root = 1;
  1198. } else if (found_num_root == 1) {
  1199. bit4_root1 = test_root;
  1200. found_num_root = 2;
  1201. } else if (found_num_root == 2) {
  1202. bit4_root2 = test_root;
  1203. found_num_root = 3;
  1204. } else {
  1205. found_num_root = 4;
  1206. bit4_root3 = test_root;
  1207. break;
  1208. }
  1209. }
  1210. }
  1211. if (found_num_root != 4) {
  1212. return -EINVAL;
  1213. } else {
  1214. bit4_root0_inv = gf4096_inv(bit4_root0);
  1215. bit4_root1_inv = gf4096_inv(bit4_root1);
  1216. bit4_root2_inv = gf4096_inv(bit4_root2);
  1217. bit4_root3_inv = gf4096_inv(bit4_root3);
  1218. find_4bit_err_pats(chk_syndrome_list[0],
  1219. chk_syndrome_list[1],
  1220. chk_syndrome_list[2],
  1221. chk_syndrome_list[3],
  1222. bit4_root0_inv, bit4_root1_inv, bit4_root2_inv, bit4_root3_inv, err_pats);
  1223. err_info[0] = 0x4;
  1224. err_info[1] = (0x55e - err_pos(bit4_root0_inv));
  1225. err_info[2] = (0x55e - err_pos(bit4_root1_inv));
  1226. err_info[3] = (0x55e - err_pos(bit4_root2_inv));
  1227. err_info[4] = (0x55e - err_pos(bit4_root3_inv));
  1228. err_info[5] = err_pats[0];
  1229. err_info[6] = err_pats[1];
  1230. err_info[7] = err_pats[2];
  1231. err_info[8] = err_pats[3];
  1232. return 0;
  1233. }
  1234. }
  1235. void correct_12bit_symbol(unsigned char *buf, unsigned short sym,
  1236. unsigned short val)
  1237. {
  1238. if (unlikely(sym > 1366)) {
  1239. printk(KERN_ERR "Error: symbol %d out of range; cannot correct\n", sym);
  1240. } else if (sym == 0) {
  1241. buf[0] ^= val;
  1242. } else if (sym & 1) {
  1243. buf[1+(3*(sym-1))/2] ^= (val >> 4);
  1244. buf[2+(3*(sym-1))/2] ^= ((val & 0xf) << 4);
  1245. } else {
  1246. buf[2+(3*(sym-2))/2] ^= (val >> 8);
  1247. buf[3+(3*(sym-2))/2] ^= (val & 0xff);
  1248. }
  1249. }
  1250. static int debugecc = 0;
  1251. module_param(debugecc, int, 0644);
  1252. int cafe_correct_ecc(unsigned char *buf,
  1253. unsigned short *chk_syndrome_list)
  1254. {
  1255. unsigned short err_info[9];
  1256. int i;
  1257. if (debugecc) {
  1258. printk(KERN_WARNING "cafe_correct_ecc invoked. Syndromes %x %x %x %x %x %x %x %x\n",
  1259. chk_syndrome_list[0], chk_syndrome_list[1],
  1260. chk_syndrome_list[2], chk_syndrome_list[3],
  1261. chk_syndrome_list[4], chk_syndrome_list[5],
  1262. chk_syndrome_list[6], chk_syndrome_list[7]);
  1263. for (i=0; i < 2048; i+=16) {
  1264. printk(KERN_WARNING "D %04x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  1265. i,
  1266. buf[i], buf[i+1], buf[i+2], buf[i+3],
  1267. buf[i+4], buf[i+5], buf[i+6], buf[i+7],
  1268. buf[i+8], buf[i+9], buf[i+10], buf[i+11],
  1269. buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
  1270. }
  1271. for ( ; i < 2112; i+=16) {
  1272. printk(KERN_WARNING "O %02x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  1273. i - 2048,
  1274. buf[i], buf[i+1], buf[i+2], buf[i+3],
  1275. buf[i+4], buf[i+5], buf[i+6], buf[i+7],
  1276. buf[i+8], buf[i+9], buf[i+10], buf[i+11],
  1277. buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
  1278. }
  1279. }
  1280. if (chk_no_err_only(chk_syndrome_list, err_info) &&
  1281. chk_1_err_only(chk_syndrome_list, err_info) &&
  1282. chk_2_err_only(chk_syndrome_list, err_info) &&
  1283. chk_3_err_only(chk_syndrome_list, err_info) &&
  1284. chk_4_err_only(chk_syndrome_list, err_info)) {
  1285. return -EIO;
  1286. }
  1287. for (i=0; i < err_info[0]; i++) {
  1288. if (debugecc)
  1289. printk(KERN_WARNING "Correct symbol %d with 0x%03x\n",
  1290. err_info[1+i], err_info[5+i]);
  1291. correct_12bit_symbol(buf, err_info[1+i], err_info[5+i]);
  1292. }
  1293. return err_info[0];
  1294. }