i5400_edac.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471
  1. /*
  2. * Intel 5400 class Memory Controllers kernel module (Seaburg)
  3. *
  4. * This file may be distributed under the terms of the
  5. * GNU General Public License.
  6. *
  7. * Copyright (c) 2008 by:
  8. * Ben Woodard <woodard@redhat.com>
  9. * Mauro Carvalho Chehab <mchehab@redhat.com>
  10. *
  11. * Red Hat Inc. http://www.redhat.com
  12. *
  13. * Forked and adapted from the i5000_edac driver which was
  14. * written by Douglas Thompson Linux Networx <norsk5@xmission.com>
  15. *
  16. * This module is based on the following document:
  17. *
  18. * Intel 5400 Chipset Memory Controller Hub (MCH) - Datasheet
  19. * http://developer.intel.com/design/chipsets/datashts/313070.htm
  20. *
  21. * This Memory Controller manages DDR2 FB-DIMMs. It has 2 branches, each with
  22. * 2 channels operating in lockstep no-mirror mode. Each channel can have up to
  23. * 4 dimm's, each with up to 8GB.
  24. *
  25. */
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/pci.h>
  29. #include <linux/pci_ids.h>
  30. #include <linux/slab.h>
  31. #include <linux/edac.h>
  32. #include <linux/mmzone.h>
  33. #include "edac_core.h"
  34. /*
  35. * Alter this version for the I5400 module when modifications are made
  36. */
  37. #define I5400_REVISION " Ver: 1.0.0"
  38. #define EDAC_MOD_STR "i5400_edac"
  39. #define i5400_printk(level, fmt, arg...) \
  40. edac_printk(level, "i5400", fmt, ##arg)
  41. #define i5400_mc_printk(mci, level, fmt, arg...) \
  42. edac_mc_chipset_printk(mci, level, "i5400", fmt, ##arg)
  43. /* Limits for i5400 */
  44. #define MAX_BRANCHES 2
  45. #define CHANNELS_PER_BRANCH 2
  46. #define DIMMS_PER_CHANNEL 4
  47. #define MAX_CHANNELS (MAX_BRANCHES * CHANNELS_PER_BRANCH)
  48. /* Device 16,
  49. * Function 0: System Address
  50. * Function 1: Memory Branch Map, Control, Errors Register
  51. * Function 2: FSB Error Registers
  52. *
  53. * All 3 functions of Device 16 (0,1,2) share the SAME DID and
  54. * uses PCI_DEVICE_ID_INTEL_5400_ERR for device 16 (0,1,2),
  55. * PCI_DEVICE_ID_INTEL_5400_FBD0 and PCI_DEVICE_ID_INTEL_5400_FBD1
  56. * for device 21 (0,1).
  57. */
  58. /* OFFSETS for Function 0 */
  59. #define AMBASE 0x48 /* AMB Mem Mapped Reg Region Base */
  60. #define MAXCH 0x56 /* Max Channel Number */
  61. #define MAXDIMMPERCH 0x57 /* Max DIMM PER Channel Number */
  62. /* OFFSETS for Function 1 */
  63. #define TOLM 0x6C
  64. #define REDMEMB 0x7C
  65. #define REC_ECC_LOCATOR_ODD(x) ((x) & 0x3fe00) /* bits [17:9] indicate ODD, [8:0] indicate EVEN */
  66. #define MIR0 0x80
  67. #define MIR1 0x84
  68. #define AMIR0 0x8c
  69. #define AMIR1 0x90
  70. /* Fatal error registers */
  71. #define FERR_FAT_FBD 0x98 /* also called as FERR_FAT_FB_DIMM at datasheet */
  72. #define FERR_FAT_FBDCHAN (3<<28) /* channel index where the highest-order error occurred */
  73. #define NERR_FAT_FBD 0x9c
  74. #define FERR_NF_FBD 0xa0 /* also called as FERR_NFAT_FB_DIMM at datasheet */
  75. /* Non-fatal error register */
  76. #define NERR_NF_FBD 0xa4
  77. /* Enable error mask */
  78. #define EMASK_FBD 0xa8
  79. #define ERR0_FBD 0xac
  80. #define ERR1_FBD 0xb0
  81. #define ERR2_FBD 0xb4
  82. #define MCERR_FBD 0xb8
  83. /* No OFFSETS for Device 16 Function 2 */
  84. /*
  85. * Device 21,
  86. * Function 0: Memory Map Branch 0
  87. *
  88. * Device 22,
  89. * Function 0: Memory Map Branch 1
  90. */
  91. /* OFFSETS for Function 0 */
  92. #define AMBPRESENT_0 0x64
  93. #define AMBPRESENT_1 0x66
  94. #define MTR0 0x80
  95. #define MTR1 0x82
  96. #define MTR2 0x84
  97. #define MTR3 0x86
  98. /* OFFSETS for Function 1 */
  99. #define NRECFGLOG 0x74
  100. #define RECFGLOG 0x78
  101. #define NRECMEMA 0xbe
  102. #define NRECMEMB 0xc0
  103. #define NRECFB_DIMMA 0xc4
  104. #define NRECFB_DIMMB 0xc8
  105. #define NRECFB_DIMMC 0xcc
  106. #define NRECFB_DIMMD 0xd0
  107. #define NRECFB_DIMME 0xd4
  108. #define NRECFB_DIMMF 0xd8
  109. #define REDMEMA 0xdC
  110. #define RECMEMA 0xf0
  111. #define RECMEMB 0xf4
  112. #define RECFB_DIMMA 0xf8
  113. #define RECFB_DIMMB 0xec
  114. #define RECFB_DIMMC 0xf0
  115. #define RECFB_DIMMD 0xf4
  116. #define RECFB_DIMME 0xf8
  117. #define RECFB_DIMMF 0xfC
  118. /*
  119. * Error indicator bits and masks
  120. * Error masks are according with Table 5-17 of i5400 datasheet
  121. */
  122. enum error_mask {
  123. EMASK_M1 = 1<<0, /* Memory Write error on non-redundant retry */
  124. EMASK_M2 = 1<<1, /* Memory or FB-DIMM configuration CRC read error */
  125. EMASK_M3 = 1<<2, /* Reserved */
  126. EMASK_M4 = 1<<3, /* Uncorrectable Data ECC on Replay */
  127. EMASK_M5 = 1<<4, /* Aliased Uncorrectable Non-Mirrored Demand Data ECC */
  128. EMASK_M6 = 1<<5, /* Unsupported on i5400 */
  129. EMASK_M7 = 1<<6, /* Aliased Uncorrectable Resilver- or Spare-Copy Data ECC */
  130. EMASK_M8 = 1<<7, /* Aliased Uncorrectable Patrol Data ECC */
  131. EMASK_M9 = 1<<8, /* Non-Aliased Uncorrectable Non-Mirrored Demand Data ECC */
  132. EMASK_M10 = 1<<9, /* Unsupported on i5400 */
  133. EMASK_M11 = 1<<10, /* Non-Aliased Uncorrectable Resilver- or Spare-Copy Data ECC */
  134. EMASK_M12 = 1<<11, /* Non-Aliased Uncorrectable Patrol Data ECC */
  135. EMASK_M13 = 1<<12, /* Memory Write error on first attempt */
  136. EMASK_M14 = 1<<13, /* FB-DIMM Configuration Write error on first attempt */
  137. EMASK_M15 = 1<<14, /* Memory or FB-DIMM configuration CRC read error */
  138. EMASK_M16 = 1<<15, /* Channel Failed-Over Occurred */
  139. EMASK_M17 = 1<<16, /* Correctable Non-Mirrored Demand Data ECC */
  140. EMASK_M18 = 1<<17, /* Unsupported on i5400 */
  141. EMASK_M19 = 1<<18, /* Correctable Resilver- or Spare-Copy Data ECC */
  142. EMASK_M20 = 1<<19, /* Correctable Patrol Data ECC */
  143. EMASK_M21 = 1<<20, /* FB-DIMM Northbound parity error on FB-DIMM Sync Status */
  144. EMASK_M22 = 1<<21, /* SPD protocol Error */
  145. EMASK_M23 = 1<<22, /* Non-Redundant Fast Reset Timeout */
  146. EMASK_M24 = 1<<23, /* Refresh error */
  147. EMASK_M25 = 1<<24, /* Memory Write error on redundant retry */
  148. EMASK_M26 = 1<<25, /* Redundant Fast Reset Timeout */
  149. EMASK_M27 = 1<<26, /* Correctable Counter Threshold Exceeded */
  150. EMASK_M28 = 1<<27, /* DIMM-Spare Copy Completed */
  151. EMASK_M29 = 1<<28, /* DIMM-Isolation Completed */
  152. };
  153. /*
  154. * Names to translate bit error into something useful
  155. */
  156. static const char *error_name[] = {
  157. [0] = "Memory Write error on non-redundant retry",
  158. [1] = "Memory or FB-DIMM configuration CRC read error",
  159. /* Reserved */
  160. [3] = "Uncorrectable Data ECC on Replay",
  161. [4] = "Aliased Uncorrectable Non-Mirrored Demand Data ECC",
  162. /* M6 Unsupported on i5400 */
  163. [6] = "Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
  164. [7] = "Aliased Uncorrectable Patrol Data ECC",
  165. [8] = "Non-Aliased Uncorrectable Non-Mirrored Demand Data ECC",
  166. /* M10 Unsupported on i5400 */
  167. [10] = "Non-Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
  168. [11] = "Non-Aliased Uncorrectable Patrol Data ECC",
  169. [12] = "Memory Write error on first attempt",
  170. [13] = "FB-DIMM Configuration Write error on first attempt",
  171. [14] = "Memory or FB-DIMM configuration CRC read error",
  172. [15] = "Channel Failed-Over Occurred",
  173. [16] = "Correctable Non-Mirrored Demand Data ECC",
  174. /* M18 Unsupported on i5400 */
  175. [18] = "Correctable Resilver- or Spare-Copy Data ECC",
  176. [19] = "Correctable Patrol Data ECC",
  177. [20] = "FB-DIMM Northbound parity error on FB-DIMM Sync Status",
  178. [21] = "SPD protocol Error",
  179. [22] = "Non-Redundant Fast Reset Timeout",
  180. [23] = "Refresh error",
  181. [24] = "Memory Write error on redundant retry",
  182. [25] = "Redundant Fast Reset Timeout",
  183. [26] = "Correctable Counter Threshold Exceeded",
  184. [27] = "DIMM-Spare Copy Completed",
  185. [28] = "DIMM-Isolation Completed",
  186. };
  187. /* Fatal errors */
  188. #define ERROR_FAT_MASK (EMASK_M1 | \
  189. EMASK_M2 | \
  190. EMASK_M23)
  191. /* Correctable errors */
  192. #define ERROR_NF_CORRECTABLE (EMASK_M27 | \
  193. EMASK_M20 | \
  194. EMASK_M19 | \
  195. EMASK_M18 | \
  196. EMASK_M17 | \
  197. EMASK_M16)
  198. #define ERROR_NF_DIMM_SPARE (EMASK_M29 | \
  199. EMASK_M28)
  200. #define ERROR_NF_SPD_PROTOCOL (EMASK_M22)
  201. #define ERROR_NF_NORTH_CRC (EMASK_M21)
  202. /* Recoverable errors */
  203. #define ERROR_NF_RECOVERABLE (EMASK_M26 | \
  204. EMASK_M25 | \
  205. EMASK_M24 | \
  206. EMASK_M15 | \
  207. EMASK_M14 | \
  208. EMASK_M13 | \
  209. EMASK_M12 | \
  210. EMASK_M11 | \
  211. EMASK_M9 | \
  212. EMASK_M8 | \
  213. EMASK_M7 | \
  214. EMASK_M5)
  215. /* uncorrectable errors */
  216. #define ERROR_NF_UNCORRECTABLE (EMASK_M4)
  217. /* mask to all non-fatal errors */
  218. #define ERROR_NF_MASK (ERROR_NF_CORRECTABLE | \
  219. ERROR_NF_UNCORRECTABLE | \
  220. ERROR_NF_RECOVERABLE | \
  221. ERROR_NF_DIMM_SPARE | \
  222. ERROR_NF_SPD_PROTOCOL | \
  223. ERROR_NF_NORTH_CRC)
  224. /*
  225. * Define error masks for the several registers
  226. */
  227. /* Enable all fatal and non fatal errors */
  228. #define ENABLE_EMASK_ALL (ERROR_FAT_MASK | ERROR_NF_MASK)
  229. /* mask for fatal error registers */
  230. #define FERR_FAT_MASK ERROR_FAT_MASK
  231. /* masks for non-fatal error register */
  232. static inline int to_nf_mask(unsigned int mask)
  233. {
  234. return (mask & EMASK_M29) | (mask >> 3);
  235. };
  236. static inline int from_nf_ferr(unsigned int mask)
  237. {
  238. return (mask & EMASK_M29) | /* Bit 28 */
  239. (mask & ((1 << 28) - 1) << 3); /* Bits 0 to 27 */
  240. };
  241. #define FERR_NF_MASK to_nf_mask(ERROR_NF_MASK)
  242. #define FERR_NF_CORRECTABLE to_nf_mask(ERROR_NF_CORRECTABLE)
  243. #define FERR_NF_DIMM_SPARE to_nf_mask(ERROR_NF_DIMM_SPARE)
  244. #define FERR_NF_SPD_PROTOCOL to_nf_mask(ERROR_NF_SPD_PROTOCOL)
  245. #define FERR_NF_NORTH_CRC to_nf_mask(ERROR_NF_NORTH_CRC)
  246. #define FERR_NF_RECOVERABLE to_nf_mask(ERROR_NF_RECOVERABLE)
  247. #define FERR_NF_UNCORRECTABLE to_nf_mask(ERROR_NF_UNCORRECTABLE)
  248. /* Defines to extract the vaious fields from the
  249. * MTRx - Memory Technology Registers
  250. */
  251. #define MTR_DIMMS_PRESENT(mtr) ((mtr) & (1 << 10))
  252. #define MTR_DIMMS_ETHROTTLE(mtr) ((mtr) & (1 << 9))
  253. #define MTR_DRAM_WIDTH(mtr) (((mtr) & (1 << 8)) ? 8 : 4)
  254. #define MTR_DRAM_BANKS(mtr) (((mtr) & (1 << 6)) ? 8 : 4)
  255. #define MTR_DRAM_BANKS_ADDR_BITS(mtr) ((MTR_DRAM_BANKS(mtr) == 8) ? 3 : 2)
  256. #define MTR_DIMM_RANK(mtr) (((mtr) >> 5) & 0x1)
  257. #define MTR_DIMM_RANK_ADDR_BITS(mtr) (MTR_DIMM_RANK(mtr) ? 2 : 1)
  258. #define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
  259. #define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
  260. #define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
  261. #define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
  262. /* This applies to FERR_NF_FB-DIMM as well as FERR_FAT_FB-DIMM */
  263. static inline int extract_fbdchan_indx(u32 x)
  264. {
  265. return (x>>28) & 0x3;
  266. }
  267. /* Device name and register DID (Device ID) */
  268. struct i5400_dev_info {
  269. const char *ctl_name; /* name for this device */
  270. u16 fsb_mapping_errors; /* DID for the branchmap,control */
  271. };
  272. /* Table of devices attributes supported by this driver */
  273. static const struct i5400_dev_info i5400_devs[] = {
  274. {
  275. .ctl_name = "I5400",
  276. .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_5400_ERR,
  277. },
  278. };
  279. struct i5400_dimm_info {
  280. int megabytes; /* size, 0 means not present */
  281. };
  282. /* driver private data structure */
  283. struct i5400_pvt {
  284. struct pci_dev *system_address; /* 16.0 */
  285. struct pci_dev *branchmap_werrors; /* 16.1 */
  286. struct pci_dev *fsb_error_regs; /* 16.2 */
  287. struct pci_dev *branch_0; /* 21.0 */
  288. struct pci_dev *branch_1; /* 22.0 */
  289. u16 tolm; /* top of low memory */
  290. u64 ambase; /* AMB BAR */
  291. u16 mir0, mir1;
  292. u16 b0_mtr[DIMMS_PER_CHANNEL]; /* Memory Technlogy Reg */
  293. u16 b0_ambpresent0; /* Branch 0, Channel 0 */
  294. u16 b0_ambpresent1; /* Brnach 0, Channel 1 */
  295. u16 b1_mtr[DIMMS_PER_CHANNEL]; /* Memory Technlogy Reg */
  296. u16 b1_ambpresent0; /* Branch 1, Channel 8 */
  297. u16 b1_ambpresent1; /* Branch 1, Channel 1 */
  298. /* DIMM information matrix, allocating architecture maximums */
  299. struct i5400_dimm_info dimm_info[DIMMS_PER_CHANNEL][MAX_CHANNELS];
  300. /* Actual values for this controller */
  301. int maxch; /* Max channels */
  302. int maxdimmperch; /* Max DIMMs per channel */
  303. };
  304. /* I5400 MCH error information retrieved from Hardware */
  305. struct i5400_error_info {
  306. /* These registers are always read from the MC */
  307. u32 ferr_fat_fbd; /* First Errors Fatal */
  308. u32 nerr_fat_fbd; /* Next Errors Fatal */
  309. u32 ferr_nf_fbd; /* First Errors Non-Fatal */
  310. u32 nerr_nf_fbd; /* Next Errors Non-Fatal */
  311. /* These registers are input ONLY if there was a Recoverable Error */
  312. u32 redmemb; /* Recoverable Mem Data Error log B */
  313. u16 recmema; /* Recoverable Mem Error log A */
  314. u32 recmemb; /* Recoverable Mem Error log B */
  315. /* These registers are input ONLY if there was a Non-Rec Error */
  316. u16 nrecmema; /* Non-Recoverable Mem log A */
  317. u16 nrecmemb; /* Non-Recoverable Mem log B */
  318. };
  319. /* note that nrec_rdwr changed from NRECMEMA to NRECMEMB between the 5000 and
  320. 5400 better to use an inline function than a macro in this case */
  321. static inline int nrec_bank(struct i5400_error_info *info)
  322. {
  323. return ((info->nrecmema) >> 12) & 0x7;
  324. }
  325. static inline int nrec_rank(struct i5400_error_info *info)
  326. {
  327. return ((info->nrecmema) >> 8) & 0xf;
  328. }
  329. static inline int nrec_buf_id(struct i5400_error_info *info)
  330. {
  331. return ((info->nrecmema)) & 0xff;
  332. }
  333. static inline int nrec_rdwr(struct i5400_error_info *info)
  334. {
  335. return (info->nrecmemb) >> 31;
  336. }
  337. /* This applies to both NREC and REC string so it can be used with nrec_rdwr
  338. and rec_rdwr */
  339. static inline const char *rdwr_str(int rdwr)
  340. {
  341. return rdwr ? "Write" : "Read";
  342. }
  343. static inline int nrec_cas(struct i5400_error_info *info)
  344. {
  345. return ((info->nrecmemb) >> 16) & 0x1fff;
  346. }
  347. static inline int nrec_ras(struct i5400_error_info *info)
  348. {
  349. return (info->nrecmemb) & 0xffff;
  350. }
  351. static inline int rec_bank(struct i5400_error_info *info)
  352. {
  353. return ((info->recmema) >> 12) & 0x7;
  354. }
  355. static inline int rec_rank(struct i5400_error_info *info)
  356. {
  357. return ((info->recmema) >> 8) & 0xf;
  358. }
  359. static inline int rec_rdwr(struct i5400_error_info *info)
  360. {
  361. return (info->recmemb) >> 31;
  362. }
  363. static inline int rec_cas(struct i5400_error_info *info)
  364. {
  365. return ((info->recmemb) >> 16) & 0x1fff;
  366. }
  367. static inline int rec_ras(struct i5400_error_info *info)
  368. {
  369. return (info->recmemb) & 0xffff;
  370. }
  371. static struct edac_pci_ctl_info *i5400_pci;
  372. /*
  373. * i5400_get_error_info Retrieve the hardware error information from
  374. * the hardware and cache it in the 'info'
  375. * structure
  376. */
  377. static void i5400_get_error_info(struct mem_ctl_info *mci,
  378. struct i5400_error_info *info)
  379. {
  380. struct i5400_pvt *pvt;
  381. u32 value;
  382. pvt = mci->pvt_info;
  383. /* read in the 1st FATAL error register */
  384. pci_read_config_dword(pvt->branchmap_werrors, FERR_FAT_FBD, &value);
  385. /* Mask only the bits that the doc says are valid
  386. */
  387. value &= (FERR_FAT_FBDCHAN | FERR_FAT_MASK);
  388. /* If there is an error, then read in the
  389. NEXT FATAL error register and the Memory Error Log Register A
  390. */
  391. if (value & FERR_FAT_MASK) {
  392. info->ferr_fat_fbd = value;
  393. /* harvest the various error data we need */
  394. pci_read_config_dword(pvt->branchmap_werrors,
  395. NERR_FAT_FBD, &info->nerr_fat_fbd);
  396. pci_read_config_word(pvt->branchmap_werrors,
  397. NRECMEMA, &info->nrecmema);
  398. pci_read_config_word(pvt->branchmap_werrors,
  399. NRECMEMB, &info->nrecmemb);
  400. /* Clear the error bits, by writing them back */
  401. pci_write_config_dword(pvt->branchmap_werrors,
  402. FERR_FAT_FBD, value);
  403. } else {
  404. info->ferr_fat_fbd = 0;
  405. info->nerr_fat_fbd = 0;
  406. info->nrecmema = 0;
  407. info->nrecmemb = 0;
  408. }
  409. /* read in the 1st NON-FATAL error register */
  410. pci_read_config_dword(pvt->branchmap_werrors, FERR_NF_FBD, &value);
  411. /* If there is an error, then read in the 1st NON-FATAL error
  412. * register as well */
  413. if (value & FERR_NF_MASK) {
  414. info->ferr_nf_fbd = value;
  415. /* harvest the various error data we need */
  416. pci_read_config_dword(pvt->branchmap_werrors,
  417. NERR_NF_FBD, &info->nerr_nf_fbd);
  418. pci_read_config_word(pvt->branchmap_werrors,
  419. RECMEMA, &info->recmema);
  420. pci_read_config_dword(pvt->branchmap_werrors,
  421. RECMEMB, &info->recmemb);
  422. pci_read_config_dword(pvt->branchmap_werrors,
  423. REDMEMB, &info->redmemb);
  424. /* Clear the error bits, by writing them back */
  425. pci_write_config_dword(pvt->branchmap_werrors,
  426. FERR_NF_FBD, value);
  427. } else {
  428. info->ferr_nf_fbd = 0;
  429. info->nerr_nf_fbd = 0;
  430. info->recmema = 0;
  431. info->recmemb = 0;
  432. info->redmemb = 0;
  433. }
  434. }
  435. /*
  436. * i5400_proccess_non_recoverable_info(struct mem_ctl_info *mci,
  437. * struct i5400_error_info *info,
  438. * int handle_errors);
  439. *
  440. * handle the Intel FATAL and unrecoverable errors, if any
  441. */
  442. static void i5400_proccess_non_recoverable_info(struct mem_ctl_info *mci,
  443. struct i5400_error_info *info,
  444. unsigned long allErrors)
  445. {
  446. char msg[EDAC_MC_LABEL_LEN + 1 + 90 + 80];
  447. int branch;
  448. int channel;
  449. int bank;
  450. int buf_id;
  451. int rank;
  452. int rdwr;
  453. int ras, cas;
  454. int errnum;
  455. char *type = NULL;
  456. enum hw_event_mc_err_type tp_event = HW_EVENT_ERR_UNCORRECTED;
  457. if (!allErrors)
  458. return; /* if no error, return now */
  459. if (allErrors & ERROR_FAT_MASK) {
  460. type = "FATAL";
  461. tp_event = HW_EVENT_ERR_FATAL;
  462. } else if (allErrors & FERR_NF_UNCORRECTABLE)
  463. type = "NON-FATAL uncorrected";
  464. else
  465. type = "NON-FATAL recoverable";
  466. /* ONLY ONE of the possible error bits will be set, as per the docs */
  467. branch = extract_fbdchan_indx(info->ferr_fat_fbd);
  468. channel = branch;
  469. /* Use the NON-Recoverable macros to extract data */
  470. bank = nrec_bank(info);
  471. rank = nrec_rank(info);
  472. buf_id = nrec_buf_id(info);
  473. rdwr = nrec_rdwr(info);
  474. ras = nrec_ras(info);
  475. cas = nrec_cas(info);
  476. edac_dbg(0, "\t\tDIMM= %d Channels= %d,%d (Branch= %d DRAM Bank= %d Buffer ID = %d rdwr= %s ras= %d cas= %d)\n",
  477. rank, channel, channel + 1, branch >> 1, bank,
  478. buf_id, rdwr_str(rdwr), ras, cas);
  479. /* Only 1 bit will be on */
  480. errnum = find_first_bit(&allErrors, ARRAY_SIZE(error_name));
  481. /* Form out message */
  482. snprintf(msg, sizeof(msg),
  483. "Bank=%d Buffer ID = %d RAS=%d CAS=%d Err=0x%lx (%s)",
  484. bank, buf_id, ras, cas, allErrors, error_name[errnum]);
  485. edac_mc_handle_error(tp_event, mci, 0, 0, 0,
  486. branch >> 1, -1, rank,
  487. rdwr ? "Write error" : "Read error",
  488. msg, NULL);
  489. }
  490. /*
  491. * i5400_process_fatal_error_info(struct mem_ctl_info *mci,
  492. * struct i5400_error_info *info,
  493. * int handle_errors);
  494. *
  495. * handle the Intel NON-FATAL errors, if any
  496. */
  497. static void i5400_process_nonfatal_error_info(struct mem_ctl_info *mci,
  498. struct i5400_error_info *info)
  499. {
  500. char msg[EDAC_MC_LABEL_LEN + 1 + 90 + 80];
  501. unsigned long allErrors;
  502. int branch;
  503. int channel;
  504. int bank;
  505. int rank;
  506. int rdwr;
  507. int ras, cas;
  508. int errnum;
  509. /* mask off the Error bits that are possible */
  510. allErrors = from_nf_ferr(info->ferr_nf_fbd & FERR_NF_MASK);
  511. if (!allErrors)
  512. return; /* if no error, return now */
  513. /* ONLY ONE of the possible error bits will be set, as per the docs */
  514. if (allErrors & (ERROR_NF_UNCORRECTABLE | ERROR_NF_RECOVERABLE)) {
  515. i5400_proccess_non_recoverable_info(mci, info, allErrors);
  516. return;
  517. }
  518. /* Correctable errors */
  519. if (allErrors & ERROR_NF_CORRECTABLE) {
  520. edac_dbg(0, "\tCorrected bits= 0x%lx\n", allErrors);
  521. branch = extract_fbdchan_indx(info->ferr_nf_fbd);
  522. channel = 0;
  523. if (REC_ECC_LOCATOR_ODD(info->redmemb))
  524. channel = 1;
  525. /* Convert channel to be based from zero, instead of
  526. * from branch base of 0 */
  527. channel += branch;
  528. bank = rec_bank(info);
  529. rank = rec_rank(info);
  530. rdwr = rec_rdwr(info);
  531. ras = rec_ras(info);
  532. cas = rec_cas(info);
  533. /* Only 1 bit will be on */
  534. errnum = find_first_bit(&allErrors, ARRAY_SIZE(error_name));
  535. edac_dbg(0, "\t\tDIMM= %d Channel= %d (Branch %d DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  536. rank, channel, branch >> 1, bank,
  537. rdwr_str(rdwr), ras, cas);
  538. /* Form out message */
  539. snprintf(msg, sizeof(msg),
  540. "Corrected error (Branch=%d DRAM-Bank=%d RDWR=%s "
  541. "RAS=%d CAS=%d, CE Err=0x%lx (%s))",
  542. branch >> 1, bank, rdwr_str(rdwr), ras, cas,
  543. allErrors, error_name[errnum]);
  544. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 0, 0, 0,
  545. branch >> 1, channel % 2, rank,
  546. rdwr ? "Write error" : "Read error",
  547. msg, NULL);
  548. return;
  549. }
  550. /* Miscellaneous errors */
  551. errnum = find_first_bit(&allErrors, ARRAY_SIZE(error_name));
  552. branch = extract_fbdchan_indx(info->ferr_nf_fbd);
  553. i5400_mc_printk(mci, KERN_EMERG,
  554. "Non-Fatal misc error (Branch=%d Err=%#lx (%s))",
  555. branch >> 1, allErrors, error_name[errnum]);
  556. }
  557. /*
  558. * i5400_process_error_info Process the error info that is
  559. * in the 'info' structure, previously retrieved from hardware
  560. */
  561. static void i5400_process_error_info(struct mem_ctl_info *mci,
  562. struct i5400_error_info *info)
  563. { u32 allErrors;
  564. /* First handle any fatal errors that occurred */
  565. allErrors = (info->ferr_fat_fbd & FERR_FAT_MASK);
  566. i5400_proccess_non_recoverable_info(mci, info, allErrors);
  567. /* now handle any non-fatal errors that occurred */
  568. i5400_process_nonfatal_error_info(mci, info);
  569. }
  570. /*
  571. * i5400_clear_error Retrieve any error from the hardware
  572. * but do NOT process that error.
  573. * Used for 'clearing' out of previous errors
  574. * Called by the Core module.
  575. */
  576. static void i5400_clear_error(struct mem_ctl_info *mci)
  577. {
  578. struct i5400_error_info info;
  579. i5400_get_error_info(mci, &info);
  580. }
  581. /*
  582. * i5400_check_error Retrieve and process errors reported by the
  583. * hardware. Called by the Core module.
  584. */
  585. static void i5400_check_error(struct mem_ctl_info *mci)
  586. {
  587. struct i5400_error_info info;
  588. edac_dbg(4, "MC%d\n", mci->mc_idx);
  589. i5400_get_error_info(mci, &info);
  590. i5400_process_error_info(mci, &info);
  591. }
  592. /*
  593. * i5400_put_devices 'put' all the devices that we have
  594. * reserved via 'get'
  595. */
  596. static void i5400_put_devices(struct mem_ctl_info *mci)
  597. {
  598. struct i5400_pvt *pvt;
  599. pvt = mci->pvt_info;
  600. /* Decrement usage count for devices */
  601. pci_dev_put(pvt->branch_1);
  602. pci_dev_put(pvt->branch_0);
  603. pci_dev_put(pvt->fsb_error_regs);
  604. pci_dev_put(pvt->branchmap_werrors);
  605. }
  606. /*
  607. * i5400_get_devices Find and perform 'get' operation on the MCH's
  608. * device/functions we want to reference for this driver
  609. *
  610. * Need to 'get' device 16 func 1 and func 2
  611. */
  612. static int i5400_get_devices(struct mem_ctl_info *mci, int dev_idx)
  613. {
  614. struct i5400_pvt *pvt;
  615. struct pci_dev *pdev;
  616. pvt = mci->pvt_info;
  617. pvt->branchmap_werrors = NULL;
  618. pvt->fsb_error_regs = NULL;
  619. pvt->branch_0 = NULL;
  620. pvt->branch_1 = NULL;
  621. /* Attempt to 'get' the MCH register we want */
  622. pdev = NULL;
  623. while (1) {
  624. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  625. PCI_DEVICE_ID_INTEL_5400_ERR, pdev);
  626. if (!pdev) {
  627. /* End of list, leave */
  628. i5400_printk(KERN_ERR,
  629. "'system address,Process Bus' "
  630. "device not found:"
  631. "vendor 0x%x device 0x%x ERR func 1 "
  632. "(broken BIOS?)\n",
  633. PCI_VENDOR_ID_INTEL,
  634. PCI_DEVICE_ID_INTEL_5400_ERR);
  635. return -ENODEV;
  636. }
  637. /* Store device 16 func 1 */
  638. if (PCI_FUNC(pdev->devfn) == 1)
  639. break;
  640. }
  641. pvt->branchmap_werrors = pdev;
  642. pdev = NULL;
  643. while (1) {
  644. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  645. PCI_DEVICE_ID_INTEL_5400_ERR, pdev);
  646. if (!pdev) {
  647. /* End of list, leave */
  648. i5400_printk(KERN_ERR,
  649. "'system address,Process Bus' "
  650. "device not found:"
  651. "vendor 0x%x device 0x%x ERR func 2 "
  652. "(broken BIOS?)\n",
  653. PCI_VENDOR_ID_INTEL,
  654. PCI_DEVICE_ID_INTEL_5400_ERR);
  655. pci_dev_put(pvt->branchmap_werrors);
  656. return -ENODEV;
  657. }
  658. /* Store device 16 func 2 */
  659. if (PCI_FUNC(pdev->devfn) == 2)
  660. break;
  661. }
  662. pvt->fsb_error_regs = pdev;
  663. edac_dbg(1, "System Address, processor bus- PCI Bus ID: %s %x:%x\n",
  664. pci_name(pvt->system_address),
  665. pvt->system_address->vendor, pvt->system_address->device);
  666. edac_dbg(1, "Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
  667. pci_name(pvt->branchmap_werrors),
  668. pvt->branchmap_werrors->vendor,
  669. pvt->branchmap_werrors->device);
  670. edac_dbg(1, "FSB Error Regs - PCI Bus ID: %s %x:%x\n",
  671. pci_name(pvt->fsb_error_regs),
  672. pvt->fsb_error_regs->vendor, pvt->fsb_error_regs->device);
  673. pvt->branch_0 = pci_get_device(PCI_VENDOR_ID_INTEL,
  674. PCI_DEVICE_ID_INTEL_5400_FBD0, NULL);
  675. if (!pvt->branch_0) {
  676. i5400_printk(KERN_ERR,
  677. "MC: 'BRANCH 0' device not found:"
  678. "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
  679. PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_FBD0);
  680. pci_dev_put(pvt->fsb_error_regs);
  681. pci_dev_put(pvt->branchmap_werrors);
  682. return -ENODEV;
  683. }
  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. return 0;
  689. pvt->branch_1 = pci_get_device(PCI_VENDOR_ID_INTEL,
  690. PCI_DEVICE_ID_INTEL_5400_FBD1, NULL);
  691. if (!pvt->branch_1) {
  692. i5400_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_INTEL_5400_FBD1);
  698. pci_dev_put(pvt->branch_0);
  699. pci_dev_put(pvt->fsb_error_regs);
  700. pci_dev_put(pvt->branchmap_werrors);
  701. return -ENODEV;
  702. }
  703. return 0;
  704. }
  705. /*
  706. * determine_amb_present
  707. *
  708. * the information is contained in DIMMS_PER_CHANNEL different
  709. * registers determining which of the DIMMS_PER_CHANNEL requires
  710. * knowing which channel is in question
  711. *
  712. * 2 branches, each with 2 channels
  713. * b0_ambpresent0 for channel '0'
  714. * b0_ambpresent1 for channel '1'
  715. * b1_ambpresent0 for channel '2'
  716. * b1_ambpresent1 for channel '3'
  717. */
  718. static int determine_amb_present_reg(struct i5400_pvt *pvt, int channel)
  719. {
  720. int amb_present;
  721. if (channel < CHANNELS_PER_BRANCH) {
  722. if (channel & 0x1)
  723. amb_present = pvt->b0_ambpresent1;
  724. else
  725. amb_present = pvt->b0_ambpresent0;
  726. } else {
  727. if (channel & 0x1)
  728. amb_present = pvt->b1_ambpresent1;
  729. else
  730. amb_present = pvt->b1_ambpresent0;
  731. }
  732. return amb_present;
  733. }
  734. /*
  735. * determine_mtr(pvt, dimm, channel)
  736. *
  737. * return the proper MTR register as determine by the dimm and desired channel
  738. */
  739. static int determine_mtr(struct i5400_pvt *pvt, int dimm, int channel)
  740. {
  741. int mtr;
  742. int n;
  743. /* There is one MTR for each slot pair of FB-DIMMs,
  744. Each slot pair may be at branch 0 or branch 1.
  745. */
  746. n = dimm;
  747. if (n >= DIMMS_PER_CHANNEL) {
  748. edac_dbg(0, "ERROR: trying to access an invalid dimm: %d\n",
  749. dimm);
  750. return 0;
  751. }
  752. if (channel < CHANNELS_PER_BRANCH)
  753. mtr = pvt->b0_mtr[n];
  754. else
  755. mtr = pvt->b1_mtr[n];
  756. return mtr;
  757. }
  758. /*
  759. */
  760. static void decode_mtr(int slot_row, u16 mtr)
  761. {
  762. int ans;
  763. ans = MTR_DIMMS_PRESENT(mtr);
  764. edac_dbg(2, "\tMTR%d=0x%x: DIMMs are %sPresent\n",
  765. slot_row, mtr, ans ? "" : "NOT ");
  766. if (!ans)
  767. return;
  768. edac_dbg(2, "\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
  769. edac_dbg(2, "\t\tELECTRICAL THROTTLING is %s\n",
  770. MTR_DIMMS_ETHROTTLE(mtr) ? "enabled" : "disabled");
  771. edac_dbg(2, "\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
  772. edac_dbg(2, "\t\tNUMRANK: %s\n",
  773. MTR_DIMM_RANK(mtr) ? "double" : "single");
  774. edac_dbg(2, "\t\tNUMROW: %s\n",
  775. MTR_DIMM_ROWS(mtr) == 0 ? "8,192 - 13 rows" :
  776. MTR_DIMM_ROWS(mtr) == 1 ? "16,384 - 14 rows" :
  777. MTR_DIMM_ROWS(mtr) == 2 ? "32,768 - 15 rows" :
  778. "65,536 - 16 rows");
  779. edac_dbg(2, "\t\tNUMCOL: %s\n",
  780. MTR_DIMM_COLS(mtr) == 0 ? "1,024 - 10 columns" :
  781. MTR_DIMM_COLS(mtr) == 1 ? "2,048 - 11 columns" :
  782. MTR_DIMM_COLS(mtr) == 2 ? "4,096 - 12 columns" :
  783. "reserved");
  784. }
  785. static void handle_channel(struct i5400_pvt *pvt, int dimm, int channel,
  786. struct i5400_dimm_info *dinfo)
  787. {
  788. int mtr;
  789. int amb_present_reg;
  790. int addrBits;
  791. mtr = determine_mtr(pvt, dimm, channel);
  792. if (MTR_DIMMS_PRESENT(mtr)) {
  793. amb_present_reg = determine_amb_present_reg(pvt, channel);
  794. /* Determine if there is a DIMM present in this DIMM slot */
  795. if (amb_present_reg & (1 << dimm)) {
  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. /* add the number of RANK bits */
  804. addrBits += MTR_DIMM_RANK(mtr);
  805. addrBits += 6; /* add 64 bits per DIMM */
  806. addrBits -= 20; /* divide by 2^^20 */
  807. addrBits -= 3; /* 8 bits per bytes */
  808. dinfo->megabytes = 1 << addrBits;
  809. }
  810. }
  811. }
  812. /*
  813. * calculate_dimm_size
  814. *
  815. * also will output a DIMM matrix map, if debug is enabled, for viewing
  816. * how the DIMMs are populated
  817. */
  818. static void calculate_dimm_size(struct i5400_pvt *pvt)
  819. {
  820. struct i5400_dimm_info *dinfo;
  821. int dimm, max_dimms;
  822. char *p, *mem_buffer;
  823. int space, n;
  824. int channel, branch;
  825. /* ================= Generate some debug output ================= */
  826. space = PAGE_SIZE;
  827. mem_buffer = p = kmalloc(space, GFP_KERNEL);
  828. if (p == NULL) {
  829. i5400_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
  830. __FILE__, __func__);
  831. return;
  832. }
  833. /* Scan all the actual DIMMS
  834. * and calculate the information for each DIMM
  835. * Start with the highest dimm first, to display it first
  836. * and work toward the 0th dimm
  837. */
  838. max_dimms = pvt->maxdimmperch;
  839. for (dimm = max_dimms - 1; dimm >= 0; dimm--) {
  840. /* on an odd dimm, first output a 'boundary' marker,
  841. * then reset the message buffer */
  842. if (dimm & 0x1) {
  843. n = snprintf(p, space, "---------------------------"
  844. "-------------------------------");
  845. p += n;
  846. space -= n;
  847. edac_dbg(2, "%s\n", mem_buffer);
  848. p = mem_buffer;
  849. space = PAGE_SIZE;
  850. }
  851. n = snprintf(p, space, "dimm %2d ", dimm);
  852. p += n;
  853. space -= n;
  854. for (channel = 0; channel < pvt->maxch; channel++) {
  855. dinfo = &pvt->dimm_info[dimm][channel];
  856. handle_channel(pvt, dimm, channel, dinfo);
  857. n = snprintf(p, space, "%4d MB | ", dinfo->megabytes);
  858. p += n;
  859. space -= n;
  860. }
  861. edac_dbg(2, "%s\n", mem_buffer);
  862. p = mem_buffer;
  863. space = PAGE_SIZE;
  864. }
  865. /* Output the last bottom 'boundary' marker */
  866. n = snprintf(p, space, "---------------------------"
  867. "-------------------------------");
  868. p += n;
  869. space -= n;
  870. edac_dbg(2, "%s\n", mem_buffer);
  871. p = mem_buffer;
  872. space = PAGE_SIZE;
  873. /* now output the 'channel' labels */
  874. n = snprintf(p, space, " ");
  875. p += n;
  876. space -= n;
  877. for (channel = 0; channel < pvt->maxch; channel++) {
  878. n = snprintf(p, space, "channel %d | ", channel);
  879. p += n;
  880. space -= n;
  881. }
  882. space -= n;
  883. edac_dbg(2, "%s\n", mem_buffer);
  884. p = mem_buffer;
  885. space = PAGE_SIZE;
  886. n = snprintf(p, space, " ");
  887. p += n;
  888. for (branch = 0; branch < MAX_BRANCHES; branch++) {
  889. n = snprintf(p, space, " branch %d | ", branch);
  890. p += n;
  891. space -= n;
  892. }
  893. /* output the last message and free buffer */
  894. edac_dbg(2, "%s\n", mem_buffer);
  895. kfree(mem_buffer);
  896. }
  897. /*
  898. * i5400_get_mc_regs read in the necessary registers and
  899. * cache locally
  900. *
  901. * Fills in the private data members
  902. */
  903. static void i5400_get_mc_regs(struct mem_ctl_info *mci)
  904. {
  905. struct i5400_pvt *pvt;
  906. u32 actual_tolm;
  907. u16 limit;
  908. int slot_row;
  909. int maxch;
  910. int maxdimmperch;
  911. int way0, way1;
  912. pvt = mci->pvt_info;
  913. pci_read_config_dword(pvt->system_address, AMBASE,
  914. (u32 *) &pvt->ambase);
  915. pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
  916. ((u32 *) &pvt->ambase) + sizeof(u32));
  917. maxdimmperch = pvt->maxdimmperch;
  918. maxch = pvt->maxch;
  919. edac_dbg(2, "AMBASE= 0x%lx MAXCH= %d MAX-DIMM-Per-CH= %d\n",
  920. (long unsigned int)pvt->ambase, pvt->maxch, pvt->maxdimmperch);
  921. /* Get the Branch Map regs */
  922. pci_read_config_word(pvt->branchmap_werrors, TOLM, &pvt->tolm);
  923. pvt->tolm >>= 12;
  924. edac_dbg(2, "\nTOLM (number of 256M regions) =%u (0x%x)\n",
  925. pvt->tolm, pvt->tolm);
  926. actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28));
  927. edac_dbg(2, "Actual TOLM byte addr=%u.%03u GB (0x%x)\n",
  928. actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28);
  929. pci_read_config_word(pvt->branchmap_werrors, MIR0, &pvt->mir0);
  930. pci_read_config_word(pvt->branchmap_werrors, MIR1, &pvt->mir1);
  931. /* Get the MIR[0-1] regs */
  932. limit = (pvt->mir0 >> 4) & 0x0fff;
  933. way0 = pvt->mir0 & 0x1;
  934. way1 = pvt->mir0 & 0x2;
  935. edac_dbg(2, "MIR0: limit= 0x%x WAY1= %u WAY0= %x\n",
  936. limit, way1, way0);
  937. limit = (pvt->mir1 >> 4) & 0xfff;
  938. way0 = pvt->mir1 & 0x1;
  939. way1 = pvt->mir1 & 0x2;
  940. edac_dbg(2, "MIR1: limit= 0x%x WAY1= %u WAY0= %x\n",
  941. limit, way1, way0);
  942. /* Get the set of MTR[0-3] regs by each branch */
  943. for (slot_row = 0; slot_row < DIMMS_PER_CHANNEL; slot_row++) {
  944. int where = MTR0 + (slot_row * sizeof(u16));
  945. /* Branch 0 set of MTR registers */
  946. pci_read_config_word(pvt->branch_0, where,
  947. &pvt->b0_mtr[slot_row]);
  948. edac_dbg(2, "MTR%d where=0x%x B0 value=0x%x\n",
  949. slot_row, where, pvt->b0_mtr[slot_row]);
  950. if (pvt->maxch < CHANNELS_PER_BRANCH) {
  951. pvt->b1_mtr[slot_row] = 0;
  952. continue;
  953. }
  954. /* Branch 1 set of MTR registers */
  955. pci_read_config_word(pvt->branch_1, where,
  956. &pvt->b1_mtr[slot_row]);
  957. edac_dbg(2, "MTR%d where=0x%x B1 value=0x%x\n",
  958. slot_row, where, pvt->b1_mtr[slot_row]);
  959. }
  960. /* Read and dump branch 0's MTRs */
  961. edac_dbg(2, "Memory Technology Registers:\n");
  962. edac_dbg(2, " Branch 0:\n");
  963. for (slot_row = 0; slot_row < DIMMS_PER_CHANNEL; slot_row++)
  964. decode_mtr(slot_row, pvt->b0_mtr[slot_row]);
  965. pci_read_config_word(pvt->branch_0, AMBPRESENT_0,
  966. &pvt->b0_ambpresent0);
  967. edac_dbg(2, "\t\tAMB-Branch 0-present0 0x%x:\n", pvt->b0_ambpresent0);
  968. pci_read_config_word(pvt->branch_0, AMBPRESENT_1,
  969. &pvt->b0_ambpresent1);
  970. edac_dbg(2, "\t\tAMB-Branch 0-present1 0x%x:\n", pvt->b0_ambpresent1);
  971. /* Only if we have 2 branchs (4 channels) */
  972. if (pvt->maxch < CHANNELS_PER_BRANCH) {
  973. pvt->b1_ambpresent0 = 0;
  974. pvt->b1_ambpresent1 = 0;
  975. } else {
  976. /* Read and dump branch 1's MTRs */
  977. edac_dbg(2, " Branch 1:\n");
  978. for (slot_row = 0; slot_row < DIMMS_PER_CHANNEL; slot_row++)
  979. decode_mtr(slot_row, pvt->b1_mtr[slot_row]);
  980. pci_read_config_word(pvt->branch_1, AMBPRESENT_0,
  981. &pvt->b1_ambpresent0);
  982. edac_dbg(2, "\t\tAMB-Branch 1-present0 0x%x:\n",
  983. pvt->b1_ambpresent0);
  984. pci_read_config_word(pvt->branch_1, AMBPRESENT_1,
  985. &pvt->b1_ambpresent1);
  986. edac_dbg(2, "\t\tAMB-Branch 1-present1 0x%x:\n",
  987. pvt->b1_ambpresent1);
  988. }
  989. /* Go and determine the size of each DIMM and place in an
  990. * orderly matrix */
  991. calculate_dimm_size(pvt);
  992. }
  993. /*
  994. * i5400_init_dimms Initialize the 'dimms' table within
  995. * the mci control structure with the
  996. * addressing of memory.
  997. *
  998. * return:
  999. * 0 success
  1000. * 1 no actual memory found on this MC
  1001. */
  1002. static int i5400_init_dimms(struct mem_ctl_info *mci)
  1003. {
  1004. struct i5400_pvt *pvt;
  1005. struct dimm_info *dimm;
  1006. int ndimms, channel_count;
  1007. int max_dimms;
  1008. int mtr;
  1009. int size_mb;
  1010. int channel, slot;
  1011. pvt = mci->pvt_info;
  1012. channel_count = pvt->maxch;
  1013. max_dimms = pvt->maxdimmperch;
  1014. ndimms = 0;
  1015. /*
  1016. * FIXME: remove pvt->dimm_info[slot][channel] and use the 3
  1017. * layers here.
  1018. */
  1019. for (channel = 0; channel < mci->layers[0].size * mci->layers[1].size;
  1020. channel++) {
  1021. for (slot = 0; slot < mci->layers[2].size; slot++) {
  1022. mtr = determine_mtr(pvt, slot, channel);
  1023. /* if no DIMMS on this slot, continue */
  1024. if (!MTR_DIMMS_PRESENT(mtr))
  1025. continue;
  1026. dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, mci->n_layers,
  1027. channel / 2, channel % 2, slot);
  1028. size_mb = pvt->dimm_info[slot][channel].megabytes;
  1029. edac_dbg(2, "dimm (branch %d channel %d slot %d): %d.%03d GB\n",
  1030. channel / 2, channel % 2, slot,
  1031. size_mb / 1000, size_mb % 1000);
  1032. dimm->nr_pages = size_mb << 8;
  1033. dimm->grain = 8;
  1034. dimm->dtype = MTR_DRAM_WIDTH(mtr) ? DEV_X8 : DEV_X4;
  1035. dimm->mtype = MEM_FB_DDR2;
  1036. /*
  1037. * The eccc mechanism is SDDC (aka SECC), with
  1038. * is similar to Chipkill.
  1039. */
  1040. dimm->edac_mode = MTR_DRAM_WIDTH(mtr) ?
  1041. EDAC_S8ECD8ED : EDAC_S4ECD4ED;
  1042. ndimms++;
  1043. }
  1044. }
  1045. /*
  1046. * When just one memory is provided, it should be at location (0,0,0).
  1047. * With such single-DIMM mode, the SDCC algorithm degrades to SECDEC+.
  1048. */
  1049. if (ndimms == 1)
  1050. mci->dimms[0]->edac_mode = EDAC_SECDED;
  1051. return (ndimms == 0);
  1052. }
  1053. /*
  1054. * i5400_enable_error_reporting
  1055. * Turn on the memory reporting features of the hardware
  1056. */
  1057. static void i5400_enable_error_reporting(struct mem_ctl_info *mci)
  1058. {
  1059. struct i5400_pvt *pvt;
  1060. u32 fbd_error_mask;
  1061. pvt = mci->pvt_info;
  1062. /* Read the FBD Error Mask Register */
  1063. pci_read_config_dword(pvt->branchmap_werrors, EMASK_FBD,
  1064. &fbd_error_mask);
  1065. /* Enable with a '0' */
  1066. fbd_error_mask &= ~(ENABLE_EMASK_ALL);
  1067. pci_write_config_dword(pvt->branchmap_werrors, EMASK_FBD,
  1068. fbd_error_mask);
  1069. }
  1070. /*
  1071. * i5400_probe1 Probe for ONE instance of device to see if it is
  1072. * present.
  1073. * return:
  1074. * 0 for FOUND a device
  1075. * < 0 for error code
  1076. */
  1077. static int i5400_probe1(struct pci_dev *pdev, int dev_idx)
  1078. {
  1079. struct mem_ctl_info *mci;
  1080. struct i5400_pvt *pvt;
  1081. struct edac_mc_layer layers[3];
  1082. if (dev_idx >= ARRAY_SIZE(i5400_devs))
  1083. return -EINVAL;
  1084. edac_dbg(0, "MC: pdev bus %u dev=0x%x fn=0x%x\n",
  1085. pdev->bus->number,
  1086. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  1087. /* We only are looking for func 0 of the set */
  1088. if (PCI_FUNC(pdev->devfn) != 0)
  1089. return -ENODEV;
  1090. /*
  1091. * allocate a new MC control structure
  1092. *
  1093. * This drivers uses the DIMM slot as "csrow" and the rest as "channel".
  1094. */
  1095. layers[0].type = EDAC_MC_LAYER_BRANCH;
  1096. layers[0].size = MAX_BRANCHES;
  1097. layers[0].is_virt_csrow = false;
  1098. layers[1].type = EDAC_MC_LAYER_CHANNEL;
  1099. layers[1].size = CHANNELS_PER_BRANCH;
  1100. layers[1].is_virt_csrow = false;
  1101. layers[2].type = EDAC_MC_LAYER_SLOT;
  1102. layers[2].size = DIMMS_PER_CHANNEL;
  1103. layers[2].is_virt_csrow = true;
  1104. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
  1105. if (mci == NULL)
  1106. return -ENOMEM;
  1107. edac_dbg(0, "MC: mci = %p\n", mci);
  1108. mci->pdev = &pdev->dev; /* record ptr to the generic device */
  1109. pvt = mci->pvt_info;
  1110. pvt->system_address = pdev; /* Record this device in our private */
  1111. pvt->maxch = MAX_CHANNELS;
  1112. pvt->maxdimmperch = DIMMS_PER_CHANNEL;
  1113. /* 'get' the pci devices we want to reserve for our use */
  1114. if (i5400_get_devices(mci, dev_idx))
  1115. goto fail0;
  1116. /* Time to get serious */
  1117. i5400_get_mc_regs(mci); /* retrieve the hardware registers */
  1118. mci->mc_idx = 0;
  1119. mci->mtype_cap = MEM_FLAG_FB_DDR2;
  1120. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  1121. mci->edac_cap = EDAC_FLAG_NONE;
  1122. mci->mod_name = "i5400_edac.c";
  1123. mci->mod_ver = I5400_REVISION;
  1124. mci->ctl_name = i5400_devs[dev_idx].ctl_name;
  1125. mci->dev_name = pci_name(pdev);
  1126. mci->ctl_page_to_phys = NULL;
  1127. /* Set the function pointer to an actual operation function */
  1128. mci->edac_check = i5400_check_error;
  1129. /* initialize the MC control structure 'dimms' table
  1130. * with the mapping and control information */
  1131. if (i5400_init_dimms(mci)) {
  1132. edac_dbg(0, "MC: Setting mci->edac_cap to EDAC_FLAG_NONE because i5400_init_dimms() returned nonzero value\n");
  1133. mci->edac_cap = EDAC_FLAG_NONE; /* no dimms found */
  1134. } else {
  1135. edac_dbg(1, "MC: Enable error reporting now\n");
  1136. i5400_enable_error_reporting(mci);
  1137. }
  1138. /* add this new MC control structure to EDAC's list of MCs */
  1139. if (edac_mc_add_mc(mci)) {
  1140. edac_dbg(0, "MC: failed edac_mc_add_mc()\n");
  1141. /* FIXME: perhaps some code should go here that disables error
  1142. * reporting if we just enabled it
  1143. */
  1144. goto fail1;
  1145. }
  1146. i5400_clear_error(mci);
  1147. /* allocating generic PCI control info */
  1148. i5400_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  1149. if (!i5400_pci) {
  1150. printk(KERN_WARNING
  1151. "%s(): Unable to create PCI control\n",
  1152. __func__);
  1153. printk(KERN_WARNING
  1154. "%s(): PCI error report via EDAC not setup\n",
  1155. __func__);
  1156. }
  1157. return 0;
  1158. /* Error exit unwinding stack */
  1159. fail1:
  1160. i5400_put_devices(mci);
  1161. fail0:
  1162. edac_mc_free(mci);
  1163. return -ENODEV;
  1164. }
  1165. /*
  1166. * i5400_init_one constructor for one instance of device
  1167. *
  1168. * returns:
  1169. * negative on error
  1170. * count (>= 0)
  1171. */
  1172. static int __devinit i5400_init_one(struct pci_dev *pdev,
  1173. const struct pci_device_id *id)
  1174. {
  1175. int rc;
  1176. edac_dbg(0, "MC:\n");
  1177. /* wake up device */
  1178. rc = pci_enable_device(pdev);
  1179. if (rc)
  1180. return rc;
  1181. /* now probe and enable the device */
  1182. return i5400_probe1(pdev, id->driver_data);
  1183. }
  1184. /*
  1185. * i5400_remove_one destructor for one instance of device
  1186. *
  1187. */
  1188. static void __devexit i5400_remove_one(struct pci_dev *pdev)
  1189. {
  1190. struct mem_ctl_info *mci;
  1191. edac_dbg(0, "\n");
  1192. if (i5400_pci)
  1193. edac_pci_release_generic_ctl(i5400_pci);
  1194. mci = edac_mc_del_mc(&pdev->dev);
  1195. if (!mci)
  1196. return;
  1197. /* retrieve references to resources, and free those resources */
  1198. i5400_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 DEFINE_PCI_DEVICE_TABLE(i5400_pci_tbl) = {
  1207. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
  1208. {0,} /* 0 terminated list. */
  1209. };
  1210. MODULE_DEVICE_TABLE(pci, i5400_pci_tbl);
  1211. /*
  1212. * i5400_driver pci_driver structure for this module
  1213. *
  1214. */
  1215. static struct pci_driver i5400_driver = {
  1216. .name = "i5400_edac",
  1217. .probe = i5400_init_one,
  1218. .remove = __devexit_p(i5400_remove_one),
  1219. .id_table = i5400_pci_tbl,
  1220. };
  1221. /*
  1222. * i5400_init Module entry function
  1223. * Try to initialize this module for its devices
  1224. */
  1225. static int __init i5400_init(void)
  1226. {
  1227. int pci_rc;
  1228. edac_dbg(2, "MC:\n");
  1229. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1230. opstate_init();
  1231. pci_rc = pci_register_driver(&i5400_driver);
  1232. return (pci_rc < 0) ? pci_rc : 0;
  1233. }
  1234. /*
  1235. * i5400_exit() Module exit function
  1236. * Unregister the driver
  1237. */
  1238. static void __exit i5400_exit(void)
  1239. {
  1240. edac_dbg(2, "MC:\n");
  1241. pci_unregister_driver(&i5400_driver);
  1242. }
  1243. module_init(i5400_init);
  1244. module_exit(i5400_exit);
  1245. MODULE_LICENSE("GPL");
  1246. MODULE_AUTHOR("Ben Woodard <woodard@redhat.com>");
  1247. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
  1248. MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
  1249. MODULE_DESCRIPTION("MC Driver for Intel I5400 memory controllers - "
  1250. I5400_REVISION);
  1251. module_param(edac_op_state, int, 0444);
  1252. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");