e752x_edac.c 41 KB

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