i5400_edac.c 40 KB

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