i5400_edac.c 40 KB

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