i5400_edac.c 40 KB

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