i5400_edac.c 40 KB

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