i5000_edac.c 41 KB

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