i5400_edac.c 39 KB

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