i5000_edac.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585
  1. /*
  2. * Intel 5000(P/V/X) class Memory Controllers kernel module
  3. *
  4. * This file may be distributed under the terms of the
  5. * GNU General Public License.
  6. *
  7. * Written by Douglas Thompson Linux Networx (http://lnxi.com)
  8. * norsk5@xmission.com
  9. *
  10. * This module is based on the following document:
  11. *
  12. * Intel 5000X Chipset Memory Controller Hub (MCH) - Datasheet
  13. * http://developer.intel.com/design/chipsets/datashts/313070.htm
  14. *
  15. */
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/pci.h>
  19. #include <linux/pci_ids.h>
  20. #include <linux/slab.h>
  21. #include <linux/edac.h>
  22. #include <asm/mmzone.h>
  23. #include "edac_core.h"
  24. /*
  25. * Alter this version for the I5000 module when modifications are made
  26. */
  27. #define I5000_REVISION " Ver: 2.0.12"
  28. #define EDAC_MOD_STR "i5000_edac"
  29. #define i5000_printk(level, fmt, arg...) \
  30. edac_printk(level, "i5000", fmt, ##arg)
  31. #define i5000_mc_printk(mci, level, fmt, arg...) \
  32. edac_mc_chipset_printk(mci, level, "i5000", fmt, ##arg)
  33. #ifndef PCI_DEVICE_ID_INTEL_FBD_0
  34. #define PCI_DEVICE_ID_INTEL_FBD_0 0x25F5
  35. #endif
  36. #ifndef PCI_DEVICE_ID_INTEL_FBD_1
  37. #define PCI_DEVICE_ID_INTEL_FBD_1 0x25F6
  38. #endif
  39. /* Device 16,
  40. * Function 0: System Address
  41. * Function 1: Memory Branch Map, Control, Errors Register
  42. * Function 2: FSB Error Registers
  43. *
  44. * All 3 functions of Device 16 (0,1,2) share the SAME DID
  45. */
  46. #define PCI_DEVICE_ID_INTEL_I5000_DEV16 0x25F0
  47. /* OFFSETS for Function 0 */
  48. /* OFFSETS for Function 1 */
  49. #define AMBASE 0x48
  50. #define MAXCH 0x56
  51. #define MAXDIMMPERCH 0x57
  52. #define TOLM 0x6C
  53. #define REDMEMB 0x7C
  54. #define RED_ECC_LOCATOR(x) ((x) & 0x3FFFF)
  55. #define REC_ECC_LOCATOR_EVEN(x) ((x) & 0x001FF)
  56. #define REC_ECC_LOCATOR_ODD(x) ((x) & 0x3FE00)
  57. #define MIR0 0x80
  58. #define MIR1 0x84
  59. #define MIR2 0x88
  60. #define AMIR0 0x8C
  61. #define AMIR1 0x90
  62. #define AMIR2 0x94
  63. #define FERR_FAT_FBD 0x98
  64. #define NERR_FAT_FBD 0x9C
  65. #define EXTRACT_FBDCHAN_INDX(x) (((x)>>28) & 0x3)
  66. #define FERR_FAT_FBDCHAN 0x30000000
  67. #define FERR_FAT_M3ERR 0x00000004
  68. #define FERR_FAT_M2ERR 0x00000002
  69. #define FERR_FAT_M1ERR 0x00000001
  70. #define FERR_FAT_MASK (FERR_FAT_M1ERR | \
  71. FERR_FAT_M2ERR | \
  72. FERR_FAT_M3ERR)
  73. #define FERR_NF_FBD 0xA0
  74. /* Thermal and SPD or BFD errors */
  75. #define FERR_NF_M28ERR 0x01000000
  76. #define FERR_NF_M27ERR 0x00800000
  77. #define FERR_NF_M26ERR 0x00400000
  78. #define FERR_NF_M25ERR 0x00200000
  79. #define FERR_NF_M24ERR 0x00100000
  80. #define FERR_NF_M23ERR 0x00080000
  81. #define FERR_NF_M22ERR 0x00040000
  82. #define FERR_NF_M21ERR 0x00020000
  83. /* Correctable errors */
  84. #define FERR_NF_M20ERR 0x00010000
  85. #define FERR_NF_M19ERR 0x00008000
  86. #define FERR_NF_M18ERR 0x00004000
  87. #define FERR_NF_M17ERR 0x00002000
  88. /* Non-Retry or redundant Retry errors */
  89. #define FERR_NF_M16ERR 0x00001000
  90. #define FERR_NF_M15ERR 0x00000800
  91. #define FERR_NF_M14ERR 0x00000400
  92. #define FERR_NF_M13ERR 0x00000200
  93. /* Uncorrectable errors */
  94. #define FERR_NF_M12ERR 0x00000100
  95. #define FERR_NF_M11ERR 0x00000080
  96. #define FERR_NF_M10ERR 0x00000040
  97. #define FERR_NF_M9ERR 0x00000020
  98. #define FERR_NF_M8ERR 0x00000010
  99. #define FERR_NF_M7ERR 0x00000008
  100. #define FERR_NF_M6ERR 0x00000004
  101. #define FERR_NF_M5ERR 0x00000002
  102. #define FERR_NF_M4ERR 0x00000001
  103. #define FERR_NF_UNCORRECTABLE (FERR_NF_M12ERR | \
  104. FERR_NF_M11ERR | \
  105. FERR_NF_M10ERR | \
  106. FERR_NF_M9ERR | \
  107. FERR_NF_M8ERR | \
  108. FERR_NF_M7ERR | \
  109. FERR_NF_M6ERR | \
  110. FERR_NF_M5ERR | \
  111. FERR_NF_M4ERR)
  112. #define FERR_NF_CORRECTABLE (FERR_NF_M20ERR | \
  113. FERR_NF_M19ERR | \
  114. FERR_NF_M18ERR | \
  115. FERR_NF_M17ERR)
  116. #define FERR_NF_DIMM_SPARE (FERR_NF_M27ERR | \
  117. FERR_NF_M28ERR)
  118. #define FERR_NF_THERMAL (FERR_NF_M26ERR | \
  119. FERR_NF_M25ERR | \
  120. FERR_NF_M24ERR | \
  121. FERR_NF_M23ERR)
  122. #define FERR_NF_SPD_PROTOCOL (FERR_NF_M22ERR)
  123. #define FERR_NF_NORTH_CRC (FERR_NF_M21ERR)
  124. #define FERR_NF_NON_RETRY (FERR_NF_M13ERR | \
  125. FERR_NF_M14ERR | \
  126. FERR_NF_M15ERR)
  127. #define NERR_NF_FBD 0xA4
  128. #define FERR_NF_MASK (FERR_NF_UNCORRECTABLE | \
  129. FERR_NF_CORRECTABLE | \
  130. FERR_NF_DIMM_SPARE | \
  131. FERR_NF_THERMAL | \
  132. FERR_NF_SPD_PROTOCOL | \
  133. FERR_NF_NORTH_CRC | \
  134. FERR_NF_NON_RETRY)
  135. #define EMASK_FBD 0xA8
  136. #define EMASK_FBD_M28ERR 0x08000000
  137. #define EMASK_FBD_M27ERR 0x04000000
  138. #define EMASK_FBD_M26ERR 0x02000000
  139. #define EMASK_FBD_M25ERR 0x01000000
  140. #define EMASK_FBD_M24ERR 0x00800000
  141. #define EMASK_FBD_M23ERR 0x00400000
  142. #define EMASK_FBD_M22ERR 0x00200000
  143. #define EMASK_FBD_M21ERR 0x00100000
  144. #define EMASK_FBD_M20ERR 0x00080000
  145. #define EMASK_FBD_M19ERR 0x00040000
  146. #define EMASK_FBD_M18ERR 0x00020000
  147. #define EMASK_FBD_M17ERR 0x00010000
  148. #define EMASK_FBD_M15ERR 0x00004000
  149. #define EMASK_FBD_M14ERR 0x00002000
  150. #define EMASK_FBD_M13ERR 0x00001000
  151. #define EMASK_FBD_M12ERR 0x00000800
  152. #define EMASK_FBD_M11ERR 0x00000400
  153. #define EMASK_FBD_M10ERR 0x00000200
  154. #define EMASK_FBD_M9ERR 0x00000100
  155. #define EMASK_FBD_M8ERR 0x00000080
  156. #define EMASK_FBD_M7ERR 0x00000040
  157. #define EMASK_FBD_M6ERR 0x00000020
  158. #define EMASK_FBD_M5ERR 0x00000010
  159. #define EMASK_FBD_M4ERR 0x00000008
  160. #define EMASK_FBD_M3ERR 0x00000004
  161. #define EMASK_FBD_M2ERR 0x00000002
  162. #define EMASK_FBD_M1ERR 0x00000001
  163. #define ENABLE_EMASK_FBD_FATAL_ERRORS (EMASK_FBD_M1ERR | \
  164. EMASK_FBD_M2ERR | \
  165. EMASK_FBD_M3ERR)
  166. #define ENABLE_EMASK_FBD_UNCORRECTABLE (EMASK_FBD_M4ERR | \
  167. EMASK_FBD_M5ERR | \
  168. EMASK_FBD_M6ERR | \
  169. EMASK_FBD_M7ERR | \
  170. EMASK_FBD_M8ERR | \
  171. EMASK_FBD_M9ERR | \
  172. EMASK_FBD_M10ERR | \
  173. EMASK_FBD_M11ERR | \
  174. EMASK_FBD_M12ERR)
  175. #define ENABLE_EMASK_FBD_CORRECTABLE (EMASK_FBD_M17ERR | \
  176. EMASK_FBD_M18ERR | \
  177. EMASK_FBD_M19ERR | \
  178. EMASK_FBD_M20ERR)
  179. #define ENABLE_EMASK_FBD_DIMM_SPARE (EMASK_FBD_M27ERR | \
  180. EMASK_FBD_M28ERR)
  181. #define ENABLE_EMASK_FBD_THERMALS (EMASK_FBD_M26ERR | \
  182. EMASK_FBD_M25ERR | \
  183. EMASK_FBD_M24ERR | \
  184. EMASK_FBD_M23ERR)
  185. #define ENABLE_EMASK_FBD_SPD_PROTOCOL (EMASK_FBD_M22ERR)
  186. #define ENABLE_EMASK_FBD_NORTH_CRC (EMASK_FBD_M21ERR)
  187. #define ENABLE_EMASK_FBD_NON_RETRY (EMASK_FBD_M15ERR | \
  188. EMASK_FBD_M14ERR | \
  189. EMASK_FBD_M13ERR)
  190. #define ENABLE_EMASK_ALL (ENABLE_EMASK_FBD_NON_RETRY | \
  191. ENABLE_EMASK_FBD_NORTH_CRC | \
  192. ENABLE_EMASK_FBD_SPD_PROTOCOL | \
  193. ENABLE_EMASK_FBD_THERMALS | \
  194. ENABLE_EMASK_FBD_DIMM_SPARE | \
  195. ENABLE_EMASK_FBD_FATAL_ERRORS | \
  196. ENABLE_EMASK_FBD_CORRECTABLE | \
  197. ENABLE_EMASK_FBD_UNCORRECTABLE)
  198. #define ERR0_FBD 0xAC
  199. #define ERR1_FBD 0xB0
  200. #define ERR2_FBD 0xB4
  201. #define MCERR_FBD 0xB8
  202. #define NRECMEMA 0xBE
  203. #define NREC_BANK(x) (((x)>>12) & 0x7)
  204. #define NREC_RDWR(x) (((x)>>11) & 1)
  205. #define NREC_RANK(x) (((x)>>8) & 0x7)
  206. #define NRECMEMB 0xC0
  207. #define NREC_CAS(x) (((x)>>16) & 0xFFFFFF)
  208. #define NREC_RAS(x) ((x) & 0x7FFF)
  209. #define NRECFGLOG 0xC4
  210. #define NREEECFBDA 0xC8
  211. #define NREEECFBDB 0xCC
  212. #define NREEECFBDC 0xD0
  213. #define NREEECFBDD 0xD4
  214. #define NREEECFBDE 0xD8
  215. #define REDMEMA 0xDC
  216. #define RECMEMA 0xE2
  217. #define REC_BANK(x) (((x)>>12) & 0x7)
  218. #define REC_RDWR(x) (((x)>>11) & 1)
  219. #define REC_RANK(x) (((x)>>8) & 0x7)
  220. #define RECMEMB 0xE4
  221. #define REC_CAS(x) (((x)>>16) & 0xFFFFFF)
  222. #define REC_RAS(x) ((x) & 0x7FFF)
  223. #define RECFGLOG 0xE8
  224. #define RECFBDA 0xEC
  225. #define RECFBDB 0xF0
  226. #define RECFBDC 0xF4
  227. #define RECFBDD 0xF8
  228. #define RECFBDE 0xFC
  229. /* OFFSETS for Function 2 */
  230. /*
  231. * Device 21,
  232. * Function 0: Memory Map Branch 0
  233. *
  234. * Device 22,
  235. * Function 0: Memory Map Branch 1
  236. */
  237. #define PCI_DEVICE_ID_I5000_BRANCH_0 0x25F5
  238. #define PCI_DEVICE_ID_I5000_BRANCH_1 0x25F6
  239. #define AMB_PRESENT_0 0x64
  240. #define AMB_PRESENT_1 0x66
  241. #define MTR0 0x80
  242. #define MTR1 0x84
  243. #define MTR2 0x88
  244. #define MTR3 0x8C
  245. #define NUM_MTRS 4
  246. #define CHANNELS_PER_BRANCH 2
  247. #define MAX_BRANCHES 2
  248. /* Defines to extract the various fields from the
  249. * MTRx - Memory Technology Registers
  250. */
  251. #define MTR_DIMMS_PRESENT(mtr) ((mtr) & (0x1 << 8))
  252. #define MTR_DRAM_WIDTH(mtr) ((((mtr) >> 6) & 0x1) ? 8 : 4)
  253. #define MTR_DRAM_BANKS(mtr) ((((mtr) >> 5) & 0x1) ? 8 : 4)
  254. #define MTR_DRAM_BANKS_ADDR_BITS(mtr) ((MTR_DRAM_BANKS(mtr) == 8) ? 3 : 2)
  255. #define MTR_DIMM_RANK(mtr) (((mtr) >> 4) & 0x1)
  256. #define MTR_DIMM_RANK_ADDR_BITS(mtr) (MTR_DIMM_RANK(mtr) ? 2 : 1)
  257. #define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
  258. #define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
  259. #define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
  260. #define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
  261. /* enables the report of miscellaneous messages as CE errors - default off */
  262. static int misc_messages;
  263. /* Enumeration of supported devices */
  264. enum i5000_chips {
  265. I5000P = 0,
  266. I5000V = 1, /* future */
  267. I5000X = 2 /* future */
  268. };
  269. /* Device name and register DID (Device ID) */
  270. struct i5000_dev_info {
  271. const char *ctl_name; /* name for this device */
  272. u16 fsb_mapping_errors; /* DID for the branchmap,control */
  273. };
  274. /* Table of devices attributes supported by this driver */
  275. static const struct i5000_dev_info i5000_devs[] = {
  276. [I5000P] = {
  277. .ctl_name = "I5000",
  278. .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I5000_DEV16,
  279. },
  280. };
  281. struct i5000_dimm_info {
  282. int megabytes; /* size, 0 means not present */
  283. int dual_rank;
  284. };
  285. #define MAX_CHANNELS 6 /* max possible channels */
  286. #define MAX_CSROWS (8*2) /* max possible csrows per channel */
  287. /* driver private data structure */
  288. struct i5000_pvt {
  289. struct pci_dev *system_address; /* 16.0 */
  290. struct pci_dev *branchmap_werrors; /* 16.1 */
  291. struct pci_dev *fsb_error_regs; /* 16.2 */
  292. struct pci_dev *branch_0; /* 21.0 */
  293. struct pci_dev *branch_1; /* 22.0 */
  294. u16 tolm; /* top of low memory */
  295. u64 ambase; /* AMB BAR */
  296. u16 mir0, mir1, mir2;
  297. u16 b0_mtr[NUM_MTRS]; /* Memory Technlogy Reg */
  298. u16 b0_ambpresent0; /* Branch 0, Channel 0 */
  299. u16 b0_ambpresent1; /* Brnach 0, Channel 1 */
  300. u16 b1_mtr[NUM_MTRS]; /* Memory Technlogy Reg */
  301. u16 b1_ambpresent0; /* Branch 1, Channel 8 */
  302. u16 b1_ambpresent1; /* Branch 1, Channel 1 */
  303. /* DIMM information matrix, allocating architecture maximums */
  304. struct i5000_dimm_info dimm_info[MAX_CSROWS][MAX_CHANNELS];
  305. /* Actual values for this controller */
  306. int maxch; /* Max channels */
  307. int maxdimmperch; /* Max DIMMs per channel */
  308. };
  309. /* I5000 MCH error information retrieved from Hardware */
  310. struct i5000_error_info {
  311. /* These registers are always read from the MC */
  312. u32 ferr_fat_fbd; /* First Errors Fatal */
  313. u32 nerr_fat_fbd; /* Next Errors Fatal */
  314. u32 ferr_nf_fbd; /* First Errors Non-Fatal */
  315. u32 nerr_nf_fbd; /* Next Errors Non-Fatal */
  316. /* These registers are input ONLY if there was a Recoverable Error */
  317. u32 redmemb; /* Recoverable Mem Data Error log B */
  318. u16 recmema; /* Recoverable Mem Error log A */
  319. u32 recmemb; /* Recoverable Mem Error log B */
  320. /* These registers are input ONLY if there was a
  321. * Non-Recoverable Error */
  322. u16 nrecmema; /* Non-Recoverable Mem log A */
  323. u16 nrecmemb; /* Non-Recoverable Mem log B */
  324. };
  325. static struct edac_pci_ctl_info *i5000_pci;
  326. /*
  327. * i5000_get_error_info Retrieve the hardware error information from
  328. * the hardware and cache it in the 'info'
  329. * structure
  330. */
  331. static void i5000_get_error_info(struct mem_ctl_info *mci,
  332. struct i5000_error_info *info)
  333. {
  334. struct i5000_pvt *pvt;
  335. u32 value;
  336. pvt = mci->pvt_info;
  337. /* read in the 1st FATAL error register */
  338. pci_read_config_dword(pvt->branchmap_werrors, FERR_FAT_FBD, &value);
  339. /* Mask only the bits that the doc says are valid
  340. */
  341. value &= (FERR_FAT_FBDCHAN | FERR_FAT_MASK);
  342. /* If there is an error, then read in the */
  343. /* NEXT FATAL error register and the Memory Error Log Register A */
  344. if (value & FERR_FAT_MASK) {
  345. info->ferr_fat_fbd = value;
  346. /* harvest the various error data we need */
  347. pci_read_config_dword(pvt->branchmap_werrors,
  348. NERR_FAT_FBD, &info->nerr_fat_fbd);
  349. pci_read_config_word(pvt->branchmap_werrors,
  350. NRECMEMA, &info->nrecmema);
  351. pci_read_config_word(pvt->branchmap_werrors,
  352. NRECMEMB, &info->nrecmemb);
  353. /* Clear the error bits, by writing them back */
  354. pci_write_config_dword(pvt->branchmap_werrors,
  355. FERR_FAT_FBD, value);
  356. } else {
  357. info->ferr_fat_fbd = 0;
  358. info->nerr_fat_fbd = 0;
  359. info->nrecmema = 0;
  360. info->nrecmemb = 0;
  361. }
  362. /* read in the 1st NON-FATAL error register */
  363. pci_read_config_dword(pvt->branchmap_werrors, FERR_NF_FBD, &value);
  364. /* If there is an error, then read in the 1st NON-FATAL error
  365. * register as well */
  366. if (value & FERR_NF_MASK) {
  367. info->ferr_nf_fbd = value;
  368. /* harvest the various error data we need */
  369. pci_read_config_dword(pvt->branchmap_werrors,
  370. NERR_NF_FBD, &info->nerr_nf_fbd);
  371. pci_read_config_word(pvt->branchmap_werrors,
  372. RECMEMA, &info->recmema);
  373. pci_read_config_dword(pvt->branchmap_werrors,
  374. RECMEMB, &info->recmemb);
  375. pci_read_config_dword(pvt->branchmap_werrors,
  376. REDMEMB, &info->redmemb);
  377. /* Clear the error bits, by writing them back */
  378. pci_write_config_dword(pvt->branchmap_werrors,
  379. FERR_NF_FBD, value);
  380. } else {
  381. info->ferr_nf_fbd = 0;
  382. info->nerr_nf_fbd = 0;
  383. info->recmema = 0;
  384. info->recmemb = 0;
  385. info->redmemb = 0;
  386. }
  387. }
  388. /*
  389. * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
  390. * struct i5000_error_info *info,
  391. * int handle_errors);
  392. *
  393. * handle the Intel FATAL errors, if any
  394. */
  395. static void i5000_process_fatal_error_info(struct mem_ctl_info *mci,
  396. struct i5000_error_info *info,
  397. int handle_errors)
  398. {
  399. char msg[EDAC_MC_LABEL_LEN + 1 + 160];
  400. char *specific = NULL;
  401. u32 allErrors;
  402. int channel;
  403. int bank;
  404. int rank;
  405. int rdwr;
  406. int ras, cas;
  407. /* mask off the Error bits that are possible */
  408. allErrors = (info->ferr_fat_fbd & FERR_FAT_MASK);
  409. if (!allErrors)
  410. return; /* if no error, return now */
  411. channel = EXTRACT_FBDCHAN_INDX(info->ferr_fat_fbd);
  412. /* Use the NON-Recoverable macros to extract data */
  413. bank = NREC_BANK(info->nrecmema);
  414. rank = NREC_RANK(info->nrecmema);
  415. rdwr = NREC_RDWR(info->nrecmema);
  416. ras = NREC_RAS(info->nrecmemb);
  417. cas = NREC_CAS(info->nrecmemb);
  418. edac_dbg(0, "\t\tCSROW= %d Channel= %d (DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  419. rank, channel, bank,
  420. rdwr ? "Write" : "Read", ras, cas);
  421. /* Only 1 bit will be on */
  422. switch (allErrors) {
  423. case FERR_FAT_M1ERR:
  424. specific = "Alert on non-redundant retry or fast "
  425. "reset timeout";
  426. break;
  427. case FERR_FAT_M2ERR:
  428. specific = "Northbound CRC error on non-redundant "
  429. "retry";
  430. break;
  431. case FERR_FAT_M3ERR:
  432. {
  433. static int done;
  434. /*
  435. * This error is generated to inform that the intelligent
  436. * throttling is disabled and the temperature passed the
  437. * specified middle point. Since this is something the BIOS
  438. * should take care of, we'll warn only once to avoid
  439. * worthlessly flooding the log.
  440. */
  441. if (done)
  442. return;
  443. done++;
  444. specific = ">Tmid Thermal event with intelligent "
  445. "throttling disabled";
  446. }
  447. break;
  448. }
  449. /* Form out message */
  450. snprintf(msg, sizeof(msg),
  451. "Bank=%d RAS=%d CAS=%d FATAL Err=0x%x (%s)",
  452. bank, ras, cas, allErrors, specific);
  453. /* Call the helper to output message */
  454. edac_mc_handle_error(HW_EVENT_ERR_FATAL, mci, 0, 0, 0,
  455. channel >> 1, channel & 1, rank,
  456. rdwr ? "Write error" : "Read error",
  457. msg, NULL);
  458. }
  459. /*
  460. * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
  461. * struct i5000_error_info *info,
  462. * int handle_errors);
  463. *
  464. * handle the Intel NON-FATAL errors, if any
  465. */
  466. static void i5000_process_nonfatal_error_info(struct mem_ctl_info *mci,
  467. struct i5000_error_info *info,
  468. int handle_errors)
  469. {
  470. char msg[EDAC_MC_LABEL_LEN + 1 + 170];
  471. char *specific = NULL;
  472. u32 allErrors;
  473. u32 ue_errors;
  474. u32 ce_errors;
  475. u32 misc_errors;
  476. int branch;
  477. int channel;
  478. int bank;
  479. int rank;
  480. int rdwr;
  481. int ras, cas;
  482. /* mask off the Error bits that are possible */
  483. allErrors = (info->ferr_nf_fbd & FERR_NF_MASK);
  484. if (!allErrors)
  485. return; /* if no error, return now */
  486. /* ONLY ONE of the possible error bits will be set, as per the docs */
  487. ue_errors = allErrors & FERR_NF_UNCORRECTABLE;
  488. if (ue_errors) {
  489. edac_dbg(0, "\tUncorrected bits= 0x%x\n", ue_errors);
  490. branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
  491. /*
  492. * According with i5000 datasheet, bit 28 has no significance
  493. * for errors M4Err-M12Err and M17Err-M21Err, on FERR_NF_FBD
  494. */
  495. channel = branch & 2;
  496. bank = NREC_BANK(info->nrecmema);
  497. rank = NREC_RANK(info->nrecmema);
  498. rdwr = NREC_RDWR(info->nrecmema);
  499. ras = NREC_RAS(info->nrecmemb);
  500. cas = NREC_CAS(info->nrecmemb);
  501. edac_dbg(0, "\t\tCSROW= %d Channels= %d,%d (Branch= %d DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  502. rank, channel, channel + 1, branch >> 1, bank,
  503. rdwr ? "Write" : "Read", ras, cas);
  504. switch (ue_errors) {
  505. case FERR_NF_M12ERR:
  506. specific = "Non-Aliased Uncorrectable Patrol Data ECC";
  507. break;
  508. case FERR_NF_M11ERR:
  509. specific = "Non-Aliased Uncorrectable Spare-Copy "
  510. "Data ECC";
  511. break;
  512. case FERR_NF_M10ERR:
  513. specific = "Non-Aliased Uncorrectable Mirrored Demand "
  514. "Data ECC";
  515. break;
  516. case FERR_NF_M9ERR:
  517. specific = "Non-Aliased Uncorrectable Non-Mirrored "
  518. "Demand Data ECC";
  519. break;
  520. case FERR_NF_M8ERR:
  521. specific = "Aliased Uncorrectable Patrol Data ECC";
  522. break;
  523. case FERR_NF_M7ERR:
  524. specific = "Aliased Uncorrectable Spare-Copy Data ECC";
  525. break;
  526. case FERR_NF_M6ERR:
  527. specific = "Aliased Uncorrectable Mirrored Demand "
  528. "Data ECC";
  529. break;
  530. case FERR_NF_M5ERR:
  531. specific = "Aliased Uncorrectable Non-Mirrored Demand "
  532. "Data ECC";
  533. break;
  534. case FERR_NF_M4ERR:
  535. specific = "Uncorrectable Data ECC on Replay";
  536. break;
  537. }
  538. /* Form out message */
  539. snprintf(msg, sizeof(msg),
  540. "Rank=%d Bank=%d RAS=%d CAS=%d, UE Err=0x%x (%s)",
  541. rank, bank, ras, cas, ue_errors, specific);
  542. /* Call the helper to output message */
  543. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 0, 0, 0,
  544. channel >> 1, -1, rank,
  545. rdwr ? "Write error" : "Read error",
  546. msg, NULL);
  547. }
  548. /* Check correctable errors */
  549. ce_errors = allErrors & FERR_NF_CORRECTABLE;
  550. if (ce_errors) {
  551. edac_dbg(0, "\tCorrected bits= 0x%x\n", ce_errors);
  552. branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
  553. channel = 0;
  554. if (REC_ECC_LOCATOR_ODD(info->redmemb))
  555. channel = 1;
  556. /* Convert channel to be based from zero, instead of
  557. * from branch base of 0 */
  558. channel += branch;
  559. bank = REC_BANK(info->recmema);
  560. rank = REC_RANK(info->recmema);
  561. rdwr = REC_RDWR(info->recmema);
  562. ras = REC_RAS(info->recmemb);
  563. cas = REC_CAS(info->recmemb);
  564. edac_dbg(0, "\t\tCSROW= %d Channel= %d (Branch %d DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  565. rank, channel, branch >> 1, bank,
  566. rdwr ? "Write" : "Read", ras, cas);
  567. switch (ce_errors) {
  568. case FERR_NF_M17ERR:
  569. specific = "Correctable Non-Mirrored Demand Data ECC";
  570. break;
  571. case FERR_NF_M18ERR:
  572. specific = "Correctable Mirrored Demand Data ECC";
  573. break;
  574. case FERR_NF_M19ERR:
  575. specific = "Correctable Spare-Copy Data ECC";
  576. break;
  577. case FERR_NF_M20ERR:
  578. specific = "Correctable Patrol Data ECC";
  579. break;
  580. }
  581. /* Form out message */
  582. snprintf(msg, sizeof(msg),
  583. "Rank=%d Bank=%d RDWR=%s RAS=%d "
  584. "CAS=%d, CE Err=0x%x (%s))", branch >> 1, bank,
  585. rdwr ? "Write" : "Read", ras, cas, ce_errors,
  586. specific);
  587. /* Call the helper to output message */
  588. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 0, 0, 0,
  589. channel >> 1, channel % 2, rank,
  590. rdwr ? "Write error" : "Read error",
  591. msg, NULL);
  592. }
  593. if (!misc_messages)
  594. return;
  595. misc_errors = allErrors & (FERR_NF_NON_RETRY | FERR_NF_NORTH_CRC |
  596. FERR_NF_SPD_PROTOCOL | FERR_NF_DIMM_SPARE);
  597. if (misc_errors) {
  598. switch (misc_errors) {
  599. case FERR_NF_M13ERR:
  600. specific = "Non-Retry or Redundant Retry FBD Memory "
  601. "Alert or Redundant Fast Reset Timeout";
  602. break;
  603. case FERR_NF_M14ERR:
  604. specific = "Non-Retry or Redundant Retry FBD "
  605. "Configuration Alert";
  606. break;
  607. case FERR_NF_M15ERR:
  608. specific = "Non-Retry or Redundant Retry FBD "
  609. "Northbound CRC error on read data";
  610. break;
  611. case FERR_NF_M21ERR:
  612. specific = "FBD Northbound CRC error on "
  613. "FBD Sync Status";
  614. break;
  615. case FERR_NF_M22ERR:
  616. specific = "SPD protocol error";
  617. break;
  618. case FERR_NF_M27ERR:
  619. specific = "DIMM-spare copy started";
  620. break;
  621. case FERR_NF_M28ERR:
  622. specific = "DIMM-spare copy completed";
  623. break;
  624. }
  625. branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
  626. /* Form out message */
  627. snprintf(msg, sizeof(msg),
  628. "Err=%#x (%s)", misc_errors, specific);
  629. /* Call the helper to output message */
  630. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 0, 0, 0,
  631. branch >> 1, -1, -1,
  632. "Misc error", msg, NULL);
  633. }
  634. }
  635. /*
  636. * i5000_process_error_info Process the error info that is
  637. * in the 'info' structure, previously retrieved from hardware
  638. */
  639. static void i5000_process_error_info(struct mem_ctl_info *mci,
  640. struct i5000_error_info *info,
  641. int handle_errors)
  642. {
  643. /* First handle any fatal errors that occurred */
  644. i5000_process_fatal_error_info(mci, info, handle_errors);
  645. /* now handle any non-fatal errors that occurred */
  646. i5000_process_nonfatal_error_info(mci, info, handle_errors);
  647. }
  648. /*
  649. * i5000_clear_error Retrieve any error from the hardware
  650. * but do NOT process that error.
  651. * Used for 'clearing' out of previous errors
  652. * Called by the Core module.
  653. */
  654. static void i5000_clear_error(struct mem_ctl_info *mci)
  655. {
  656. struct i5000_error_info info;
  657. i5000_get_error_info(mci, &info);
  658. }
  659. /*
  660. * i5000_check_error Retrieve and process errors reported by the
  661. * hardware. Called by the Core module.
  662. */
  663. static void i5000_check_error(struct mem_ctl_info *mci)
  664. {
  665. struct i5000_error_info info;
  666. edac_dbg(4, "MC%d\n", mci->mc_idx);
  667. i5000_get_error_info(mci, &info);
  668. i5000_process_error_info(mci, &info, 1);
  669. }
  670. /*
  671. * i5000_get_devices Find and perform 'get' operation on the MCH's
  672. * device/functions we want to reference for this driver
  673. *
  674. * Need to 'get' device 16 func 1 and func 2
  675. */
  676. static int i5000_get_devices(struct mem_ctl_info *mci, int dev_idx)
  677. {
  678. //const struct i5000_dev_info *i5000_dev = &i5000_devs[dev_idx];
  679. struct i5000_pvt *pvt;
  680. struct pci_dev *pdev;
  681. pvt = mci->pvt_info;
  682. /* Attempt to 'get' the MCH register we want */
  683. pdev = NULL;
  684. while (1) {
  685. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  686. PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
  687. /* End of list, leave */
  688. if (pdev == NULL) {
  689. i5000_printk(KERN_ERR,
  690. "'system address,Process Bus' "
  691. "device not found:"
  692. "vendor 0x%x device 0x%x FUNC 1 "
  693. "(broken BIOS?)\n",
  694. PCI_VENDOR_ID_INTEL,
  695. PCI_DEVICE_ID_INTEL_I5000_DEV16);
  696. return 1;
  697. }
  698. /* Scan for device 16 func 1 */
  699. if (PCI_FUNC(pdev->devfn) == 1)
  700. break;
  701. }
  702. pvt->branchmap_werrors = pdev;
  703. /* Attempt to 'get' the MCH register we want */
  704. pdev = NULL;
  705. while (1) {
  706. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  707. PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
  708. if (pdev == NULL) {
  709. i5000_printk(KERN_ERR,
  710. "MC: 'branchmap,control,errors' "
  711. "device not found:"
  712. "vendor 0x%x device 0x%x Func 2 "
  713. "(broken BIOS?)\n",
  714. PCI_VENDOR_ID_INTEL,
  715. PCI_DEVICE_ID_INTEL_I5000_DEV16);
  716. pci_dev_put(pvt->branchmap_werrors);
  717. return 1;
  718. }
  719. /* Scan for device 16 func 1 */
  720. if (PCI_FUNC(pdev->devfn) == 2)
  721. break;
  722. }
  723. pvt->fsb_error_regs = pdev;
  724. edac_dbg(1, "System Address, processor bus- PCI Bus ID: %s %x:%x\n",
  725. pci_name(pvt->system_address),
  726. pvt->system_address->vendor, pvt->system_address->device);
  727. edac_dbg(1, "Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
  728. pci_name(pvt->branchmap_werrors),
  729. pvt->branchmap_werrors->vendor,
  730. pvt->branchmap_werrors->device);
  731. edac_dbg(1, "FSB Error Regs - PCI Bus ID: %s %x:%x\n",
  732. pci_name(pvt->fsb_error_regs),
  733. pvt->fsb_error_regs->vendor, pvt->fsb_error_regs->device);
  734. pdev = NULL;
  735. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  736. PCI_DEVICE_ID_I5000_BRANCH_0, pdev);
  737. if (pdev == NULL) {
  738. i5000_printk(KERN_ERR,
  739. "MC: 'BRANCH 0' device not found:"
  740. "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
  741. PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_I5000_BRANCH_0);
  742. pci_dev_put(pvt->branchmap_werrors);
  743. pci_dev_put(pvt->fsb_error_regs);
  744. return 1;
  745. }
  746. pvt->branch_0 = pdev;
  747. /* If this device claims to have more than 2 channels then
  748. * fetch Branch 1's information
  749. */
  750. if (pvt->maxch >= CHANNELS_PER_BRANCH) {
  751. pdev = NULL;
  752. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  753. PCI_DEVICE_ID_I5000_BRANCH_1, pdev);
  754. if (pdev == NULL) {
  755. i5000_printk(KERN_ERR,
  756. "MC: 'BRANCH 1' device not found:"
  757. "vendor 0x%x device 0x%x Func 0 "
  758. "(broken BIOS?)\n",
  759. PCI_VENDOR_ID_INTEL,
  760. PCI_DEVICE_ID_I5000_BRANCH_1);
  761. pci_dev_put(pvt->branchmap_werrors);
  762. pci_dev_put(pvt->fsb_error_regs);
  763. pci_dev_put(pvt->branch_0);
  764. return 1;
  765. }
  766. pvt->branch_1 = pdev;
  767. }
  768. return 0;
  769. }
  770. /*
  771. * i5000_put_devices 'put' all the devices that we have
  772. * reserved via 'get'
  773. */
  774. static void i5000_put_devices(struct mem_ctl_info *mci)
  775. {
  776. struct i5000_pvt *pvt;
  777. pvt = mci->pvt_info;
  778. pci_dev_put(pvt->branchmap_werrors); /* FUNC 1 */
  779. pci_dev_put(pvt->fsb_error_regs); /* FUNC 2 */
  780. pci_dev_put(pvt->branch_0); /* DEV 21 */
  781. /* Only if more than 2 channels do we release the second branch */
  782. if (pvt->maxch >= CHANNELS_PER_BRANCH)
  783. pci_dev_put(pvt->branch_1); /* DEV 22 */
  784. }
  785. /*
  786. * determine_amb_resent
  787. *
  788. * the information is contained in NUM_MTRS different registers
  789. * determineing which of the NUM_MTRS requires knowing
  790. * which channel is in question
  791. *
  792. * 2 branches, each with 2 channels
  793. * b0_ambpresent0 for channel '0'
  794. * b0_ambpresent1 for channel '1'
  795. * b1_ambpresent0 for channel '2'
  796. * b1_ambpresent1 for channel '3'
  797. */
  798. static int determine_amb_present_reg(struct i5000_pvt *pvt, int channel)
  799. {
  800. int amb_present;
  801. if (channel < CHANNELS_PER_BRANCH) {
  802. if (channel & 0x1)
  803. amb_present = pvt->b0_ambpresent1;
  804. else
  805. amb_present = pvt->b0_ambpresent0;
  806. } else {
  807. if (channel & 0x1)
  808. amb_present = pvt->b1_ambpresent1;
  809. else
  810. amb_present = pvt->b1_ambpresent0;
  811. }
  812. return amb_present;
  813. }
  814. /*
  815. * determine_mtr(pvt, csrow, channel)
  816. *
  817. * return the proper MTR register as determine by the csrow and channel desired
  818. */
  819. static int determine_mtr(struct i5000_pvt *pvt, int slot, int channel)
  820. {
  821. int mtr;
  822. if (channel < CHANNELS_PER_BRANCH)
  823. mtr = pvt->b0_mtr[slot];
  824. else
  825. mtr = pvt->b1_mtr[slot];
  826. return mtr;
  827. }
  828. /*
  829. */
  830. static void decode_mtr(int slot_row, u16 mtr)
  831. {
  832. int ans;
  833. ans = MTR_DIMMS_PRESENT(mtr);
  834. edac_dbg(2, "\tMTR%d=0x%x: DIMMs are %sPresent\n",
  835. slot_row, mtr, ans ? "" : "NOT ");
  836. if (!ans)
  837. return;
  838. edac_dbg(2, "\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
  839. edac_dbg(2, "\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
  840. edac_dbg(2, "\t\tNUMRANK: %s\n",
  841. MTR_DIMM_RANK(mtr) ? "double" : "single");
  842. edac_dbg(2, "\t\tNUMROW: %s\n",
  843. MTR_DIMM_ROWS(mtr) == 0 ? "8,192 - 13 rows" :
  844. MTR_DIMM_ROWS(mtr) == 1 ? "16,384 - 14 rows" :
  845. MTR_DIMM_ROWS(mtr) == 2 ? "32,768 - 15 rows" :
  846. "reserved");
  847. edac_dbg(2, "\t\tNUMCOL: %s\n",
  848. MTR_DIMM_COLS(mtr) == 0 ? "1,024 - 10 columns" :
  849. MTR_DIMM_COLS(mtr) == 1 ? "2,048 - 11 columns" :
  850. MTR_DIMM_COLS(mtr) == 2 ? "4,096 - 12 columns" :
  851. "reserved");
  852. }
  853. static void handle_channel(struct i5000_pvt *pvt, int slot, int channel,
  854. struct i5000_dimm_info *dinfo)
  855. {
  856. int mtr;
  857. int amb_present_reg;
  858. int addrBits;
  859. mtr = determine_mtr(pvt, slot, channel);
  860. if (MTR_DIMMS_PRESENT(mtr)) {
  861. amb_present_reg = determine_amb_present_reg(pvt, channel);
  862. /* Determine if there is a DIMM present in this DIMM slot */
  863. if (amb_present_reg) {
  864. dinfo->dual_rank = MTR_DIMM_RANK(mtr);
  865. /* Start with the number of bits for a Bank
  866. * on the DRAM */
  867. addrBits = MTR_DRAM_BANKS_ADDR_BITS(mtr);
  868. /* Add the number of ROW bits */
  869. addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
  870. /* add the number of COLUMN bits */
  871. addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
  872. addrBits += 6; /* add 64 bits per DIMM */
  873. addrBits -= 20; /* divide by 2^^20 */
  874. addrBits -= 3; /* 8 bits per bytes */
  875. dinfo->megabytes = 1 << addrBits;
  876. }
  877. }
  878. }
  879. /*
  880. * calculate_dimm_size
  881. *
  882. * also will output a DIMM matrix map, if debug is enabled, for viewing
  883. * how the DIMMs are populated
  884. */
  885. static void calculate_dimm_size(struct i5000_pvt *pvt)
  886. {
  887. struct i5000_dimm_info *dinfo;
  888. int slot, channel, branch;
  889. char *p, *mem_buffer;
  890. int space, n;
  891. /* ================= Generate some debug output ================= */
  892. space = PAGE_SIZE;
  893. mem_buffer = p = kmalloc(space, GFP_KERNEL);
  894. if (p == NULL) {
  895. i5000_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
  896. __FILE__, __func__);
  897. return;
  898. }
  899. /* Scan all the actual slots
  900. * and calculate the information for each DIMM
  901. * Start with the highest slot first, to display it first
  902. * and work toward the 0th slot
  903. */
  904. for (slot = pvt->maxdimmperch - 1; slot >= 0; slot--) {
  905. /* on an odd slot, first output a 'boundary' marker,
  906. * then reset the message buffer */
  907. if (slot & 0x1) {
  908. n = snprintf(p, space, "--------------------------"
  909. "--------------------------------");
  910. p += n;
  911. space -= n;
  912. edac_dbg(2, "%s\n", mem_buffer);
  913. p = mem_buffer;
  914. space = PAGE_SIZE;
  915. }
  916. n = snprintf(p, space, "slot %2d ", slot);
  917. p += n;
  918. space -= n;
  919. for (channel = 0; channel < pvt->maxch; channel++) {
  920. dinfo = &pvt->dimm_info[slot][channel];
  921. handle_channel(pvt, slot, channel, dinfo);
  922. if (dinfo->megabytes)
  923. n = snprintf(p, space, "%4d MB %dR| ",
  924. dinfo->megabytes, dinfo->dual_rank + 1);
  925. else
  926. n = snprintf(p, space, "%4d MB | ", 0);
  927. p += n;
  928. space -= n;
  929. }
  930. p += n;
  931. space -= n;
  932. edac_dbg(2, "%s\n", mem_buffer);
  933. p = mem_buffer;
  934. space = PAGE_SIZE;
  935. }
  936. /* Output the last bottom 'boundary' marker */
  937. n = snprintf(p, space, "--------------------------"
  938. "--------------------------------");
  939. p += n;
  940. space -= n;
  941. edac_dbg(2, "%s\n", mem_buffer);
  942. p = mem_buffer;
  943. space = PAGE_SIZE;
  944. /* now output the 'channel' labels */
  945. n = snprintf(p, space, " ");
  946. p += n;
  947. space -= n;
  948. for (channel = 0; channel < pvt->maxch; channel++) {
  949. n = snprintf(p, space, "channel %d | ", channel);
  950. p += n;
  951. space -= n;
  952. }
  953. edac_dbg(2, "%s\n", mem_buffer);
  954. p = mem_buffer;
  955. space = PAGE_SIZE;
  956. n = snprintf(p, space, " ");
  957. p += n;
  958. for (branch = 0; branch < MAX_BRANCHES; branch++) {
  959. n = snprintf(p, space, " branch %d | ", branch);
  960. p += n;
  961. space -= n;
  962. }
  963. /* output the last message and free buffer */
  964. edac_dbg(2, "%s\n", mem_buffer);
  965. kfree(mem_buffer);
  966. }
  967. /*
  968. * i5000_get_mc_regs read in the necessary registers and
  969. * cache locally
  970. *
  971. * Fills in the private data members
  972. */
  973. static void i5000_get_mc_regs(struct mem_ctl_info *mci)
  974. {
  975. struct i5000_pvt *pvt;
  976. u32 actual_tolm;
  977. u16 limit;
  978. int slot_row;
  979. int maxch;
  980. int maxdimmperch;
  981. int way0, way1;
  982. pvt = mci->pvt_info;
  983. pci_read_config_dword(pvt->system_address, AMBASE,
  984. (u32 *) & pvt->ambase);
  985. pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
  986. ((u32 *) & pvt->ambase) + sizeof(u32));
  987. maxdimmperch = pvt->maxdimmperch;
  988. maxch = pvt->maxch;
  989. edac_dbg(2, "AMBASE= 0x%lx MAXCH= %d MAX-DIMM-Per-CH= %d\n",
  990. (long unsigned int)pvt->ambase, pvt->maxch, pvt->maxdimmperch);
  991. /* Get the Branch Map regs */
  992. pci_read_config_word(pvt->branchmap_werrors, TOLM, &pvt->tolm);
  993. pvt->tolm >>= 12;
  994. edac_dbg(2, "TOLM (number of 256M regions) =%u (0x%x)\n",
  995. pvt->tolm, pvt->tolm);
  996. actual_tolm = pvt->tolm << 28;
  997. edac_dbg(2, "Actual TOLM byte addr=%u (0x%x)\n",
  998. actual_tolm, actual_tolm);
  999. pci_read_config_word(pvt->branchmap_werrors, MIR0, &pvt->mir0);
  1000. pci_read_config_word(pvt->branchmap_werrors, MIR1, &pvt->mir1);
  1001. pci_read_config_word(pvt->branchmap_werrors, MIR2, &pvt->mir2);
  1002. /* Get the MIR[0-2] regs */
  1003. limit = (pvt->mir0 >> 4) & 0x0FFF;
  1004. way0 = pvt->mir0 & 0x1;
  1005. way1 = pvt->mir0 & 0x2;
  1006. edac_dbg(2, "MIR0: limit= 0x%x WAY1= %u WAY0= %x\n",
  1007. limit, way1, way0);
  1008. limit = (pvt->mir1 >> 4) & 0x0FFF;
  1009. way0 = pvt->mir1 & 0x1;
  1010. way1 = pvt->mir1 & 0x2;
  1011. edac_dbg(2, "MIR1: limit= 0x%x WAY1= %u WAY0= %x\n",
  1012. limit, way1, way0);
  1013. limit = (pvt->mir2 >> 4) & 0x0FFF;
  1014. way0 = pvt->mir2 & 0x1;
  1015. way1 = pvt->mir2 & 0x2;
  1016. edac_dbg(2, "MIR2: limit= 0x%x WAY1= %u WAY0= %x\n",
  1017. limit, way1, way0);
  1018. /* Get the MTR[0-3] regs */
  1019. for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
  1020. int where = MTR0 + (slot_row * sizeof(u32));
  1021. pci_read_config_word(pvt->branch_0, where,
  1022. &pvt->b0_mtr[slot_row]);
  1023. edac_dbg(2, "MTR%d where=0x%x B0 value=0x%x\n",
  1024. slot_row, where, pvt->b0_mtr[slot_row]);
  1025. if (pvt->maxch >= CHANNELS_PER_BRANCH) {
  1026. pci_read_config_word(pvt->branch_1, where,
  1027. &pvt->b1_mtr[slot_row]);
  1028. edac_dbg(2, "MTR%d where=0x%x B1 value=0x%x\n",
  1029. slot_row, where, pvt->b1_mtr[slot_row]);
  1030. } else {
  1031. pvt->b1_mtr[slot_row] = 0;
  1032. }
  1033. }
  1034. /* Read and dump branch 0's MTRs */
  1035. edac_dbg(2, "Memory Technology Registers:\n");
  1036. edac_dbg(2, " Branch 0:\n");
  1037. for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
  1038. decode_mtr(slot_row, pvt->b0_mtr[slot_row]);
  1039. }
  1040. pci_read_config_word(pvt->branch_0, AMB_PRESENT_0,
  1041. &pvt->b0_ambpresent0);
  1042. edac_dbg(2, "\t\tAMB-Branch 0-present0 0x%x:\n", pvt->b0_ambpresent0);
  1043. pci_read_config_word(pvt->branch_0, AMB_PRESENT_1,
  1044. &pvt->b0_ambpresent1);
  1045. edac_dbg(2, "\t\tAMB-Branch 0-present1 0x%x:\n", pvt->b0_ambpresent1);
  1046. /* Only if we have 2 branchs (4 channels) */
  1047. if (pvt->maxch < CHANNELS_PER_BRANCH) {
  1048. pvt->b1_ambpresent0 = 0;
  1049. pvt->b1_ambpresent1 = 0;
  1050. } else {
  1051. /* Read and dump branch 1's MTRs */
  1052. edac_dbg(2, " Branch 1:\n");
  1053. for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
  1054. decode_mtr(slot_row, pvt->b1_mtr[slot_row]);
  1055. }
  1056. pci_read_config_word(pvt->branch_1, AMB_PRESENT_0,
  1057. &pvt->b1_ambpresent0);
  1058. edac_dbg(2, "\t\tAMB-Branch 1-present0 0x%x:\n",
  1059. pvt->b1_ambpresent0);
  1060. pci_read_config_word(pvt->branch_1, AMB_PRESENT_1,
  1061. &pvt->b1_ambpresent1);
  1062. edac_dbg(2, "\t\tAMB-Branch 1-present1 0x%x:\n",
  1063. pvt->b1_ambpresent1);
  1064. }
  1065. /* Go and determine the size of each DIMM and place in an
  1066. * orderly matrix */
  1067. calculate_dimm_size(pvt);
  1068. }
  1069. /*
  1070. * i5000_init_csrows Initialize the 'csrows' table within
  1071. * the mci control structure with the
  1072. * addressing of memory.
  1073. *
  1074. * return:
  1075. * 0 success
  1076. * 1 no actual memory found on this MC
  1077. */
  1078. static int i5000_init_csrows(struct mem_ctl_info *mci)
  1079. {
  1080. struct i5000_pvt *pvt;
  1081. struct dimm_info *dimm;
  1082. int empty, channel_count;
  1083. int max_csrows;
  1084. int mtr;
  1085. int csrow_megs;
  1086. int channel;
  1087. int slot;
  1088. pvt = mci->pvt_info;
  1089. channel_count = pvt->maxch;
  1090. max_csrows = pvt->maxdimmperch * 2;
  1091. empty = 1; /* Assume NO memory */
  1092. /*
  1093. * FIXME: The memory layout used to map slot/channel into the
  1094. * real memory architecture is weird: branch+slot are "csrows"
  1095. * and channel is channel. That required an extra array (dimm_info)
  1096. * to map the dimms. A good cleanup would be to remove this array,
  1097. * and do a loop here with branch, channel, slot
  1098. */
  1099. for (slot = 0; slot < max_csrows; slot++) {
  1100. for (channel = 0; channel < pvt->maxch; channel++) {
  1101. mtr = determine_mtr(pvt, slot, channel);
  1102. if (!MTR_DIMMS_PRESENT(mtr))
  1103. continue;
  1104. dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, mci->n_layers,
  1105. channel / MAX_BRANCHES,
  1106. channel % MAX_BRANCHES, slot);
  1107. csrow_megs = pvt->dimm_info[slot][channel].megabytes;
  1108. dimm->grain = 8;
  1109. /* Assume DDR2 for now */
  1110. dimm->mtype = MEM_FB_DDR2;
  1111. /* ask what device type on this row */
  1112. if (MTR_DRAM_WIDTH(mtr))
  1113. dimm->dtype = DEV_X8;
  1114. else
  1115. dimm->dtype = DEV_X4;
  1116. dimm->edac_mode = EDAC_S8ECD8ED;
  1117. dimm->nr_pages = csrow_megs << 8;
  1118. }
  1119. empty = 0;
  1120. }
  1121. return empty;
  1122. }
  1123. /*
  1124. * i5000_enable_error_reporting
  1125. * Turn on the memory reporting features of the hardware
  1126. */
  1127. static void i5000_enable_error_reporting(struct mem_ctl_info *mci)
  1128. {
  1129. struct i5000_pvt *pvt;
  1130. u32 fbd_error_mask;
  1131. pvt = mci->pvt_info;
  1132. /* Read the FBD Error Mask Register */
  1133. pci_read_config_dword(pvt->branchmap_werrors, EMASK_FBD,
  1134. &fbd_error_mask);
  1135. /* Enable with a '0' */
  1136. fbd_error_mask &= ~(ENABLE_EMASK_ALL);
  1137. pci_write_config_dword(pvt->branchmap_werrors, EMASK_FBD,
  1138. fbd_error_mask);
  1139. }
  1140. /*
  1141. * i5000_get_dimm_and_channel_counts(pdev, &nr_csrows, &num_channels)
  1142. *
  1143. * ask the device how many channels are present and how many CSROWS
  1144. * as well
  1145. */
  1146. static void i5000_get_dimm_and_channel_counts(struct pci_dev *pdev,
  1147. int *num_dimms_per_channel,
  1148. int *num_channels)
  1149. {
  1150. u8 value;
  1151. /* Need to retrieve just how many channels and dimms per channel are
  1152. * supported on this memory controller
  1153. */
  1154. pci_read_config_byte(pdev, MAXDIMMPERCH, &value);
  1155. *num_dimms_per_channel = (int)value;
  1156. pci_read_config_byte(pdev, MAXCH, &value);
  1157. *num_channels = (int)value;
  1158. }
  1159. /*
  1160. * i5000_probe1 Probe for ONE instance of device to see if it is
  1161. * present.
  1162. * return:
  1163. * 0 for FOUND a device
  1164. * < 0 for error code
  1165. */
  1166. static int i5000_probe1(struct pci_dev *pdev, int dev_idx)
  1167. {
  1168. struct mem_ctl_info *mci;
  1169. struct edac_mc_layer layers[3];
  1170. struct i5000_pvt *pvt;
  1171. int num_channels;
  1172. int num_dimms_per_channel;
  1173. edac_dbg(0, "MC: pdev bus %u dev=0x%x fn=0x%x\n",
  1174. pdev->bus->number,
  1175. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  1176. /* We only are looking for func 0 of the set */
  1177. if (PCI_FUNC(pdev->devfn) != 0)
  1178. return -ENODEV;
  1179. /* Ask the devices for the number of CSROWS and CHANNELS so
  1180. * that we can calculate the memory resources, etc
  1181. *
  1182. * The Chipset will report what it can handle which will be greater
  1183. * or equal to what the motherboard manufacturer will implement.
  1184. *
  1185. * As we don't have a motherboard identification routine to determine
  1186. * actual number of slots/dimms per channel, we thus utilize the
  1187. * resource as specified by the chipset. Thus, we might have
  1188. * have more DIMMs per channel than actually on the mobo, but this
  1189. * allows the driver to support up to the chipset max, without
  1190. * some fancy mobo determination.
  1191. */
  1192. i5000_get_dimm_and_channel_counts(pdev, &num_dimms_per_channel,
  1193. &num_channels);
  1194. edac_dbg(0, "MC: Number of Branches=2 Channels= %d DIMMS= %d\n",
  1195. num_channels, num_dimms_per_channel);
  1196. /* allocate a new MC control structure */
  1197. layers[0].type = EDAC_MC_LAYER_BRANCH;
  1198. layers[0].size = MAX_BRANCHES;
  1199. layers[0].is_virt_csrow = false;
  1200. layers[1].type = EDAC_MC_LAYER_CHANNEL;
  1201. layers[1].size = num_channels / MAX_BRANCHES;
  1202. layers[1].is_virt_csrow = false;
  1203. layers[2].type = EDAC_MC_LAYER_SLOT;
  1204. layers[2].size = num_dimms_per_channel;
  1205. layers[2].is_virt_csrow = true;
  1206. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
  1207. if (mci == NULL)
  1208. return -ENOMEM;
  1209. edac_dbg(0, "MC: mci = %p\n", mci);
  1210. mci->pdev = &pdev->dev; /* record ptr to the generic device */
  1211. pvt = mci->pvt_info;
  1212. pvt->system_address = pdev; /* Record this device in our private */
  1213. pvt->maxch = num_channels;
  1214. pvt->maxdimmperch = num_dimms_per_channel;
  1215. /* 'get' the pci devices we want to reserve for our use */
  1216. if (i5000_get_devices(mci, dev_idx))
  1217. goto fail0;
  1218. /* Time to get serious */
  1219. i5000_get_mc_regs(mci); /* retrieve the hardware registers */
  1220. mci->mc_idx = 0;
  1221. mci->mtype_cap = MEM_FLAG_FB_DDR2;
  1222. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  1223. mci->edac_cap = EDAC_FLAG_NONE;
  1224. mci->mod_name = "i5000_edac.c";
  1225. mci->mod_ver = I5000_REVISION;
  1226. mci->ctl_name = i5000_devs[dev_idx].ctl_name;
  1227. mci->dev_name = pci_name(pdev);
  1228. mci->ctl_page_to_phys = NULL;
  1229. /* Set the function pointer to an actual operation function */
  1230. mci->edac_check = i5000_check_error;
  1231. /* initialize the MC control structure 'csrows' table
  1232. * with the mapping and control information */
  1233. if (i5000_init_csrows(mci)) {
  1234. edac_dbg(0, "MC: Setting mci->edac_cap to EDAC_FLAG_NONE because i5000_init_csrows() returned nonzero value\n");
  1235. mci->edac_cap = EDAC_FLAG_NONE; /* no csrows found */
  1236. } else {
  1237. edac_dbg(1, "MC: Enable error reporting now\n");
  1238. i5000_enable_error_reporting(mci);
  1239. }
  1240. /* add this new MC control structure to EDAC's list of MCs */
  1241. if (edac_mc_add_mc(mci)) {
  1242. edac_dbg(0, "MC: failed edac_mc_add_mc()\n");
  1243. /* FIXME: perhaps some code should go here that disables error
  1244. * reporting if we just enabled it
  1245. */
  1246. goto fail1;
  1247. }
  1248. i5000_clear_error(mci);
  1249. /* allocating generic PCI control info */
  1250. i5000_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  1251. if (!i5000_pci) {
  1252. printk(KERN_WARNING
  1253. "%s(): Unable to create PCI control\n",
  1254. __func__);
  1255. printk(KERN_WARNING
  1256. "%s(): PCI error report via EDAC not setup\n",
  1257. __func__);
  1258. }
  1259. return 0;
  1260. /* Error exit unwinding stack */
  1261. fail1:
  1262. i5000_put_devices(mci);
  1263. fail0:
  1264. edac_mc_free(mci);
  1265. return -ENODEV;
  1266. }
  1267. /*
  1268. * i5000_init_one constructor for one instance of device
  1269. *
  1270. * returns:
  1271. * negative on error
  1272. * count (>= 0)
  1273. */
  1274. static int __devinit i5000_init_one(struct pci_dev *pdev,
  1275. const struct pci_device_id *id)
  1276. {
  1277. int rc;
  1278. edac_dbg(0, "MC:\n");
  1279. /* wake up device */
  1280. rc = pci_enable_device(pdev);
  1281. if (rc)
  1282. return rc;
  1283. /* now probe and enable the device */
  1284. return i5000_probe1(pdev, id->driver_data);
  1285. }
  1286. /*
  1287. * i5000_remove_one destructor for one instance of device
  1288. *
  1289. */
  1290. static void __devexit i5000_remove_one(struct pci_dev *pdev)
  1291. {
  1292. struct mem_ctl_info *mci;
  1293. edac_dbg(0, "\n");
  1294. if (i5000_pci)
  1295. edac_pci_release_generic_ctl(i5000_pci);
  1296. if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
  1297. return;
  1298. /* retrieve references to resources, and free those resources */
  1299. i5000_put_devices(mci);
  1300. edac_mc_free(mci);
  1301. }
  1302. /*
  1303. * pci_device_id table for which devices we are looking for
  1304. *
  1305. * The "E500P" device is the first device supported.
  1306. */
  1307. static DEFINE_PCI_DEVICE_TABLE(i5000_pci_tbl) = {
  1308. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
  1309. .driver_data = I5000P},
  1310. {0,} /* 0 terminated list. */
  1311. };
  1312. MODULE_DEVICE_TABLE(pci, i5000_pci_tbl);
  1313. /*
  1314. * i5000_driver pci_driver structure for this module
  1315. *
  1316. */
  1317. static struct pci_driver i5000_driver = {
  1318. .name = KBUILD_BASENAME,
  1319. .probe = i5000_init_one,
  1320. .remove = __devexit_p(i5000_remove_one),
  1321. .id_table = i5000_pci_tbl,
  1322. };
  1323. /*
  1324. * i5000_init Module entry function
  1325. * Try to initialize this module for its devices
  1326. */
  1327. static int __init i5000_init(void)
  1328. {
  1329. int pci_rc;
  1330. edac_dbg(2, "MC:\n");
  1331. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1332. opstate_init();
  1333. pci_rc = pci_register_driver(&i5000_driver);
  1334. return (pci_rc < 0) ? pci_rc : 0;
  1335. }
  1336. /*
  1337. * i5000_exit() Module exit function
  1338. * Unregister the driver
  1339. */
  1340. static void __exit i5000_exit(void)
  1341. {
  1342. edac_dbg(2, "MC:\n");
  1343. pci_unregister_driver(&i5000_driver);
  1344. }
  1345. module_init(i5000_init);
  1346. module_exit(i5000_exit);
  1347. MODULE_LICENSE("GPL");
  1348. MODULE_AUTHOR
  1349. ("Linux Networx (http://lnxi.com) Doug Thompson <norsk5@xmission.com>");
  1350. MODULE_DESCRIPTION("MC Driver for Intel I5000 memory controllers - "
  1351. I5000_REVISION);
  1352. module_param(edac_op_state, int, 0444);
  1353. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
  1354. module_param(misc_messages, int, 0444);
  1355. MODULE_PARM_DESC(misc_messages, "Log miscellaneous non fatal messages");