e752x_edac.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485
  1. /*
  2. * Intel e752x Memory Controller kernel module
  3. * (C) 2004 Linux Networx (http://lnxi.com)
  4. * This file may be distributed under the terms of the
  5. * GNU General Public License.
  6. *
  7. * Implement support for the e7520, E7525, e7320 and i3100 memory controllers.
  8. *
  9. * Datasheets:
  10. * http://www.intel.in/content/www/in/en/chipsets/e7525-memory-controller-hub-datasheet.html
  11. * ftp://download.intel.com/design/intarch/datashts/31345803.pdf
  12. *
  13. * Written by Tom Zimmerman
  14. *
  15. * Contributors:
  16. * Thayne Harbaugh at realmsys.com (?)
  17. * Wang Zhenyu at intel.com
  18. * Dave Jiang at mvista.com
  19. *
  20. */
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/pci.h>
  24. #include <linux/pci_ids.h>
  25. #include <linux/edac.h>
  26. #include "edac_core.h"
  27. #define E752X_REVISION " Ver: 2.0.2"
  28. #define EDAC_MOD_STR "e752x_edac"
  29. static int report_non_memory_errors;
  30. static int force_function_unhide;
  31. static int sysbus_parity = -1;
  32. static struct edac_pci_ctl_info *e752x_pci;
  33. #define e752x_printk(level, fmt, arg...) \
  34. edac_printk(level, "e752x", fmt, ##arg)
  35. #define e752x_mc_printk(mci, level, fmt, arg...) \
  36. edac_mc_chipset_printk(mci, level, "e752x", fmt, ##arg)
  37. #ifndef PCI_DEVICE_ID_INTEL_7520_0
  38. #define PCI_DEVICE_ID_INTEL_7520_0 0x3590
  39. #endif /* PCI_DEVICE_ID_INTEL_7520_0 */
  40. #ifndef PCI_DEVICE_ID_INTEL_7520_1_ERR
  41. #define PCI_DEVICE_ID_INTEL_7520_1_ERR 0x3591
  42. #endif /* PCI_DEVICE_ID_INTEL_7520_1_ERR */
  43. #ifndef PCI_DEVICE_ID_INTEL_7525_0
  44. #define PCI_DEVICE_ID_INTEL_7525_0 0x359E
  45. #endif /* PCI_DEVICE_ID_INTEL_7525_0 */
  46. #ifndef PCI_DEVICE_ID_INTEL_7525_1_ERR
  47. #define PCI_DEVICE_ID_INTEL_7525_1_ERR 0x3593
  48. #endif /* PCI_DEVICE_ID_INTEL_7525_1_ERR */
  49. #ifndef PCI_DEVICE_ID_INTEL_7320_0
  50. #define PCI_DEVICE_ID_INTEL_7320_0 0x3592
  51. #endif /* PCI_DEVICE_ID_INTEL_7320_0 */
  52. #ifndef PCI_DEVICE_ID_INTEL_7320_1_ERR
  53. #define PCI_DEVICE_ID_INTEL_7320_1_ERR 0x3593
  54. #endif /* PCI_DEVICE_ID_INTEL_7320_1_ERR */
  55. #ifndef PCI_DEVICE_ID_INTEL_3100_0
  56. #define PCI_DEVICE_ID_INTEL_3100_0 0x35B0
  57. #endif /* PCI_DEVICE_ID_INTEL_3100_0 */
  58. #ifndef PCI_DEVICE_ID_INTEL_3100_1_ERR
  59. #define PCI_DEVICE_ID_INTEL_3100_1_ERR 0x35B1
  60. #endif /* PCI_DEVICE_ID_INTEL_3100_1_ERR */
  61. #define E752X_NR_CSROWS 8 /* number of csrows */
  62. /* E752X register addresses - device 0 function 0 */
  63. #define E752X_MCHSCRB 0x52 /* Memory Scrub register (16b) */
  64. /*
  65. * 6:5 Scrub Completion Count
  66. * 3:2 Scrub Rate (i3100 only)
  67. * 01=fast 10=normal
  68. * 1:0 Scrub Mode enable
  69. * 00=off 10=on
  70. */
  71. #define E752X_DRB 0x60 /* DRAM row boundary register (8b) */
  72. #define E752X_DRA 0x70 /* DRAM row attribute register (8b) */
  73. /*
  74. * 31:30 Device width row 7
  75. * 01=x8 10=x4 11=x8 DDR2
  76. * 27:26 Device width row 6
  77. * 23:22 Device width row 5
  78. * 19:20 Device width row 4
  79. * 15:14 Device width row 3
  80. * 11:10 Device width row 2
  81. * 7:6 Device width row 1
  82. * 3:2 Device width row 0
  83. */
  84. #define E752X_DRC 0x7C /* DRAM controller mode reg (32b) */
  85. /* FIXME:IS THIS RIGHT? */
  86. /*
  87. * 22 Number channels 0=1,1=2
  88. * 19:18 DRB Granularity 32/64MB
  89. */
  90. #define E752X_DRM 0x80 /* Dimm mapping register */
  91. #define E752X_DDRCSR 0x9A /* DDR control and status reg (16b) */
  92. /*
  93. * 14:12 1 single A, 2 single B, 3 dual
  94. */
  95. #define E752X_TOLM 0xC4 /* DRAM top of low memory reg (16b) */
  96. #define E752X_REMAPBASE 0xC6 /* DRAM remap base address reg (16b) */
  97. #define E752X_REMAPLIMIT 0xC8 /* DRAM remap limit address reg (16b) */
  98. #define E752X_REMAPOFFSET 0xCA /* DRAM remap limit offset reg (16b) */
  99. /* E752X register addresses - device 0 function 1 */
  100. #define E752X_FERR_GLOBAL 0x40 /* Global first error register (32b) */
  101. #define E752X_NERR_GLOBAL 0x44 /* Global next error register (32b) */
  102. #define E752X_HI_FERR 0x50 /* Hub interface first error reg (8b) */
  103. #define E752X_HI_NERR 0x52 /* Hub interface next error reg (8b) */
  104. #define E752X_HI_ERRMASK 0x54 /* Hub interface error mask reg (8b) */
  105. #define E752X_HI_SMICMD 0x5A /* Hub interface SMI command reg (8b) */
  106. #define E752X_SYSBUS_FERR 0x60 /* System buss first error reg (16b) */
  107. #define E752X_SYSBUS_NERR 0x62 /* System buss next error reg (16b) */
  108. #define E752X_SYSBUS_ERRMASK 0x64 /* System buss error mask reg (16b) */
  109. #define E752X_SYSBUS_SMICMD 0x6A /* System buss SMI command reg (16b) */
  110. #define E752X_BUF_FERR 0x70 /* Memory buffer first error reg (8b) */
  111. #define E752X_BUF_NERR 0x72 /* Memory buffer next error reg (8b) */
  112. #define E752X_BUF_ERRMASK 0x74 /* Memory buffer error mask reg (8b) */
  113. #define E752X_BUF_SMICMD 0x7A /* Memory buffer SMI cmd reg (8b) */
  114. #define E752X_DRAM_FERR 0x80 /* DRAM first error register (16b) */
  115. #define E752X_DRAM_NERR 0x82 /* DRAM next error register (16b) */
  116. #define E752X_DRAM_ERRMASK 0x84 /* DRAM error mask register (8b) */
  117. #define E752X_DRAM_SMICMD 0x8A /* DRAM SMI command register (8b) */
  118. #define E752X_DRAM_RETR_ADD 0xAC /* DRAM Retry address register (32b) */
  119. #define E752X_DRAM_SEC1_ADD 0xA0 /* DRAM first correctable memory */
  120. /* error address register (32b) */
  121. /*
  122. * 31 Reserved
  123. * 30:2 CE address (64 byte block 34:6
  124. * 1 Reserved
  125. * 0 HiLoCS
  126. */
  127. #define E752X_DRAM_SEC2_ADD 0xC8 /* DRAM first correctable memory */
  128. /* error address register (32b) */
  129. /*
  130. * 31 Reserved
  131. * 30:2 CE address (64 byte block 34:6)
  132. * 1 Reserved
  133. * 0 HiLoCS
  134. */
  135. #define E752X_DRAM_DED_ADD 0xA4 /* DRAM first uncorrectable memory */
  136. /* error address register (32b) */
  137. /*
  138. * 31 Reserved
  139. * 30:2 CE address (64 byte block 34:6)
  140. * 1 Reserved
  141. * 0 HiLoCS
  142. */
  143. #define E752X_DRAM_SCRB_ADD 0xA8 /* DRAM 1st uncorrectable scrub mem */
  144. /* error address register (32b) */
  145. /*
  146. * 31 Reserved
  147. * 30:2 CE address (64 byte block 34:6
  148. * 1 Reserved
  149. * 0 HiLoCS
  150. */
  151. #define E752X_DRAM_SEC1_SYNDROME 0xC4 /* DRAM first correctable memory */
  152. /* error syndrome register (16b) */
  153. #define E752X_DRAM_SEC2_SYNDROME 0xC6 /* DRAM second correctable memory */
  154. /* error syndrome register (16b) */
  155. #define E752X_DEVPRES1 0xF4 /* Device Present 1 register (8b) */
  156. /* 3100 IMCH specific register addresses - device 0 function 1 */
  157. #define I3100_NSI_FERR 0x48 /* NSI first error reg (32b) */
  158. #define I3100_NSI_NERR 0x4C /* NSI next error reg (32b) */
  159. #define I3100_NSI_SMICMD 0x54 /* NSI SMI command register (32b) */
  160. #define I3100_NSI_EMASK 0x90 /* NSI error mask register (32b) */
  161. /* ICH5R register addresses - device 30 function 0 */
  162. #define ICH5R_PCI_STAT 0x06 /* PCI status register (16b) */
  163. #define ICH5R_PCI_2ND_STAT 0x1E /* PCI status secondary reg (16b) */
  164. #define ICH5R_PCI_BRIDGE_CTL 0x3E /* PCI bridge control register (16b) */
  165. enum e752x_chips {
  166. E7520 = 0,
  167. E7525 = 1,
  168. E7320 = 2,
  169. I3100 = 3
  170. };
  171. /*
  172. * Those chips Support single-rank and dual-rank memories only.
  173. *
  174. * On e752x chips, the odd rows are present only on dual-rank memories.
  175. * Dividing the rank by two will provide the dimm#
  176. *
  177. * i3100 MC has a different mapping: it supports only 4 ranks.
  178. *
  179. * The mapping is (from 1 to n):
  180. * slot single-ranked double-ranked
  181. * dimm #1 -> rank #4 NA
  182. * dimm #2 -> rank #3 NA
  183. * dimm #3 -> rank #2 Ranks 2 and 3
  184. * dimm #4 -> rank $1 Ranks 1 and 4
  185. *
  186. * FIXME: The current mapping for i3100 considers that it supports up to 8
  187. * ranks/chanel, but datasheet says that the MC supports only 4 ranks.
  188. */
  189. struct e752x_pvt {
  190. struct pci_dev *dev_d0f0;
  191. struct pci_dev *dev_d0f1;
  192. u32 tolm;
  193. u32 remapbase;
  194. u32 remaplimit;
  195. int mc_symmetric;
  196. u8 map[8];
  197. int map_type;
  198. const struct e752x_dev_info *dev_info;
  199. };
  200. struct e752x_dev_info {
  201. u16 err_dev;
  202. u16 ctl_dev;
  203. const char *ctl_name;
  204. };
  205. struct e752x_error_info {
  206. u32 ferr_global;
  207. u32 nerr_global;
  208. u32 nsi_ferr; /* 3100 only */
  209. u32 nsi_nerr; /* 3100 only */
  210. u8 hi_ferr; /* all but 3100 */
  211. u8 hi_nerr; /* all but 3100 */
  212. u16 sysbus_ferr;
  213. u16 sysbus_nerr;
  214. u8 buf_ferr;
  215. u8 buf_nerr;
  216. u16 dram_ferr;
  217. u16 dram_nerr;
  218. u32 dram_sec1_add;
  219. u32 dram_sec2_add;
  220. u16 dram_sec1_syndrome;
  221. u16 dram_sec2_syndrome;
  222. u32 dram_ded_add;
  223. u32 dram_scrb_add;
  224. u32 dram_retr_add;
  225. };
  226. static const struct e752x_dev_info e752x_devs[] = {
  227. [E7520] = {
  228. .err_dev = PCI_DEVICE_ID_INTEL_7520_1_ERR,
  229. .ctl_dev = PCI_DEVICE_ID_INTEL_7520_0,
  230. .ctl_name = "E7520"},
  231. [E7525] = {
  232. .err_dev = PCI_DEVICE_ID_INTEL_7525_1_ERR,
  233. .ctl_dev = PCI_DEVICE_ID_INTEL_7525_0,
  234. .ctl_name = "E7525"},
  235. [E7320] = {
  236. .err_dev = PCI_DEVICE_ID_INTEL_7320_1_ERR,
  237. .ctl_dev = PCI_DEVICE_ID_INTEL_7320_0,
  238. .ctl_name = "E7320"},
  239. [I3100] = {
  240. .err_dev = PCI_DEVICE_ID_INTEL_3100_1_ERR,
  241. .ctl_dev = PCI_DEVICE_ID_INTEL_3100_0,
  242. .ctl_name = "3100"},
  243. };
  244. /* Valid scrub rates for the e752x/3100 hardware memory scrubber. We
  245. * map the scrubbing bandwidth to a hardware register value. The 'set'
  246. * operation finds the 'matching or higher value'. Note that scrubbing
  247. * on the e752x can only be enabled/disabled. The 3100 supports
  248. * a normal and fast mode.
  249. */
  250. #define SDRATE_EOT 0xFFFFFFFF
  251. struct scrubrate {
  252. u32 bandwidth; /* bandwidth consumed by scrubbing in bytes/sec */
  253. u16 scrubval; /* register value for scrub rate */
  254. };
  255. /* Rate below assumes same performance as i3100 using PC3200 DDR2 in
  256. * normal mode. e752x bridges don't support choosing normal or fast mode,
  257. * so the scrubbing bandwidth value isn't all that important - scrubbing is
  258. * either on or off.
  259. */
  260. static const struct scrubrate scrubrates_e752x[] = {
  261. {0, 0x00}, /* Scrubbing Off */
  262. {500000, 0x02}, /* Scrubbing On */
  263. {SDRATE_EOT, 0x00} /* End of Table */
  264. };
  265. /* Fast mode: 2 GByte PC3200 DDR2 scrubbed in 33s = 63161283 bytes/s
  266. * Normal mode: 125 (32000 / 256) times slower than fast mode.
  267. */
  268. static const struct scrubrate scrubrates_i3100[] = {
  269. {0, 0x00}, /* Scrubbing Off */
  270. {500000, 0x0a}, /* Normal mode - 32k clocks */
  271. {62500000, 0x06}, /* Fast mode - 256 clocks */
  272. {SDRATE_EOT, 0x00} /* End of Table */
  273. };
  274. static unsigned long ctl_page_to_phys(struct mem_ctl_info *mci,
  275. unsigned long page)
  276. {
  277. u32 remap;
  278. struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
  279. edac_dbg(3, "\n");
  280. if (page < pvt->tolm)
  281. return page;
  282. if ((page >= 0x100000) && (page < pvt->remapbase))
  283. return page;
  284. remap = (page - pvt->tolm) + pvt->remapbase;
  285. if (remap < pvt->remaplimit)
  286. return remap;
  287. e752x_printk(KERN_ERR, "Invalid page %lx - out of range\n", page);
  288. return pvt->tolm - 1;
  289. }
  290. static void do_process_ce(struct mem_ctl_info *mci, u16 error_one,
  291. u32 sec1_add, u16 sec1_syndrome)
  292. {
  293. u32 page;
  294. int row;
  295. int channel;
  296. int i;
  297. struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
  298. edac_dbg(3, "\n");
  299. /* convert the addr to 4k page */
  300. page = sec1_add >> (PAGE_SHIFT - 4);
  301. /* FIXME - check for -1 */
  302. if (pvt->mc_symmetric) {
  303. /* chip select are bits 14 & 13 */
  304. row = ((page >> 1) & 3);
  305. e752x_printk(KERN_WARNING,
  306. "Test row %d Table %d %d %d %d %d %d %d %d\n", row,
  307. pvt->map[0], pvt->map[1], pvt->map[2], pvt->map[3],
  308. pvt->map[4], pvt->map[5], pvt->map[6],
  309. pvt->map[7]);
  310. /* test for channel remapping */
  311. for (i = 0; i < 8; i++) {
  312. if (pvt->map[i] == row)
  313. break;
  314. }
  315. e752x_printk(KERN_WARNING, "Test computed row %d\n", i);
  316. if (i < 8)
  317. row = i;
  318. else
  319. e752x_mc_printk(mci, KERN_WARNING,
  320. "row %d not found in remap table\n",
  321. row);
  322. } else
  323. row = edac_mc_find_csrow_by_page(mci, page);
  324. /* 0 = channel A, 1 = channel B */
  325. channel = !(error_one & 1);
  326. /* e752x mc reads 34:6 of the DRAM linear address */
  327. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
  328. page, offset_in_page(sec1_add << 4), sec1_syndrome,
  329. row, channel, -1,
  330. "e752x CE", "");
  331. }
  332. static inline void process_ce(struct mem_ctl_info *mci, u16 error_one,
  333. u32 sec1_add, u16 sec1_syndrome, int *error_found,
  334. int handle_error)
  335. {
  336. *error_found = 1;
  337. if (handle_error)
  338. do_process_ce(mci, error_one, sec1_add, sec1_syndrome);
  339. }
  340. static void do_process_ue(struct mem_ctl_info *mci, u16 error_one,
  341. u32 ded_add, u32 scrb_add)
  342. {
  343. u32 error_2b, block_page;
  344. int row;
  345. struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
  346. edac_dbg(3, "\n");
  347. if (error_one & 0x0202) {
  348. error_2b = ded_add;
  349. /* convert to 4k address */
  350. block_page = error_2b >> (PAGE_SHIFT - 4);
  351. row = pvt->mc_symmetric ?
  352. /* chip select are bits 14 & 13 */
  353. ((block_page >> 1) & 3) :
  354. edac_mc_find_csrow_by_page(mci, block_page);
  355. /* e752x mc reads 34:6 of the DRAM linear address */
  356. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
  357. block_page,
  358. offset_in_page(error_2b << 4), 0,
  359. row, -1, -1,
  360. "e752x UE from Read", "");
  361. }
  362. if (error_one & 0x0404) {
  363. error_2b = scrb_add;
  364. /* convert to 4k address */
  365. block_page = error_2b >> (PAGE_SHIFT - 4);
  366. row = pvt->mc_symmetric ?
  367. /* chip select are bits 14 & 13 */
  368. ((block_page >> 1) & 3) :
  369. edac_mc_find_csrow_by_page(mci, block_page);
  370. /* e752x mc reads 34:6 of the DRAM linear address */
  371. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
  372. block_page,
  373. offset_in_page(error_2b << 4), 0,
  374. row, -1, -1,
  375. "e752x UE from Scruber", "");
  376. }
  377. }
  378. static inline void process_ue(struct mem_ctl_info *mci, u16 error_one,
  379. u32 ded_add, u32 scrb_add, int *error_found,
  380. int handle_error)
  381. {
  382. *error_found = 1;
  383. if (handle_error)
  384. do_process_ue(mci, error_one, ded_add, scrb_add);
  385. }
  386. static inline void process_ue_no_info_wr(struct mem_ctl_info *mci,
  387. int *error_found, int handle_error)
  388. {
  389. *error_found = 1;
  390. if (!handle_error)
  391. return;
  392. edac_dbg(3, "\n");
  393. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 0, 0, 0,
  394. -1, -1, -1,
  395. "e752x UE log memory write", "");
  396. }
  397. static void do_process_ded_retry(struct mem_ctl_info *mci, u16 error,
  398. u32 retry_add)
  399. {
  400. u32 error_1b, page;
  401. int row;
  402. struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
  403. error_1b = retry_add;
  404. page = error_1b >> (PAGE_SHIFT - 4); /* convert the addr to 4k page */
  405. /* chip select are bits 14 & 13 */
  406. row = pvt->mc_symmetric ? ((page >> 1) & 3) :
  407. edac_mc_find_csrow_by_page(mci, page);
  408. e752x_mc_printk(mci, KERN_WARNING,
  409. "CE page 0x%lx, row %d : Memory read retry\n",
  410. (long unsigned int)page, row);
  411. }
  412. static inline void process_ded_retry(struct mem_ctl_info *mci, u16 error,
  413. u32 retry_add, int *error_found,
  414. int handle_error)
  415. {
  416. *error_found = 1;
  417. if (handle_error)
  418. do_process_ded_retry(mci, error, retry_add);
  419. }
  420. static inline void process_threshold_ce(struct mem_ctl_info *mci, u16 error,
  421. int *error_found, int handle_error)
  422. {
  423. *error_found = 1;
  424. if (handle_error)
  425. e752x_mc_printk(mci, KERN_WARNING, "Memory threshold CE\n");
  426. }
  427. static char *global_message[11] = {
  428. "PCI Express C1",
  429. "PCI Express C",
  430. "PCI Express B1",
  431. "PCI Express B",
  432. "PCI Express A1",
  433. "PCI Express A",
  434. "DMA Controller",
  435. "HUB or NS Interface",
  436. "System Bus",
  437. "DRAM Controller", /* 9th entry */
  438. "Internal Buffer"
  439. };
  440. #define DRAM_ENTRY 9
  441. static char *fatal_message[2] = { "Non-Fatal ", "Fatal " };
  442. static void do_global_error(int fatal, u32 errors)
  443. {
  444. int i;
  445. for (i = 0; i < 11; i++) {
  446. if (errors & (1 << i)) {
  447. /* If the error is from DRAM Controller OR
  448. * we are to report ALL errors, then
  449. * report the error
  450. */
  451. if ((i == DRAM_ENTRY) || report_non_memory_errors)
  452. e752x_printk(KERN_WARNING, "%sError %s\n",
  453. fatal_message[fatal],
  454. global_message[i]);
  455. }
  456. }
  457. }
  458. static inline void global_error(int fatal, u32 errors, int *error_found,
  459. int handle_error)
  460. {
  461. *error_found = 1;
  462. if (handle_error)
  463. do_global_error(fatal, errors);
  464. }
  465. static char *hub_message[7] = {
  466. "HI Address or Command Parity", "HI Illegal Access",
  467. "HI Internal Parity", "Out of Range Access",
  468. "HI Data Parity", "Enhanced Config Access",
  469. "Hub Interface Target Abort"
  470. };
  471. static void do_hub_error(int fatal, u8 errors)
  472. {
  473. int i;
  474. for (i = 0; i < 7; i++) {
  475. if (errors & (1 << i))
  476. e752x_printk(KERN_WARNING, "%sError %s\n",
  477. fatal_message[fatal], hub_message[i]);
  478. }
  479. }
  480. static inline void hub_error(int fatal, u8 errors, int *error_found,
  481. int handle_error)
  482. {
  483. *error_found = 1;
  484. if (handle_error)
  485. do_hub_error(fatal, errors);
  486. }
  487. #define NSI_FATAL_MASK 0x0c080081
  488. #define NSI_NON_FATAL_MASK 0x23a0ba64
  489. #define NSI_ERR_MASK (NSI_FATAL_MASK | NSI_NON_FATAL_MASK)
  490. static char *nsi_message[30] = {
  491. "NSI Link Down", /* NSI_FERR/NSI_NERR bit 0, fatal error */
  492. "", /* reserved */
  493. "NSI Parity Error", /* bit 2, non-fatal */
  494. "", /* reserved */
  495. "", /* reserved */
  496. "Correctable Error Message", /* bit 5, non-fatal */
  497. "Non-Fatal Error Message", /* bit 6, non-fatal */
  498. "Fatal Error Message", /* bit 7, fatal */
  499. "", /* reserved */
  500. "Receiver Error", /* bit 9, non-fatal */
  501. "", /* reserved */
  502. "Bad TLP", /* bit 11, non-fatal */
  503. "Bad DLLP", /* bit 12, non-fatal */
  504. "REPLAY_NUM Rollover", /* bit 13, non-fatal */
  505. "", /* reserved */
  506. "Replay Timer Timeout", /* bit 15, non-fatal */
  507. "", /* reserved */
  508. "", /* reserved */
  509. "", /* reserved */
  510. "Data Link Protocol Error", /* bit 19, fatal */
  511. "", /* reserved */
  512. "Poisoned TLP", /* bit 21, non-fatal */
  513. "", /* reserved */
  514. "Completion Timeout", /* bit 23, non-fatal */
  515. "Completer Abort", /* bit 24, non-fatal */
  516. "Unexpected Completion", /* bit 25, non-fatal */
  517. "Receiver Overflow", /* bit 26, fatal */
  518. "Malformed TLP", /* bit 27, fatal */
  519. "", /* reserved */
  520. "Unsupported Request" /* bit 29, non-fatal */
  521. };
  522. static void do_nsi_error(int fatal, u32 errors)
  523. {
  524. int i;
  525. for (i = 0; i < 30; i++) {
  526. if (errors & (1 << i))
  527. printk(KERN_WARNING "%sError %s\n",
  528. fatal_message[fatal], nsi_message[i]);
  529. }
  530. }
  531. static inline void nsi_error(int fatal, u32 errors, int *error_found,
  532. int handle_error)
  533. {
  534. *error_found = 1;
  535. if (handle_error)
  536. do_nsi_error(fatal, errors);
  537. }
  538. static char *membuf_message[4] = {
  539. "Internal PMWB to DRAM parity",
  540. "Internal PMWB to System Bus Parity",
  541. "Internal System Bus or IO to PMWB Parity",
  542. "Internal DRAM to PMWB Parity"
  543. };
  544. static void do_membuf_error(u8 errors)
  545. {
  546. int i;
  547. for (i = 0; i < 4; i++) {
  548. if (errors & (1 << i))
  549. e752x_printk(KERN_WARNING, "Non-Fatal Error %s\n",
  550. membuf_message[i]);
  551. }
  552. }
  553. static inline void membuf_error(u8 errors, int *error_found, int handle_error)
  554. {
  555. *error_found = 1;
  556. if (handle_error)
  557. do_membuf_error(errors);
  558. }
  559. static char *sysbus_message[10] = {
  560. "Addr or Request Parity",
  561. "Data Strobe Glitch",
  562. "Addr Strobe Glitch",
  563. "Data Parity",
  564. "Addr Above TOM",
  565. "Non DRAM Lock Error",
  566. "MCERR", "BINIT",
  567. "Memory Parity",
  568. "IO Subsystem Parity"
  569. };
  570. static void do_sysbus_error(int fatal, u32 errors)
  571. {
  572. int i;
  573. for (i = 0; i < 10; i++) {
  574. if (errors & (1 << i))
  575. e752x_printk(KERN_WARNING, "%sError System Bus %s\n",
  576. fatal_message[fatal], sysbus_message[i]);
  577. }
  578. }
  579. static inline void sysbus_error(int fatal, u32 errors, int *error_found,
  580. int handle_error)
  581. {
  582. *error_found = 1;
  583. if (handle_error)
  584. do_sysbus_error(fatal, errors);
  585. }
  586. static void e752x_check_hub_interface(struct e752x_error_info *info,
  587. int *error_found, int handle_error)
  588. {
  589. u8 stat8;
  590. //pci_read_config_byte(dev,E752X_HI_FERR,&stat8);
  591. stat8 = info->hi_ferr;
  592. if (stat8 & 0x7f) { /* Error, so process */
  593. stat8 &= 0x7f;
  594. if (stat8 & 0x2b)
  595. hub_error(1, stat8 & 0x2b, error_found, handle_error);
  596. if (stat8 & 0x54)
  597. hub_error(0, stat8 & 0x54, error_found, handle_error);
  598. }
  599. //pci_read_config_byte(dev,E752X_HI_NERR,&stat8);
  600. stat8 = info->hi_nerr;
  601. if (stat8 & 0x7f) { /* Error, so process */
  602. stat8 &= 0x7f;
  603. if (stat8 & 0x2b)
  604. hub_error(1, stat8 & 0x2b, error_found, handle_error);
  605. if (stat8 & 0x54)
  606. hub_error(0, stat8 & 0x54, error_found, handle_error);
  607. }
  608. }
  609. static void e752x_check_ns_interface(struct e752x_error_info *info,
  610. int *error_found, int handle_error)
  611. {
  612. u32 stat32;
  613. stat32 = info->nsi_ferr;
  614. if (stat32 & NSI_ERR_MASK) { /* Error, so process */
  615. if (stat32 & NSI_FATAL_MASK) /* check for fatal errors */
  616. nsi_error(1, stat32 & NSI_FATAL_MASK, error_found,
  617. handle_error);
  618. if (stat32 & NSI_NON_FATAL_MASK) /* check for non-fatal ones */
  619. nsi_error(0, stat32 & NSI_NON_FATAL_MASK, error_found,
  620. handle_error);
  621. }
  622. stat32 = info->nsi_nerr;
  623. if (stat32 & NSI_ERR_MASK) {
  624. if (stat32 & NSI_FATAL_MASK)
  625. nsi_error(1, stat32 & NSI_FATAL_MASK, error_found,
  626. handle_error);
  627. if (stat32 & NSI_NON_FATAL_MASK)
  628. nsi_error(0, stat32 & NSI_NON_FATAL_MASK, error_found,
  629. handle_error);
  630. }
  631. }
  632. static void e752x_check_sysbus(struct e752x_error_info *info,
  633. int *error_found, int handle_error)
  634. {
  635. u32 stat32, error32;
  636. //pci_read_config_dword(dev,E752X_SYSBUS_FERR,&stat32);
  637. stat32 = info->sysbus_ferr + (info->sysbus_nerr << 16);
  638. if (stat32 == 0)
  639. return; /* no errors */
  640. error32 = (stat32 >> 16) & 0x3ff;
  641. stat32 = stat32 & 0x3ff;
  642. if (stat32 & 0x087)
  643. sysbus_error(1, stat32 & 0x087, error_found, handle_error);
  644. if (stat32 & 0x378)
  645. sysbus_error(0, stat32 & 0x378, error_found, handle_error);
  646. if (error32 & 0x087)
  647. sysbus_error(1, error32 & 0x087, error_found, handle_error);
  648. if (error32 & 0x378)
  649. sysbus_error(0, error32 & 0x378, error_found, handle_error);
  650. }
  651. static void e752x_check_membuf(struct e752x_error_info *info,
  652. int *error_found, int handle_error)
  653. {
  654. u8 stat8;
  655. stat8 = info->buf_ferr;
  656. if (stat8 & 0x0f) { /* Error, so process */
  657. stat8 &= 0x0f;
  658. membuf_error(stat8, error_found, handle_error);
  659. }
  660. stat8 = info->buf_nerr;
  661. if (stat8 & 0x0f) { /* Error, so process */
  662. stat8 &= 0x0f;
  663. membuf_error(stat8, error_found, handle_error);
  664. }
  665. }
  666. static void e752x_check_dram(struct mem_ctl_info *mci,
  667. struct e752x_error_info *info, int *error_found,
  668. int handle_error)
  669. {
  670. u16 error_one, error_next;
  671. error_one = info->dram_ferr;
  672. error_next = info->dram_nerr;
  673. /* decode and report errors */
  674. if (error_one & 0x0101) /* check first error correctable */
  675. process_ce(mci, error_one, info->dram_sec1_add,
  676. info->dram_sec1_syndrome, error_found, handle_error);
  677. if (error_next & 0x0101) /* check next error correctable */
  678. process_ce(mci, error_next, info->dram_sec2_add,
  679. info->dram_sec2_syndrome, error_found, handle_error);
  680. if (error_one & 0x4040)
  681. process_ue_no_info_wr(mci, error_found, handle_error);
  682. if (error_next & 0x4040)
  683. process_ue_no_info_wr(mci, error_found, handle_error);
  684. if (error_one & 0x2020)
  685. process_ded_retry(mci, error_one, info->dram_retr_add,
  686. error_found, handle_error);
  687. if (error_next & 0x2020)
  688. process_ded_retry(mci, error_next, info->dram_retr_add,
  689. error_found, handle_error);
  690. if (error_one & 0x0808)
  691. process_threshold_ce(mci, error_one, error_found, handle_error);
  692. if (error_next & 0x0808)
  693. process_threshold_ce(mci, error_next, error_found,
  694. handle_error);
  695. if (error_one & 0x0606)
  696. process_ue(mci, error_one, info->dram_ded_add,
  697. info->dram_scrb_add, error_found, handle_error);
  698. if (error_next & 0x0606)
  699. process_ue(mci, error_next, info->dram_ded_add,
  700. info->dram_scrb_add, error_found, handle_error);
  701. }
  702. static void e752x_get_error_info(struct mem_ctl_info *mci,
  703. struct e752x_error_info *info)
  704. {
  705. struct pci_dev *dev;
  706. struct e752x_pvt *pvt;
  707. memset(info, 0, sizeof(*info));
  708. pvt = (struct e752x_pvt *)mci->pvt_info;
  709. dev = pvt->dev_d0f1;
  710. pci_read_config_dword(dev, E752X_FERR_GLOBAL, &info->ferr_global);
  711. if (info->ferr_global) {
  712. if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
  713. pci_read_config_dword(dev, I3100_NSI_FERR,
  714. &info->nsi_ferr);
  715. info->hi_ferr = 0;
  716. } else {
  717. pci_read_config_byte(dev, E752X_HI_FERR,
  718. &info->hi_ferr);
  719. info->nsi_ferr = 0;
  720. }
  721. pci_read_config_word(dev, E752X_SYSBUS_FERR,
  722. &info->sysbus_ferr);
  723. pci_read_config_byte(dev, E752X_BUF_FERR, &info->buf_ferr);
  724. pci_read_config_word(dev, E752X_DRAM_FERR, &info->dram_ferr);
  725. pci_read_config_dword(dev, E752X_DRAM_SEC1_ADD,
  726. &info->dram_sec1_add);
  727. pci_read_config_word(dev, E752X_DRAM_SEC1_SYNDROME,
  728. &info->dram_sec1_syndrome);
  729. pci_read_config_dword(dev, E752X_DRAM_DED_ADD,
  730. &info->dram_ded_add);
  731. pci_read_config_dword(dev, E752X_DRAM_SCRB_ADD,
  732. &info->dram_scrb_add);
  733. pci_read_config_dword(dev, E752X_DRAM_RETR_ADD,
  734. &info->dram_retr_add);
  735. /* ignore the reserved bits just in case */
  736. if (info->hi_ferr & 0x7f)
  737. pci_write_config_byte(dev, E752X_HI_FERR,
  738. info->hi_ferr);
  739. if (info->nsi_ferr & NSI_ERR_MASK)
  740. pci_write_config_dword(dev, I3100_NSI_FERR,
  741. info->nsi_ferr);
  742. if (info->sysbus_ferr)
  743. pci_write_config_word(dev, E752X_SYSBUS_FERR,
  744. info->sysbus_ferr);
  745. if (info->buf_ferr & 0x0f)
  746. pci_write_config_byte(dev, E752X_BUF_FERR,
  747. info->buf_ferr);
  748. if (info->dram_ferr)
  749. pci_write_bits16(pvt->dev_d0f1, E752X_DRAM_FERR,
  750. info->dram_ferr, info->dram_ferr);
  751. pci_write_config_dword(dev, E752X_FERR_GLOBAL,
  752. info->ferr_global);
  753. }
  754. pci_read_config_dword(dev, E752X_NERR_GLOBAL, &info->nerr_global);
  755. if (info->nerr_global) {
  756. if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
  757. pci_read_config_dword(dev, I3100_NSI_NERR,
  758. &info->nsi_nerr);
  759. info->hi_nerr = 0;
  760. } else {
  761. pci_read_config_byte(dev, E752X_HI_NERR,
  762. &info->hi_nerr);
  763. info->nsi_nerr = 0;
  764. }
  765. pci_read_config_word(dev, E752X_SYSBUS_NERR,
  766. &info->sysbus_nerr);
  767. pci_read_config_byte(dev, E752X_BUF_NERR, &info->buf_nerr);
  768. pci_read_config_word(dev, E752X_DRAM_NERR, &info->dram_nerr);
  769. pci_read_config_dword(dev, E752X_DRAM_SEC2_ADD,
  770. &info->dram_sec2_add);
  771. pci_read_config_word(dev, E752X_DRAM_SEC2_SYNDROME,
  772. &info->dram_sec2_syndrome);
  773. if (info->hi_nerr & 0x7f)
  774. pci_write_config_byte(dev, E752X_HI_NERR,
  775. info->hi_nerr);
  776. if (info->nsi_nerr & NSI_ERR_MASK)
  777. pci_write_config_dword(dev, I3100_NSI_NERR,
  778. info->nsi_nerr);
  779. if (info->sysbus_nerr)
  780. pci_write_config_word(dev, E752X_SYSBUS_NERR,
  781. info->sysbus_nerr);
  782. if (info->buf_nerr & 0x0f)
  783. pci_write_config_byte(dev, E752X_BUF_NERR,
  784. info->buf_nerr);
  785. if (info->dram_nerr)
  786. pci_write_bits16(pvt->dev_d0f1, E752X_DRAM_NERR,
  787. info->dram_nerr, info->dram_nerr);
  788. pci_write_config_dword(dev, E752X_NERR_GLOBAL,
  789. info->nerr_global);
  790. }
  791. }
  792. static int e752x_process_error_info(struct mem_ctl_info *mci,
  793. struct e752x_error_info *info,
  794. int handle_errors)
  795. {
  796. u32 error32, stat32;
  797. int error_found;
  798. error_found = 0;
  799. error32 = (info->ferr_global >> 18) & 0x3ff;
  800. stat32 = (info->ferr_global >> 4) & 0x7ff;
  801. if (error32)
  802. global_error(1, error32, &error_found, handle_errors);
  803. if (stat32)
  804. global_error(0, stat32, &error_found, handle_errors);
  805. error32 = (info->nerr_global >> 18) & 0x3ff;
  806. stat32 = (info->nerr_global >> 4) & 0x7ff;
  807. if (error32)
  808. global_error(1, error32, &error_found, handle_errors);
  809. if (stat32)
  810. global_error(0, stat32, &error_found, handle_errors);
  811. e752x_check_hub_interface(info, &error_found, handle_errors);
  812. e752x_check_ns_interface(info, &error_found, handle_errors);
  813. e752x_check_sysbus(info, &error_found, handle_errors);
  814. e752x_check_membuf(info, &error_found, handle_errors);
  815. e752x_check_dram(mci, info, &error_found, handle_errors);
  816. return error_found;
  817. }
  818. static void e752x_check(struct mem_ctl_info *mci)
  819. {
  820. struct e752x_error_info info;
  821. edac_dbg(3, "\n");
  822. e752x_get_error_info(mci, &info);
  823. e752x_process_error_info(mci, &info, 1);
  824. }
  825. /* Program byte/sec bandwidth scrub rate to hardware */
  826. static int set_sdram_scrub_rate(struct mem_ctl_info *mci, u32 new_bw)
  827. {
  828. const struct scrubrate *scrubrates;
  829. struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
  830. struct pci_dev *pdev = pvt->dev_d0f0;
  831. int i;
  832. if (pvt->dev_info->ctl_dev == PCI_DEVICE_ID_INTEL_3100_0)
  833. scrubrates = scrubrates_i3100;
  834. else
  835. scrubrates = scrubrates_e752x;
  836. /* Translate the desired scrub rate to a e752x/3100 register value.
  837. * Search for the bandwidth that is equal or greater than the
  838. * desired rate and program the cooresponding register value.
  839. */
  840. for (i = 0; scrubrates[i].bandwidth != SDRATE_EOT; i++)
  841. if (scrubrates[i].bandwidth >= new_bw)
  842. break;
  843. if (scrubrates[i].bandwidth == SDRATE_EOT)
  844. return -1;
  845. pci_write_config_word(pdev, E752X_MCHSCRB, scrubrates[i].scrubval);
  846. return scrubrates[i].bandwidth;
  847. }
  848. /* Convert current scrub rate value into byte/sec bandwidth */
  849. static int get_sdram_scrub_rate(struct mem_ctl_info *mci)
  850. {
  851. const struct scrubrate *scrubrates;
  852. struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
  853. struct pci_dev *pdev = pvt->dev_d0f0;
  854. u16 scrubval;
  855. int i;
  856. if (pvt->dev_info->ctl_dev == PCI_DEVICE_ID_INTEL_3100_0)
  857. scrubrates = scrubrates_i3100;
  858. else
  859. scrubrates = scrubrates_e752x;
  860. /* Find the bandwidth matching the memory scrubber configuration */
  861. pci_read_config_word(pdev, E752X_MCHSCRB, &scrubval);
  862. scrubval = scrubval & 0x0f;
  863. for (i = 0; scrubrates[i].bandwidth != SDRATE_EOT; i++)
  864. if (scrubrates[i].scrubval == scrubval)
  865. break;
  866. if (scrubrates[i].bandwidth == SDRATE_EOT) {
  867. e752x_printk(KERN_WARNING,
  868. "Invalid sdram scrub control value: 0x%x\n", scrubval);
  869. return -1;
  870. }
  871. return scrubrates[i].bandwidth;
  872. }
  873. /* Return 1 if dual channel mode is active. Else return 0. */
  874. static inline int dual_channel_active(u16 ddrcsr)
  875. {
  876. return (((ddrcsr >> 12) & 3) == 3);
  877. }
  878. /* Remap csrow index numbers if map_type is "reverse"
  879. */
  880. static inline int remap_csrow_index(struct mem_ctl_info *mci, int index)
  881. {
  882. struct e752x_pvt *pvt = mci->pvt_info;
  883. if (!pvt->map_type)
  884. return (7 - index);
  885. return (index);
  886. }
  887. static void e752x_init_csrows(struct mem_ctl_info *mci, struct pci_dev *pdev,
  888. u16 ddrcsr)
  889. {
  890. struct csrow_info *csrow;
  891. enum edac_type edac_mode;
  892. unsigned long last_cumul_size;
  893. int index, mem_dev, drc_chan;
  894. int drc_drbg; /* DRB granularity 0=64mb, 1=128mb */
  895. int drc_ddim; /* DRAM Data Integrity Mode 0=none, 2=edac */
  896. u8 value;
  897. u32 dra, drc, cumul_size, i, nr_pages;
  898. dra = 0;
  899. for (index = 0; index < 4; index++) {
  900. u8 dra_reg;
  901. pci_read_config_byte(pdev, E752X_DRA + index, &dra_reg);
  902. dra |= dra_reg << (index * 8);
  903. }
  904. pci_read_config_dword(pdev, E752X_DRC, &drc);
  905. drc_chan = dual_channel_active(ddrcsr) ? 1 : 0;
  906. drc_drbg = drc_chan + 1; /* 128 in dual mode, 64 in single */
  907. drc_ddim = (drc >> 20) & 0x3;
  908. /* The dram row boundary (DRB) reg values are boundary address for
  909. * each DRAM row with a granularity of 64 or 128MB (single/dual
  910. * channel operation). DRB regs are cumulative; therefore DRB7 will
  911. * contain the total memory contained in all eight rows.
  912. */
  913. for (last_cumul_size = index = 0; index < mci->nr_csrows; index++) {
  914. /* mem_dev 0=x8, 1=x4 */
  915. mem_dev = (dra >> (index * 4 + 2)) & 0x3;
  916. csrow = mci->csrows[remap_csrow_index(mci, index)];
  917. mem_dev = (mem_dev == 2);
  918. pci_read_config_byte(pdev, E752X_DRB + index, &value);
  919. /* convert a 128 or 64 MiB DRB to a page size. */
  920. cumul_size = value << (25 + drc_drbg - PAGE_SHIFT);
  921. edac_dbg(3, "(%d) cumul_size 0x%x\n", index, cumul_size);
  922. if (cumul_size == last_cumul_size)
  923. continue; /* not populated */
  924. csrow->first_page = last_cumul_size;
  925. csrow->last_page = cumul_size - 1;
  926. nr_pages = cumul_size - last_cumul_size;
  927. last_cumul_size = cumul_size;
  928. /*
  929. * if single channel or x8 devices then SECDED
  930. * if dual channel and x4 then S4ECD4ED
  931. */
  932. if (drc_ddim) {
  933. if (drc_chan && mem_dev) {
  934. edac_mode = EDAC_S4ECD4ED;
  935. mci->edac_cap |= EDAC_FLAG_S4ECD4ED;
  936. } else {
  937. edac_mode = EDAC_SECDED;
  938. mci->edac_cap |= EDAC_FLAG_SECDED;
  939. }
  940. } else
  941. edac_mode = EDAC_NONE;
  942. for (i = 0; i < csrow->nr_channels; i++) {
  943. struct dimm_info *dimm = csrow->channels[i]->dimm;
  944. edac_dbg(3, "Initializing rank at (%i,%i)\n", index, i);
  945. dimm->nr_pages = nr_pages / csrow->nr_channels;
  946. dimm->grain = 1 << 12; /* 4KiB - resolution of CELOG */
  947. dimm->mtype = MEM_RDDR; /* only one type supported */
  948. dimm->dtype = mem_dev ? DEV_X4 : DEV_X8;
  949. dimm->edac_mode = edac_mode;
  950. }
  951. }
  952. }
  953. static void e752x_init_mem_map_table(struct pci_dev *pdev,
  954. struct e752x_pvt *pvt)
  955. {
  956. int index;
  957. u8 value, last, row;
  958. last = 0;
  959. row = 0;
  960. for (index = 0; index < 8; index += 2) {
  961. pci_read_config_byte(pdev, E752X_DRB + index, &value);
  962. /* test if there is a dimm in this slot */
  963. if (value == last) {
  964. /* no dimm in the slot, so flag it as empty */
  965. pvt->map[index] = 0xff;
  966. pvt->map[index + 1] = 0xff;
  967. } else { /* there is a dimm in the slot */
  968. pvt->map[index] = row;
  969. row++;
  970. last = value;
  971. /* test the next value to see if the dimm is double
  972. * sided
  973. */
  974. pci_read_config_byte(pdev, E752X_DRB + index + 1,
  975. &value);
  976. /* the dimm is single sided, so flag as empty */
  977. /* this is a double sided dimm to save the next row #*/
  978. pvt->map[index + 1] = (value == last) ? 0xff : row;
  979. row++;
  980. last = value;
  981. }
  982. }
  983. }
  984. /* Return 0 on success or 1 on failure. */
  985. static int e752x_get_devs(struct pci_dev *pdev, int dev_idx,
  986. struct e752x_pvt *pvt)
  987. {
  988. pvt->dev_d0f1 = pci_get_device(PCI_VENDOR_ID_INTEL,
  989. pvt->dev_info->err_dev, NULL);
  990. if (pvt->dev_d0f1 == NULL) {
  991. pvt->dev_d0f1 = pci_scan_single_device(pdev->bus,
  992. PCI_DEVFN(0, 1));
  993. pci_dev_get(pvt->dev_d0f1);
  994. }
  995. if (pvt->dev_d0f1 == NULL) {
  996. e752x_printk(KERN_ERR, "error reporting device not found:"
  997. "vendor %x device 0x%x (broken BIOS?)\n",
  998. PCI_VENDOR_ID_INTEL, e752x_devs[dev_idx].err_dev);
  999. return 1;
  1000. }
  1001. pvt->dev_d0f0 = pci_get_device(PCI_VENDOR_ID_INTEL,
  1002. e752x_devs[dev_idx].ctl_dev,
  1003. NULL);
  1004. if (pvt->dev_d0f0 == NULL)
  1005. goto fail;
  1006. return 0;
  1007. fail:
  1008. pci_dev_put(pvt->dev_d0f1);
  1009. return 1;
  1010. }
  1011. /* Setup system bus parity mask register.
  1012. * Sysbus parity supported on:
  1013. * e7320/e7520/e7525 + Xeon
  1014. */
  1015. static void e752x_init_sysbus_parity_mask(struct e752x_pvt *pvt)
  1016. {
  1017. char *cpu_id = cpu_data(0).x86_model_id;
  1018. struct pci_dev *dev = pvt->dev_d0f1;
  1019. int enable = 1;
  1020. /* Allow module parameter override, else see if CPU supports parity */
  1021. if (sysbus_parity != -1) {
  1022. enable = sysbus_parity;
  1023. } else if (cpu_id[0] && !strstr(cpu_id, "Xeon")) {
  1024. e752x_printk(KERN_INFO, "System Bus Parity not "
  1025. "supported by CPU, disabling\n");
  1026. enable = 0;
  1027. }
  1028. if (enable)
  1029. pci_write_config_word(dev, E752X_SYSBUS_ERRMASK, 0x0000);
  1030. else
  1031. pci_write_config_word(dev, E752X_SYSBUS_ERRMASK, 0x0309);
  1032. }
  1033. static void e752x_init_error_reporting_regs(struct e752x_pvt *pvt)
  1034. {
  1035. struct pci_dev *dev;
  1036. dev = pvt->dev_d0f1;
  1037. /* Turn off error disable & SMI in case the BIOS turned it on */
  1038. if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
  1039. pci_write_config_dword(dev, I3100_NSI_EMASK, 0);
  1040. pci_write_config_dword(dev, I3100_NSI_SMICMD, 0);
  1041. } else {
  1042. pci_write_config_byte(dev, E752X_HI_ERRMASK, 0x00);
  1043. pci_write_config_byte(dev, E752X_HI_SMICMD, 0x00);
  1044. }
  1045. e752x_init_sysbus_parity_mask(pvt);
  1046. pci_write_config_word(dev, E752X_SYSBUS_SMICMD, 0x00);
  1047. pci_write_config_byte(dev, E752X_BUF_ERRMASK, 0x00);
  1048. pci_write_config_byte(dev, E752X_BUF_SMICMD, 0x00);
  1049. pci_write_config_byte(dev, E752X_DRAM_ERRMASK, 0x00);
  1050. pci_write_config_byte(dev, E752X_DRAM_SMICMD, 0x00);
  1051. }
  1052. static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
  1053. {
  1054. u16 pci_data;
  1055. u8 stat8;
  1056. struct mem_ctl_info *mci;
  1057. struct edac_mc_layer layers[2];
  1058. struct e752x_pvt *pvt;
  1059. u16 ddrcsr;
  1060. int drc_chan; /* Number of channels 0=1chan,1=2chan */
  1061. struct e752x_error_info discard;
  1062. edac_dbg(0, "mci\n");
  1063. edac_dbg(0, "Starting Probe1\n");
  1064. /* check to see if device 0 function 1 is enabled; if it isn't, we
  1065. * assume the BIOS has reserved it for a reason and is expecting
  1066. * exclusive access, we take care not to violate that assumption and
  1067. * fail the probe. */
  1068. pci_read_config_byte(pdev, E752X_DEVPRES1, &stat8);
  1069. if (!force_function_unhide && !(stat8 & (1 << 5))) {
  1070. printk(KERN_INFO "Contact your BIOS vendor to see if the "
  1071. "E752x error registers can be safely un-hidden\n");
  1072. return -ENODEV;
  1073. }
  1074. stat8 |= (1 << 5);
  1075. pci_write_config_byte(pdev, E752X_DEVPRES1, stat8);
  1076. pci_read_config_word(pdev, E752X_DDRCSR, &ddrcsr);
  1077. /* FIXME: should check >>12 or 0xf, true for all? */
  1078. /* Dual channel = 1, Single channel = 0 */
  1079. drc_chan = dual_channel_active(ddrcsr);
  1080. layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
  1081. layers[0].size = E752X_NR_CSROWS;
  1082. layers[0].is_virt_csrow = true;
  1083. layers[1].type = EDAC_MC_LAYER_CHANNEL;
  1084. layers[1].size = drc_chan + 1;
  1085. layers[1].is_virt_csrow = false;
  1086. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
  1087. if (mci == NULL)
  1088. return -ENOMEM;
  1089. edac_dbg(3, "init mci\n");
  1090. mci->mtype_cap = MEM_FLAG_RDDR;
  1091. /* 3100 IMCH supports SECDEC only */
  1092. mci->edac_ctl_cap = (dev_idx == I3100) ? EDAC_FLAG_SECDED :
  1093. (EDAC_FLAG_NONE | EDAC_FLAG_SECDED | EDAC_FLAG_S4ECD4ED);
  1094. /* FIXME - what if different memory types are in different csrows? */
  1095. mci->mod_name = EDAC_MOD_STR;
  1096. mci->mod_ver = E752X_REVISION;
  1097. mci->pdev = &pdev->dev;
  1098. edac_dbg(3, "init pvt\n");
  1099. pvt = (struct e752x_pvt *)mci->pvt_info;
  1100. pvt->dev_info = &e752x_devs[dev_idx];
  1101. pvt->mc_symmetric = ((ddrcsr & 0x10) != 0);
  1102. if (e752x_get_devs(pdev, dev_idx, pvt)) {
  1103. edac_mc_free(mci);
  1104. return -ENODEV;
  1105. }
  1106. edac_dbg(3, "more mci init\n");
  1107. mci->ctl_name = pvt->dev_info->ctl_name;
  1108. mci->dev_name = pci_name(pdev);
  1109. mci->edac_check = e752x_check;
  1110. mci->ctl_page_to_phys = ctl_page_to_phys;
  1111. mci->set_sdram_scrub_rate = set_sdram_scrub_rate;
  1112. mci->get_sdram_scrub_rate = get_sdram_scrub_rate;
  1113. /* set the map type. 1 = normal, 0 = reversed
  1114. * Must be set before e752x_init_csrows in case csrow mapping
  1115. * is reversed.
  1116. */
  1117. pci_read_config_byte(pdev, E752X_DRM, &stat8);
  1118. pvt->map_type = ((stat8 & 0x0f) > ((stat8 >> 4) & 0x0f));
  1119. e752x_init_csrows(mci, pdev, ddrcsr);
  1120. e752x_init_mem_map_table(pdev, pvt);
  1121. if (dev_idx == I3100)
  1122. mci->edac_cap = EDAC_FLAG_SECDED; /* the only mode supported */
  1123. else
  1124. mci->edac_cap |= EDAC_FLAG_NONE;
  1125. edac_dbg(3, "tolm, remapbase, remaplimit\n");
  1126. /* load the top of low memory, remap base, and remap limit vars */
  1127. pci_read_config_word(pdev, E752X_TOLM, &pci_data);
  1128. pvt->tolm = ((u32) pci_data) << 4;
  1129. pci_read_config_word(pdev, E752X_REMAPBASE, &pci_data);
  1130. pvt->remapbase = ((u32) pci_data) << 14;
  1131. pci_read_config_word(pdev, E752X_REMAPLIMIT, &pci_data);
  1132. pvt->remaplimit = ((u32) pci_data) << 14;
  1133. e752x_printk(KERN_INFO,
  1134. "tolm = %x, remapbase = %x, remaplimit = %x\n",
  1135. pvt->tolm, pvt->remapbase, pvt->remaplimit);
  1136. /* Here we assume that we will never see multiple instances of this
  1137. * type of memory controller. The ID is therefore hardcoded to 0.
  1138. */
  1139. if (edac_mc_add_mc(mci)) {
  1140. edac_dbg(3, "failed edac_mc_add_mc()\n");
  1141. goto fail;
  1142. }
  1143. e752x_init_error_reporting_regs(pvt);
  1144. e752x_get_error_info(mci, &discard); /* clear other MCH errors */
  1145. /* allocating generic PCI control info */
  1146. e752x_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  1147. if (!e752x_pci) {
  1148. printk(KERN_WARNING
  1149. "%s(): Unable to create PCI control\n", __func__);
  1150. printk(KERN_WARNING
  1151. "%s(): PCI error report via EDAC not setup\n",
  1152. __func__);
  1153. }
  1154. /* get this far and it's successful */
  1155. edac_dbg(3, "success\n");
  1156. return 0;
  1157. fail:
  1158. pci_dev_put(pvt->dev_d0f0);
  1159. pci_dev_put(pvt->dev_d0f1);
  1160. edac_mc_free(mci);
  1161. return -ENODEV;
  1162. }
  1163. /* returns count (>= 0), or negative on error */
  1164. static int e752x_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  1165. {
  1166. edac_dbg(0, "\n");
  1167. /* wake up and enable device */
  1168. if (pci_enable_device(pdev) < 0)
  1169. return -EIO;
  1170. return e752x_probe1(pdev, ent->driver_data);
  1171. }
  1172. static void e752x_remove_one(struct pci_dev *pdev)
  1173. {
  1174. struct mem_ctl_info *mci;
  1175. struct e752x_pvt *pvt;
  1176. edac_dbg(0, "\n");
  1177. if (e752x_pci)
  1178. edac_pci_release_generic_ctl(e752x_pci);
  1179. if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
  1180. return;
  1181. pvt = (struct e752x_pvt *)mci->pvt_info;
  1182. pci_dev_put(pvt->dev_d0f0);
  1183. pci_dev_put(pvt->dev_d0f1);
  1184. edac_mc_free(mci);
  1185. }
  1186. static const struct pci_device_id e752x_pci_tbl[] = {
  1187. {
  1188. PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  1189. E7520},
  1190. {
  1191. PCI_VEND_DEV(INTEL, 7525_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  1192. E7525},
  1193. {
  1194. PCI_VEND_DEV(INTEL, 7320_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  1195. E7320},
  1196. {
  1197. PCI_VEND_DEV(INTEL, 3100_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  1198. I3100},
  1199. {
  1200. 0,
  1201. } /* 0 terminated list. */
  1202. };
  1203. MODULE_DEVICE_TABLE(pci, e752x_pci_tbl);
  1204. static struct pci_driver e752x_driver = {
  1205. .name = EDAC_MOD_STR,
  1206. .probe = e752x_init_one,
  1207. .remove = e752x_remove_one,
  1208. .id_table = e752x_pci_tbl,
  1209. };
  1210. static int __init e752x_init(void)
  1211. {
  1212. int pci_rc;
  1213. edac_dbg(3, "\n");
  1214. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1215. opstate_init();
  1216. pci_rc = pci_register_driver(&e752x_driver);
  1217. return (pci_rc < 0) ? pci_rc : 0;
  1218. }
  1219. static void __exit e752x_exit(void)
  1220. {
  1221. edac_dbg(3, "\n");
  1222. pci_unregister_driver(&e752x_driver);
  1223. }
  1224. module_init(e752x_init);
  1225. module_exit(e752x_exit);
  1226. MODULE_LICENSE("GPL");
  1227. MODULE_AUTHOR("Linux Networx (http://lnxi.com) Tom Zimmerman\n");
  1228. MODULE_DESCRIPTION("MC support for Intel e752x/3100 memory controllers");
  1229. module_param(force_function_unhide, int, 0444);
  1230. MODULE_PARM_DESC(force_function_unhide, "if BIOS sets Dev0:Fun1 up as hidden:"
  1231. " 1=force unhide and hope BIOS doesn't fight driver for "
  1232. "Dev0:Fun1 access");
  1233. module_param(edac_op_state, int, 0444);
  1234. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
  1235. module_param(sysbus_parity, int, 0444);
  1236. MODULE_PARM_DESC(sysbus_parity, "0=disable system bus parity checking,"
  1237. " 1=enable system bus parity checking, default=auto-detect");
  1238. module_param(report_non_memory_errors, int, 0644);
  1239. MODULE_PARM_DESC(report_non_memory_errors, "0=disable non-memory error "
  1240. "reporting, 1=enable non-memory error reporting");