i5000_edac.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581
  1. /*
  2. * Intel 5000(P/V/X) class Memory Controllers kernel module
  3. *
  4. * This file may be distributed under the terms of the
  5. * GNU General Public License.
  6. *
  7. * Written by Douglas Thompson Linux Networx (http://lnxi.com)
  8. * norsk5@xmission.com
  9. *
  10. * This module is based on the following document:
  11. *
  12. * Intel 5000X Chipset Memory Controller Hub (MCH) - Datasheet
  13. * http://developer.intel.com/design/chipsets/datashts/313070.htm
  14. *
  15. */
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/pci.h>
  19. #include <linux/pci_ids.h>
  20. #include <linux/slab.h>
  21. #include <linux/edac.h>
  22. #include <asm/mmzone.h>
  23. #include "edac_core.h"
  24. /*
  25. * Alter this version for the I5000 module when modifications are made
  26. */
  27. #define I5000_REVISION " Ver: 2.0.12"
  28. #define EDAC_MOD_STR "i5000_edac"
  29. #define i5000_printk(level, fmt, arg...) \
  30. edac_printk(level, "i5000", fmt, ##arg)
  31. #define i5000_mc_printk(mci, level, fmt, arg...) \
  32. edac_mc_chipset_printk(mci, level, "i5000", fmt, ##arg)
  33. #ifndef PCI_DEVICE_ID_INTEL_FBD_0
  34. #define PCI_DEVICE_ID_INTEL_FBD_0 0x25F5
  35. #endif
  36. #ifndef PCI_DEVICE_ID_INTEL_FBD_1
  37. #define PCI_DEVICE_ID_INTEL_FBD_1 0x25F6
  38. #endif
  39. /* Device 16,
  40. * Function 0: System Address
  41. * Function 1: Memory Branch Map, Control, Errors Register
  42. * Function 2: FSB Error Registers
  43. *
  44. * All 3 functions of Device 16 (0,1,2) share the SAME DID
  45. */
  46. #define PCI_DEVICE_ID_INTEL_I5000_DEV16 0x25F0
  47. /* OFFSETS for Function 0 */
  48. /* OFFSETS for Function 1 */
  49. #define AMBASE 0x48
  50. #define MAXCH 0x56
  51. #define MAXDIMMPERCH 0x57
  52. #define TOLM 0x6C
  53. #define REDMEMB 0x7C
  54. #define RED_ECC_LOCATOR(x) ((x) & 0x3FFFF)
  55. #define REC_ECC_LOCATOR_EVEN(x) ((x) & 0x001FF)
  56. #define REC_ECC_LOCATOR_ODD(x) ((x) & 0x3FE00)
  57. #define MIR0 0x80
  58. #define MIR1 0x84
  59. #define MIR2 0x88
  60. #define AMIR0 0x8C
  61. #define AMIR1 0x90
  62. #define AMIR2 0x94
  63. #define FERR_FAT_FBD 0x98
  64. #define NERR_FAT_FBD 0x9C
  65. #define EXTRACT_FBDCHAN_INDX(x) (((x)>>28) & 0x3)
  66. #define FERR_FAT_FBDCHAN 0x30000000
  67. #define FERR_FAT_M3ERR 0x00000004
  68. #define FERR_FAT_M2ERR 0x00000002
  69. #define FERR_FAT_M1ERR 0x00000001
  70. #define FERR_FAT_MASK (FERR_FAT_M1ERR | \
  71. FERR_FAT_M2ERR | \
  72. FERR_FAT_M3ERR)
  73. #define FERR_NF_FBD 0xA0
  74. /* Thermal and SPD or BFD errors */
  75. #define FERR_NF_M28ERR 0x01000000
  76. #define FERR_NF_M27ERR 0x00800000
  77. #define FERR_NF_M26ERR 0x00400000
  78. #define FERR_NF_M25ERR 0x00200000
  79. #define FERR_NF_M24ERR 0x00100000
  80. #define FERR_NF_M23ERR 0x00080000
  81. #define FERR_NF_M22ERR 0x00040000
  82. #define FERR_NF_M21ERR 0x00020000
  83. /* Correctable errors */
  84. #define FERR_NF_M20ERR 0x00010000
  85. #define FERR_NF_M19ERR 0x00008000
  86. #define FERR_NF_M18ERR 0x00004000
  87. #define FERR_NF_M17ERR 0x00002000
  88. /* Non-Retry or redundant Retry errors */
  89. #define FERR_NF_M16ERR 0x00001000
  90. #define FERR_NF_M15ERR 0x00000800
  91. #define FERR_NF_M14ERR 0x00000400
  92. #define FERR_NF_M13ERR 0x00000200
  93. /* Uncorrectable errors */
  94. #define FERR_NF_M12ERR 0x00000100
  95. #define FERR_NF_M11ERR 0x00000080
  96. #define FERR_NF_M10ERR 0x00000040
  97. #define FERR_NF_M9ERR 0x00000020
  98. #define FERR_NF_M8ERR 0x00000010
  99. #define FERR_NF_M7ERR 0x00000008
  100. #define FERR_NF_M6ERR 0x00000004
  101. #define FERR_NF_M5ERR 0x00000002
  102. #define FERR_NF_M4ERR 0x00000001
  103. #define FERR_NF_UNCORRECTABLE (FERR_NF_M12ERR | \
  104. FERR_NF_M11ERR | \
  105. FERR_NF_M10ERR | \
  106. FERR_NF_M9ERR | \
  107. FERR_NF_M8ERR | \
  108. FERR_NF_M7ERR | \
  109. FERR_NF_M6ERR | \
  110. FERR_NF_M5ERR | \
  111. FERR_NF_M4ERR)
  112. #define FERR_NF_CORRECTABLE (FERR_NF_M20ERR | \
  113. FERR_NF_M19ERR | \
  114. FERR_NF_M18ERR | \
  115. FERR_NF_M17ERR)
  116. #define FERR_NF_DIMM_SPARE (FERR_NF_M27ERR | \
  117. FERR_NF_M28ERR)
  118. #define FERR_NF_THERMAL (FERR_NF_M26ERR | \
  119. FERR_NF_M25ERR | \
  120. FERR_NF_M24ERR | \
  121. FERR_NF_M23ERR)
  122. #define FERR_NF_SPD_PROTOCOL (FERR_NF_M22ERR)
  123. #define FERR_NF_NORTH_CRC (FERR_NF_M21ERR)
  124. #define FERR_NF_NON_RETRY (FERR_NF_M13ERR | \
  125. FERR_NF_M14ERR | \
  126. FERR_NF_M15ERR)
  127. #define NERR_NF_FBD 0xA4
  128. #define FERR_NF_MASK (FERR_NF_UNCORRECTABLE | \
  129. FERR_NF_CORRECTABLE | \
  130. FERR_NF_DIMM_SPARE | \
  131. FERR_NF_THERMAL | \
  132. FERR_NF_SPD_PROTOCOL | \
  133. FERR_NF_NORTH_CRC | \
  134. FERR_NF_NON_RETRY)
  135. #define EMASK_FBD 0xA8
  136. #define EMASK_FBD_M28ERR 0x08000000
  137. #define EMASK_FBD_M27ERR 0x04000000
  138. #define EMASK_FBD_M26ERR 0x02000000
  139. #define EMASK_FBD_M25ERR 0x01000000
  140. #define EMASK_FBD_M24ERR 0x00800000
  141. #define EMASK_FBD_M23ERR 0x00400000
  142. #define EMASK_FBD_M22ERR 0x00200000
  143. #define EMASK_FBD_M21ERR 0x00100000
  144. #define EMASK_FBD_M20ERR 0x00080000
  145. #define EMASK_FBD_M19ERR 0x00040000
  146. #define EMASK_FBD_M18ERR 0x00020000
  147. #define EMASK_FBD_M17ERR 0x00010000
  148. #define EMASK_FBD_M15ERR 0x00004000
  149. #define EMASK_FBD_M14ERR 0x00002000
  150. #define EMASK_FBD_M13ERR 0x00001000
  151. #define EMASK_FBD_M12ERR 0x00000800
  152. #define EMASK_FBD_M11ERR 0x00000400
  153. #define EMASK_FBD_M10ERR 0x00000200
  154. #define EMASK_FBD_M9ERR 0x00000100
  155. #define EMASK_FBD_M8ERR 0x00000080
  156. #define EMASK_FBD_M7ERR 0x00000040
  157. #define EMASK_FBD_M6ERR 0x00000020
  158. #define EMASK_FBD_M5ERR 0x00000010
  159. #define EMASK_FBD_M4ERR 0x00000008
  160. #define EMASK_FBD_M3ERR 0x00000004
  161. #define EMASK_FBD_M2ERR 0x00000002
  162. #define EMASK_FBD_M1ERR 0x00000001
  163. #define ENABLE_EMASK_FBD_FATAL_ERRORS (EMASK_FBD_M1ERR | \
  164. EMASK_FBD_M2ERR | \
  165. EMASK_FBD_M3ERR)
  166. #define ENABLE_EMASK_FBD_UNCORRECTABLE (EMASK_FBD_M4ERR | \
  167. EMASK_FBD_M5ERR | \
  168. EMASK_FBD_M6ERR | \
  169. EMASK_FBD_M7ERR | \
  170. EMASK_FBD_M8ERR | \
  171. EMASK_FBD_M9ERR | \
  172. EMASK_FBD_M10ERR | \
  173. EMASK_FBD_M11ERR | \
  174. EMASK_FBD_M12ERR)
  175. #define ENABLE_EMASK_FBD_CORRECTABLE (EMASK_FBD_M17ERR | \
  176. EMASK_FBD_M18ERR | \
  177. EMASK_FBD_M19ERR | \
  178. EMASK_FBD_M20ERR)
  179. #define ENABLE_EMASK_FBD_DIMM_SPARE (EMASK_FBD_M27ERR | \
  180. EMASK_FBD_M28ERR)
  181. #define ENABLE_EMASK_FBD_THERMALS (EMASK_FBD_M26ERR | \
  182. EMASK_FBD_M25ERR | \
  183. EMASK_FBD_M24ERR | \
  184. EMASK_FBD_M23ERR)
  185. #define ENABLE_EMASK_FBD_SPD_PROTOCOL (EMASK_FBD_M22ERR)
  186. #define ENABLE_EMASK_FBD_NORTH_CRC (EMASK_FBD_M21ERR)
  187. #define ENABLE_EMASK_FBD_NON_RETRY (EMASK_FBD_M15ERR | \
  188. EMASK_FBD_M14ERR | \
  189. EMASK_FBD_M13ERR)
  190. #define ENABLE_EMASK_ALL (ENABLE_EMASK_FBD_NON_RETRY | \
  191. ENABLE_EMASK_FBD_NORTH_CRC | \
  192. ENABLE_EMASK_FBD_SPD_PROTOCOL | \
  193. ENABLE_EMASK_FBD_THERMALS | \
  194. ENABLE_EMASK_FBD_DIMM_SPARE | \
  195. ENABLE_EMASK_FBD_FATAL_ERRORS | \
  196. ENABLE_EMASK_FBD_CORRECTABLE | \
  197. ENABLE_EMASK_FBD_UNCORRECTABLE)
  198. #define ERR0_FBD 0xAC
  199. #define ERR1_FBD 0xB0
  200. #define ERR2_FBD 0xB4
  201. #define MCERR_FBD 0xB8
  202. #define NRECMEMA 0xBE
  203. #define NREC_BANK(x) (((x)>>12) & 0x7)
  204. #define NREC_RDWR(x) (((x)>>11) & 1)
  205. #define NREC_RANK(x) (((x)>>8) & 0x7)
  206. #define NRECMEMB 0xC0
  207. #define NREC_CAS(x) (((x)>>16) & 0xFFFFFF)
  208. #define NREC_RAS(x) ((x) & 0x7FFF)
  209. #define NRECFGLOG 0xC4
  210. #define NREEECFBDA 0xC8
  211. #define NREEECFBDB 0xCC
  212. #define NREEECFBDC 0xD0
  213. #define NREEECFBDD 0xD4
  214. #define NREEECFBDE 0xD8
  215. #define REDMEMA 0xDC
  216. #define RECMEMA 0xE2
  217. #define REC_BANK(x) (((x)>>12) & 0x7)
  218. #define REC_RDWR(x) (((x)>>11) & 1)
  219. #define REC_RANK(x) (((x)>>8) & 0x7)
  220. #define RECMEMB 0xE4
  221. #define REC_CAS(x) (((x)>>16) & 0xFFFFFF)
  222. #define REC_RAS(x) ((x) & 0x7FFF)
  223. #define RECFGLOG 0xE8
  224. #define RECFBDA 0xEC
  225. #define RECFBDB 0xF0
  226. #define RECFBDC 0xF4
  227. #define RECFBDD 0xF8
  228. #define RECFBDE 0xFC
  229. /* OFFSETS for Function 2 */
  230. /*
  231. * Device 21,
  232. * Function 0: Memory Map Branch 0
  233. *
  234. * Device 22,
  235. * Function 0: Memory Map Branch 1
  236. */
  237. #define PCI_DEVICE_ID_I5000_BRANCH_0 0x25F5
  238. #define PCI_DEVICE_ID_I5000_BRANCH_1 0x25F6
  239. #define AMB_PRESENT_0 0x64
  240. #define AMB_PRESENT_1 0x66
  241. #define MTR0 0x80
  242. #define MTR1 0x84
  243. #define MTR2 0x88
  244. #define MTR3 0x8C
  245. #define NUM_MTRS 4
  246. #define CHANNELS_PER_BRANCH (2)
  247. /* Defines to extract the vaious fields from the
  248. * MTRx - Memory Technology Registers
  249. */
  250. #define MTR_DIMMS_PRESENT(mtr) ((mtr) & (0x1 << 8))
  251. #define MTR_DRAM_WIDTH(mtr) ((((mtr) >> 6) & 0x1) ? 8 : 4)
  252. #define MTR_DRAM_BANKS(mtr) ((((mtr) >> 5) & 0x1) ? 8 : 4)
  253. #define MTR_DRAM_BANKS_ADDR_BITS(mtr) ((MTR_DRAM_BANKS(mtr) == 8) ? 3 : 2)
  254. #define MTR_DIMM_RANK(mtr) (((mtr) >> 4) & 0x1)
  255. #define MTR_DIMM_RANK_ADDR_BITS(mtr) (MTR_DIMM_RANK(mtr) ? 2 : 1)
  256. #define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
  257. #define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
  258. #define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
  259. #define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
  260. #ifdef CONFIG_EDAC_DEBUG
  261. static char *numrow_toString[] = {
  262. "8,192 - 13 rows",
  263. "16,384 - 14 rows",
  264. "32,768 - 15 rows",
  265. "reserved"
  266. };
  267. static char *numcol_toString[] = {
  268. "1,024 - 10 columns",
  269. "2,048 - 11 columns",
  270. "4,096 - 12 columns",
  271. "reserved"
  272. };
  273. #endif
  274. /* enables the report of miscellaneous messages as CE errors - default off */
  275. static int misc_messages;
  276. /* Enumeration of supported devices */
  277. enum i5000_chips {
  278. I5000P = 0,
  279. I5000V = 1, /* future */
  280. I5000X = 2 /* future */
  281. };
  282. /* Device name and register DID (Device ID) */
  283. struct i5000_dev_info {
  284. const char *ctl_name; /* name for this device */
  285. u16 fsb_mapping_errors; /* DID for the branchmap,control */
  286. };
  287. /* Table of devices attributes supported by this driver */
  288. static const struct i5000_dev_info i5000_devs[] = {
  289. [I5000P] = {
  290. .ctl_name = "I5000",
  291. .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I5000_DEV16,
  292. },
  293. };
  294. struct i5000_dimm_info {
  295. int megabytes; /* size, 0 means not present */
  296. int dual_rank;
  297. };
  298. #define MAX_CHANNELS 6 /* max possible channels */
  299. #define MAX_CSROWS (8*2) /* max possible csrows per channel */
  300. /* driver private data structure */
  301. struct i5000_pvt {
  302. struct pci_dev *system_address; /* 16.0 */
  303. struct pci_dev *branchmap_werrors; /* 16.1 */
  304. struct pci_dev *fsb_error_regs; /* 16.2 */
  305. struct pci_dev *branch_0; /* 21.0 */
  306. struct pci_dev *branch_1; /* 22.0 */
  307. u16 tolm; /* top of low memory */
  308. u64 ambase; /* AMB BAR */
  309. u16 mir0, mir1, mir2;
  310. u16 b0_mtr[NUM_MTRS]; /* Memory Technlogy Reg */
  311. u16 b0_ambpresent0; /* Branch 0, Channel 0 */
  312. u16 b0_ambpresent1; /* Brnach 0, Channel 1 */
  313. u16 b1_mtr[NUM_MTRS]; /* Memory Technlogy Reg */
  314. u16 b1_ambpresent0; /* Branch 1, Channel 8 */
  315. u16 b1_ambpresent1; /* Branch 1, Channel 1 */
  316. /* DIMM information matrix, allocating architecture maximums */
  317. struct i5000_dimm_info dimm_info[MAX_CSROWS][MAX_CHANNELS];
  318. /* Actual values for this controller */
  319. int maxch; /* Max channels */
  320. int maxdimmperch; /* Max DIMMs per channel */
  321. };
  322. /* I5000 MCH error information retrieved from Hardware */
  323. struct i5000_error_info {
  324. /* These registers are always read from the MC */
  325. u32 ferr_fat_fbd; /* First Errors Fatal */
  326. u32 nerr_fat_fbd; /* Next Errors Fatal */
  327. u32 ferr_nf_fbd; /* First Errors Non-Fatal */
  328. u32 nerr_nf_fbd; /* Next Errors Non-Fatal */
  329. /* These registers are input ONLY if there was a Recoverable Error */
  330. u32 redmemb; /* Recoverable Mem Data Error log B */
  331. u16 recmema; /* Recoverable Mem Error log A */
  332. u32 recmemb; /* Recoverable Mem Error log B */
  333. /* These registers are input ONLY if there was a
  334. * Non-Recoverable Error */
  335. u16 nrecmema; /* Non-Recoverable Mem log A */
  336. u16 nrecmemb; /* Non-Recoverable Mem log B */
  337. };
  338. static struct edac_pci_ctl_info *i5000_pci;
  339. /*
  340. * i5000_get_error_info Retrieve the hardware error information from
  341. * the hardware and cache it in the 'info'
  342. * structure
  343. */
  344. static void i5000_get_error_info(struct mem_ctl_info *mci,
  345. struct i5000_error_info *info)
  346. {
  347. struct i5000_pvt *pvt;
  348. u32 value;
  349. pvt = mci->pvt_info;
  350. /* read in the 1st FATAL error register */
  351. pci_read_config_dword(pvt->branchmap_werrors, FERR_FAT_FBD, &value);
  352. /* Mask only the bits that the doc says are valid
  353. */
  354. value &= (FERR_FAT_FBDCHAN | FERR_FAT_MASK);
  355. /* If there is an error, then read in the */
  356. /* NEXT FATAL error register and the Memory Error Log Register A */
  357. if (value & FERR_FAT_MASK) {
  358. info->ferr_fat_fbd = value;
  359. /* harvest the various error data we need */
  360. pci_read_config_dword(pvt->branchmap_werrors,
  361. NERR_FAT_FBD, &info->nerr_fat_fbd);
  362. pci_read_config_word(pvt->branchmap_werrors,
  363. NRECMEMA, &info->nrecmema);
  364. pci_read_config_word(pvt->branchmap_werrors,
  365. NRECMEMB, &info->nrecmemb);
  366. /* Clear the error bits, by writing them back */
  367. pci_write_config_dword(pvt->branchmap_werrors,
  368. FERR_FAT_FBD, value);
  369. } else {
  370. info->ferr_fat_fbd = 0;
  371. info->nerr_fat_fbd = 0;
  372. info->nrecmema = 0;
  373. info->nrecmemb = 0;
  374. }
  375. /* read in the 1st NON-FATAL error register */
  376. pci_read_config_dword(pvt->branchmap_werrors, FERR_NF_FBD, &value);
  377. /* If there is an error, then read in the 1st NON-FATAL error
  378. * register as well */
  379. if (value & FERR_NF_MASK) {
  380. info->ferr_nf_fbd = value;
  381. /* harvest the various error data we need */
  382. pci_read_config_dword(pvt->branchmap_werrors,
  383. NERR_NF_FBD, &info->nerr_nf_fbd);
  384. pci_read_config_word(pvt->branchmap_werrors,
  385. RECMEMA, &info->recmema);
  386. pci_read_config_dword(pvt->branchmap_werrors,
  387. RECMEMB, &info->recmemb);
  388. pci_read_config_dword(pvt->branchmap_werrors,
  389. REDMEMB, &info->redmemb);
  390. /* Clear the error bits, by writing them back */
  391. pci_write_config_dword(pvt->branchmap_werrors,
  392. FERR_NF_FBD, value);
  393. } else {
  394. info->ferr_nf_fbd = 0;
  395. info->nerr_nf_fbd = 0;
  396. info->recmema = 0;
  397. info->recmemb = 0;
  398. info->redmemb = 0;
  399. }
  400. }
  401. /*
  402. * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
  403. * struct i5000_error_info *info,
  404. * int handle_errors);
  405. *
  406. * handle the Intel FATAL errors, if any
  407. */
  408. static void i5000_process_fatal_error_info(struct mem_ctl_info *mci,
  409. struct i5000_error_info *info,
  410. int handle_errors)
  411. {
  412. char msg[EDAC_MC_LABEL_LEN + 1 + 160];
  413. char *specific = NULL;
  414. u32 allErrors;
  415. int branch;
  416. int channel;
  417. int bank;
  418. int rank;
  419. int rdwr;
  420. int ras, cas;
  421. /* mask off the Error bits that are possible */
  422. allErrors = (info->ferr_fat_fbd & FERR_FAT_MASK);
  423. if (!allErrors)
  424. return; /* if no error, return now */
  425. branch = EXTRACT_FBDCHAN_INDX(info->ferr_fat_fbd);
  426. channel = branch;
  427. /* Use the NON-Recoverable macros to extract data */
  428. bank = NREC_BANK(info->nrecmema);
  429. rank = NREC_RANK(info->nrecmema);
  430. rdwr = NREC_RDWR(info->nrecmema);
  431. ras = NREC_RAS(info->nrecmemb);
  432. cas = NREC_CAS(info->nrecmemb);
  433. debugf0("\t\tCSROW= %d Channels= %d,%d (Branch= %d "
  434. "DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  435. rank, channel, channel + 1, branch >> 1, bank,
  436. rdwr ? "Write" : "Read", ras, cas);
  437. /* Only 1 bit will be on */
  438. switch (allErrors) {
  439. case FERR_FAT_M1ERR:
  440. specific = "Alert on non-redundant retry or fast "
  441. "reset timeout";
  442. break;
  443. case FERR_FAT_M2ERR:
  444. specific = "Northbound CRC error on non-redundant "
  445. "retry";
  446. break;
  447. case FERR_FAT_M3ERR:
  448. {
  449. static int done;
  450. /*
  451. * This error is generated to inform that the intelligent
  452. * throttling is disabled and the temperature passed the
  453. * specified middle point. Since this is something the BIOS
  454. * should take care of, we'll warn only once to avoid
  455. * worthlessly flooding the log.
  456. */
  457. if (done)
  458. return;
  459. done++;
  460. specific = ">Tmid Thermal event with intelligent "
  461. "throttling disabled";
  462. }
  463. break;
  464. }
  465. /* Form out message */
  466. snprintf(msg, sizeof(msg),
  467. "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d CAS=%d "
  468. "FATAL Err=0x%x (%s))",
  469. branch >> 1, bank, rdwr ? "Write" : "Read", ras, cas,
  470. allErrors, specific);
  471. /* Call the helper to output message */
  472. edac_mc_handle_fbd_ue(mci, rank, channel, channel + 1, msg);
  473. }
  474. /*
  475. * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
  476. * struct i5000_error_info *info,
  477. * int handle_errors);
  478. *
  479. * handle the Intel NON-FATAL errors, if any
  480. */
  481. static void i5000_process_nonfatal_error_info(struct mem_ctl_info *mci,
  482. struct i5000_error_info *info,
  483. int handle_errors)
  484. {
  485. char msg[EDAC_MC_LABEL_LEN + 1 + 170];
  486. char *specific = NULL;
  487. u32 allErrors;
  488. u32 ue_errors;
  489. u32 ce_errors;
  490. u32 misc_errors;
  491. int branch;
  492. int channel;
  493. int bank;
  494. int rank;
  495. int rdwr;
  496. int ras, cas;
  497. /* mask off the Error bits that are possible */
  498. allErrors = (info->ferr_nf_fbd & FERR_NF_MASK);
  499. if (!allErrors)
  500. return; /* if no error, return now */
  501. /* ONLY ONE of the possible error bits will be set, as per the docs */
  502. ue_errors = allErrors & FERR_NF_UNCORRECTABLE;
  503. if (ue_errors) {
  504. debugf0("\tUncorrected bits= 0x%x\n", ue_errors);
  505. branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
  506. /*
  507. * According with i5000 datasheet, bit 28 has no significance
  508. * for errors M4Err-M12Err and M17Err-M21Err, on FERR_NF_FBD
  509. */
  510. channel = branch & 2;
  511. bank = NREC_BANK(info->nrecmema);
  512. rank = NREC_RANK(info->nrecmema);
  513. rdwr = NREC_RDWR(info->nrecmema);
  514. ras = NREC_RAS(info->nrecmemb);
  515. cas = NREC_CAS(info->nrecmemb);
  516. debugf0
  517. ("\t\tCSROW= %d Channels= %d,%d (Branch= %d "
  518. "DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  519. rank, channel, channel + 1, branch >> 1, bank,
  520. rdwr ? "Write" : "Read", ras, cas);
  521. switch (ue_errors) {
  522. case FERR_NF_M12ERR:
  523. specific = "Non-Aliased Uncorrectable Patrol Data ECC";
  524. break;
  525. case FERR_NF_M11ERR:
  526. specific = "Non-Aliased Uncorrectable Spare-Copy "
  527. "Data ECC";
  528. break;
  529. case FERR_NF_M10ERR:
  530. specific = "Non-Aliased Uncorrectable Mirrored Demand "
  531. "Data ECC";
  532. break;
  533. case FERR_NF_M9ERR:
  534. specific = "Non-Aliased Uncorrectable Non-Mirrored "
  535. "Demand Data ECC";
  536. break;
  537. case FERR_NF_M8ERR:
  538. specific = "Aliased Uncorrectable Patrol Data ECC";
  539. break;
  540. case FERR_NF_M7ERR:
  541. specific = "Aliased Uncorrectable Spare-Copy Data ECC";
  542. break;
  543. case FERR_NF_M6ERR:
  544. specific = "Aliased Uncorrectable Mirrored Demand "
  545. "Data ECC";
  546. break;
  547. case FERR_NF_M5ERR:
  548. specific = "Aliased Uncorrectable Non-Mirrored Demand "
  549. "Data ECC";
  550. break;
  551. case FERR_NF_M4ERR:
  552. specific = "Uncorrectable Data ECC on Replay";
  553. break;
  554. }
  555. /* Form out message */
  556. snprintf(msg, sizeof(msg),
  557. "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d "
  558. "CAS=%d, UE Err=0x%x (%s))",
  559. branch >> 1, bank, rdwr ? "Write" : "Read", ras, cas,
  560. ue_errors, specific);
  561. /* Call the helper to output message */
  562. edac_mc_handle_fbd_ue(mci, rank, channel, channel + 1, msg);
  563. }
  564. /* Check correctable errors */
  565. ce_errors = allErrors & FERR_NF_CORRECTABLE;
  566. if (ce_errors) {
  567. debugf0("\tCorrected bits= 0x%x\n", ce_errors);
  568. branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
  569. channel = 0;
  570. if (REC_ECC_LOCATOR_ODD(info->redmemb))
  571. channel = 1;
  572. /* Convert channel to be based from zero, instead of
  573. * from branch base of 0 */
  574. channel += branch;
  575. bank = REC_BANK(info->recmema);
  576. rank = REC_RANK(info->recmema);
  577. rdwr = REC_RDWR(info->recmema);
  578. ras = REC_RAS(info->recmemb);
  579. cas = REC_CAS(info->recmemb);
  580. debugf0("\t\tCSROW= %d Channel= %d (Branch %d "
  581. "DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  582. rank, channel, branch >> 1, bank,
  583. rdwr ? "Write" : "Read", ras, cas);
  584. switch (ce_errors) {
  585. case FERR_NF_M17ERR:
  586. specific = "Correctable Non-Mirrored Demand Data ECC";
  587. break;
  588. case FERR_NF_M18ERR:
  589. specific = "Correctable Mirrored Demand Data ECC";
  590. break;
  591. case FERR_NF_M19ERR:
  592. specific = "Correctable Spare-Copy Data ECC";
  593. break;
  594. case FERR_NF_M20ERR:
  595. specific = "Correctable Patrol Data ECC";
  596. break;
  597. }
  598. /* Form out message */
  599. snprintf(msg, sizeof(msg),
  600. "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d "
  601. "CAS=%d, CE Err=0x%x (%s))", branch >> 1, bank,
  602. rdwr ? "Write" : "Read", ras, cas, ce_errors,
  603. specific);
  604. /* Call the helper to output message */
  605. edac_mc_handle_fbd_ce(mci, rank, channel, msg);
  606. }
  607. if (!misc_messages)
  608. return;
  609. misc_errors = allErrors & (FERR_NF_NON_RETRY | FERR_NF_NORTH_CRC |
  610. FERR_NF_SPD_PROTOCOL | FERR_NF_DIMM_SPARE);
  611. if (misc_errors) {
  612. switch (misc_errors) {
  613. case FERR_NF_M13ERR:
  614. specific = "Non-Retry or Redundant Retry FBD Memory "
  615. "Alert or Redundant Fast Reset Timeout";
  616. break;
  617. case FERR_NF_M14ERR:
  618. specific = "Non-Retry or Redundant Retry FBD "
  619. "Configuration Alert";
  620. break;
  621. case FERR_NF_M15ERR:
  622. specific = "Non-Retry or Redundant Retry FBD "
  623. "Northbound CRC error on read data";
  624. break;
  625. case FERR_NF_M21ERR:
  626. specific = "FBD Northbound CRC error on "
  627. "FBD Sync Status";
  628. break;
  629. case FERR_NF_M22ERR:
  630. specific = "SPD protocol error";
  631. break;
  632. case FERR_NF_M27ERR:
  633. specific = "DIMM-spare copy started";
  634. break;
  635. case FERR_NF_M28ERR:
  636. specific = "DIMM-spare copy completed";
  637. break;
  638. }
  639. branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
  640. /* Form out message */
  641. snprintf(msg, sizeof(msg),
  642. "(Branch=%d Err=%#x (%s))", branch >> 1,
  643. misc_errors, specific);
  644. /* Call the helper to output message */
  645. edac_mc_handle_fbd_ce(mci, 0, 0, msg);
  646. }
  647. }
  648. /*
  649. * i5000_process_error_info Process the error info that is
  650. * in the 'info' structure, previously retrieved from hardware
  651. */
  652. static void i5000_process_error_info(struct mem_ctl_info *mci,
  653. struct i5000_error_info *info,
  654. int handle_errors)
  655. {
  656. /* First handle any fatal errors that occurred */
  657. i5000_process_fatal_error_info(mci, info, handle_errors);
  658. /* now handle any non-fatal errors that occurred */
  659. i5000_process_nonfatal_error_info(mci, info, handle_errors);
  660. }
  661. /*
  662. * i5000_clear_error Retrieve any error from the hardware
  663. * but do NOT process that error.
  664. * Used for 'clearing' out of previous errors
  665. * Called by the Core module.
  666. */
  667. static void i5000_clear_error(struct mem_ctl_info *mci)
  668. {
  669. struct i5000_error_info info;
  670. i5000_get_error_info(mci, &info);
  671. }
  672. /*
  673. * i5000_check_error Retrieve and process errors reported by the
  674. * hardware. Called by the Core module.
  675. */
  676. static void i5000_check_error(struct mem_ctl_info *mci)
  677. {
  678. struct i5000_error_info info;
  679. debugf4("MC%d: %s: %s()\n", mci->mc_idx, __FILE__, __func__);
  680. i5000_get_error_info(mci, &info);
  681. i5000_process_error_info(mci, &info, 1);
  682. }
  683. /*
  684. * i5000_get_devices Find and perform 'get' operation on the MCH's
  685. * device/functions we want to reference for this driver
  686. *
  687. * Need to 'get' device 16 func 1 and func 2
  688. */
  689. static int i5000_get_devices(struct mem_ctl_info *mci, int dev_idx)
  690. {
  691. //const struct i5000_dev_info *i5000_dev = &i5000_devs[dev_idx];
  692. struct i5000_pvt *pvt;
  693. struct pci_dev *pdev;
  694. pvt = mci->pvt_info;
  695. /* Attempt to 'get' the MCH register we want */
  696. pdev = NULL;
  697. while (1) {
  698. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  699. PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
  700. /* End of list, leave */
  701. if (pdev == NULL) {
  702. i5000_printk(KERN_ERR,
  703. "'system address,Process Bus' "
  704. "device not found:"
  705. "vendor 0x%x device 0x%x FUNC 1 "
  706. "(broken BIOS?)\n",
  707. PCI_VENDOR_ID_INTEL,
  708. PCI_DEVICE_ID_INTEL_I5000_DEV16);
  709. return 1;
  710. }
  711. /* Scan for device 16 func 1 */
  712. if (PCI_FUNC(pdev->devfn) == 1)
  713. break;
  714. }
  715. pvt->branchmap_werrors = pdev;
  716. /* Attempt to 'get' the MCH register we want */
  717. pdev = NULL;
  718. while (1) {
  719. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  720. PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
  721. if (pdev == NULL) {
  722. i5000_printk(KERN_ERR,
  723. "MC: 'branchmap,control,errors' "
  724. "device not found:"
  725. "vendor 0x%x device 0x%x Func 2 "
  726. "(broken BIOS?)\n",
  727. PCI_VENDOR_ID_INTEL,
  728. PCI_DEVICE_ID_INTEL_I5000_DEV16);
  729. pci_dev_put(pvt->branchmap_werrors);
  730. return 1;
  731. }
  732. /* Scan for device 16 func 1 */
  733. if (PCI_FUNC(pdev->devfn) == 2)
  734. break;
  735. }
  736. pvt->fsb_error_regs = pdev;
  737. debugf1("System Address, processor bus- PCI Bus ID: %s %x:%x\n",
  738. pci_name(pvt->system_address),
  739. pvt->system_address->vendor, pvt->system_address->device);
  740. debugf1("Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
  741. pci_name(pvt->branchmap_werrors),
  742. pvt->branchmap_werrors->vendor, pvt->branchmap_werrors->device);
  743. debugf1("FSB Error Regs - PCI Bus ID: %s %x:%x\n",
  744. pci_name(pvt->fsb_error_regs),
  745. pvt->fsb_error_regs->vendor, pvt->fsb_error_regs->device);
  746. pdev = NULL;
  747. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  748. PCI_DEVICE_ID_I5000_BRANCH_0, pdev);
  749. if (pdev == NULL) {
  750. i5000_printk(KERN_ERR,
  751. "MC: 'BRANCH 0' device not found:"
  752. "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
  753. PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_I5000_BRANCH_0);
  754. pci_dev_put(pvt->branchmap_werrors);
  755. pci_dev_put(pvt->fsb_error_regs);
  756. return 1;
  757. }
  758. pvt->branch_0 = pdev;
  759. /* If this device claims to have more than 2 channels then
  760. * fetch Branch 1's information
  761. */
  762. if (pvt->maxch >= CHANNELS_PER_BRANCH) {
  763. pdev = NULL;
  764. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  765. PCI_DEVICE_ID_I5000_BRANCH_1, pdev);
  766. if (pdev == NULL) {
  767. i5000_printk(KERN_ERR,
  768. "MC: 'BRANCH 1' device not found:"
  769. "vendor 0x%x device 0x%x Func 0 "
  770. "(broken BIOS?)\n",
  771. PCI_VENDOR_ID_INTEL,
  772. PCI_DEVICE_ID_I5000_BRANCH_1);
  773. pci_dev_put(pvt->branchmap_werrors);
  774. pci_dev_put(pvt->fsb_error_regs);
  775. pci_dev_put(pvt->branch_0);
  776. return 1;
  777. }
  778. pvt->branch_1 = pdev;
  779. }
  780. return 0;
  781. }
  782. /*
  783. * i5000_put_devices 'put' all the devices that we have
  784. * reserved via 'get'
  785. */
  786. static void i5000_put_devices(struct mem_ctl_info *mci)
  787. {
  788. struct i5000_pvt *pvt;
  789. pvt = mci->pvt_info;
  790. pci_dev_put(pvt->branchmap_werrors); /* FUNC 1 */
  791. pci_dev_put(pvt->fsb_error_regs); /* FUNC 2 */
  792. pci_dev_put(pvt->branch_0); /* DEV 21 */
  793. /* Only if more than 2 channels do we release the second branch */
  794. if (pvt->maxch >= CHANNELS_PER_BRANCH)
  795. pci_dev_put(pvt->branch_1); /* DEV 22 */
  796. }
  797. /*
  798. * determine_amb_resent
  799. *
  800. * the information is contained in NUM_MTRS different registers
  801. * determineing which of the NUM_MTRS requires knowing
  802. * which channel is in question
  803. *
  804. * 2 branches, each with 2 channels
  805. * b0_ambpresent0 for channel '0'
  806. * b0_ambpresent1 for channel '1'
  807. * b1_ambpresent0 for channel '2'
  808. * b1_ambpresent1 for channel '3'
  809. */
  810. static int determine_amb_present_reg(struct i5000_pvt *pvt, int channel)
  811. {
  812. int amb_present;
  813. if (channel < CHANNELS_PER_BRANCH) {
  814. if (channel & 0x1)
  815. amb_present = pvt->b0_ambpresent1;
  816. else
  817. amb_present = pvt->b0_ambpresent0;
  818. } else {
  819. if (channel & 0x1)
  820. amb_present = pvt->b1_ambpresent1;
  821. else
  822. amb_present = pvt->b1_ambpresent0;
  823. }
  824. return amb_present;
  825. }
  826. /*
  827. * determine_mtr(pvt, csrow, channel)
  828. *
  829. * return the proper MTR register as determine by the csrow and channel desired
  830. */
  831. static int determine_mtr(struct i5000_pvt *pvt, int csrow, int channel)
  832. {
  833. int mtr;
  834. if (channel < CHANNELS_PER_BRANCH)
  835. mtr = pvt->b0_mtr[csrow >> 1];
  836. else
  837. mtr = pvt->b1_mtr[csrow >> 1];
  838. return mtr;
  839. }
  840. /*
  841. */
  842. static void decode_mtr(int slot_row, u16 mtr)
  843. {
  844. int ans;
  845. ans = MTR_DIMMS_PRESENT(mtr);
  846. debugf2("\tMTR%d=0x%x: DIMMs are %s\n", slot_row, mtr,
  847. ans ? "Present" : "NOT Present");
  848. if (!ans)
  849. return;
  850. debugf2("\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
  851. debugf2("\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
  852. debugf2("\t\tNUMRANK: %s\n", MTR_DIMM_RANK(mtr) ? "double" : "single");
  853. debugf2("\t\tNUMROW: %s\n", numrow_toString[MTR_DIMM_ROWS(mtr)]);
  854. debugf2("\t\tNUMCOL: %s\n", numcol_toString[MTR_DIMM_COLS(mtr)]);
  855. }
  856. static void handle_channel(struct i5000_pvt *pvt, int csrow, int channel,
  857. struct i5000_dimm_info *dinfo)
  858. {
  859. int mtr;
  860. int amb_present_reg;
  861. int addrBits;
  862. mtr = determine_mtr(pvt, csrow, channel);
  863. if (MTR_DIMMS_PRESENT(mtr)) {
  864. amb_present_reg = determine_amb_present_reg(pvt, channel);
  865. /* Determine if there is a DIMM present in this DIMM slot */
  866. if (amb_present_reg & (1 << (csrow >> 1))) {
  867. dinfo->dual_rank = MTR_DIMM_RANK(mtr);
  868. if (!((dinfo->dual_rank == 0) &&
  869. ((csrow & 0x1) == 0x1))) {
  870. /* Start with the number of bits for a Bank
  871. * on the DRAM */
  872. addrBits = MTR_DRAM_BANKS_ADDR_BITS(mtr);
  873. /* Add thenumber of ROW bits */
  874. addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
  875. /* add the number of COLUMN bits */
  876. addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
  877. addrBits += 6; /* add 64 bits per DIMM */
  878. addrBits -= 20; /* divide by 2^^20 */
  879. addrBits -= 3; /* 8 bits per bytes */
  880. dinfo->megabytes = 1 << addrBits;
  881. }
  882. }
  883. }
  884. }
  885. /*
  886. * calculate_dimm_size
  887. *
  888. * also will output a DIMM matrix map, if debug is enabled, for viewing
  889. * how the DIMMs are populated
  890. */
  891. static void calculate_dimm_size(struct i5000_pvt *pvt)
  892. {
  893. struct i5000_dimm_info *dinfo;
  894. int csrow, max_csrows;
  895. char *p, *mem_buffer;
  896. int space, n;
  897. int channel;
  898. /* ================= Generate some debug output ================= */
  899. space = PAGE_SIZE;
  900. mem_buffer = p = kmalloc(space, GFP_KERNEL);
  901. if (p == NULL) {
  902. i5000_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
  903. __FILE__, __func__);
  904. return;
  905. }
  906. n = snprintf(p, space, "\n");
  907. p += n;
  908. space -= n;
  909. /* Scan all the actual CSROWS (which is # of DIMMS * 2)
  910. * and calculate the information for each DIMM
  911. * Start with the highest csrow first, to display it first
  912. * and work toward the 0th csrow
  913. */
  914. max_csrows = pvt->maxdimmperch * 2;
  915. for (csrow = max_csrows - 1; csrow >= 0; csrow--) {
  916. /* on an odd csrow, first output a 'boundary' marker,
  917. * then reset the message buffer */
  918. if (csrow & 0x1) {
  919. n = snprintf(p, space, "---------------------------"
  920. "--------------------------------");
  921. p += n;
  922. space -= n;
  923. debugf2("%s\n", mem_buffer);
  924. p = mem_buffer;
  925. space = PAGE_SIZE;
  926. }
  927. n = snprintf(p, space, "csrow %2d ", csrow);
  928. p += n;
  929. space -= n;
  930. for (channel = 0; channel < pvt->maxch; channel++) {
  931. dinfo = &pvt->dimm_info[csrow][channel];
  932. handle_channel(pvt, csrow, channel, dinfo);
  933. n = snprintf(p, space, "%4d MB | ", dinfo->megabytes);
  934. p += n;
  935. space -= n;
  936. }
  937. n = snprintf(p, space, "\n");
  938. p += n;
  939. space -= n;
  940. }
  941. /* Output the last bottom 'boundary' marker */
  942. n = snprintf(p, space, "---------------------------"
  943. "--------------------------------\n");
  944. p += n;
  945. space -= n;
  946. /* now output the 'channel' labels */
  947. n = snprintf(p, space, " ");
  948. p += n;
  949. space -= n;
  950. for (channel = 0; channel < pvt->maxch; channel++) {
  951. n = snprintf(p, space, "channel %d | ", channel);
  952. p += n;
  953. space -= n;
  954. }
  955. n = snprintf(p, space, "\n");
  956. p += n;
  957. space -= n;
  958. /* output the last message and free buffer */
  959. debugf2("%s\n", mem_buffer);
  960. kfree(mem_buffer);
  961. }
  962. /*
  963. * i5000_get_mc_regs read in the necessary registers and
  964. * cache locally
  965. *
  966. * Fills in the private data members
  967. */
  968. static void i5000_get_mc_regs(struct mem_ctl_info *mci)
  969. {
  970. struct i5000_pvt *pvt;
  971. u32 actual_tolm;
  972. u16 limit;
  973. int slot_row;
  974. int maxch;
  975. int maxdimmperch;
  976. int way0, way1;
  977. pvt = mci->pvt_info;
  978. pci_read_config_dword(pvt->system_address, AMBASE,
  979. (u32 *) & pvt->ambase);
  980. pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
  981. ((u32 *) & pvt->ambase) + sizeof(u32));
  982. maxdimmperch = pvt->maxdimmperch;
  983. maxch = pvt->maxch;
  984. debugf2("AMBASE= 0x%lx MAXCH= %d MAX-DIMM-Per-CH= %d\n",
  985. (long unsigned int)pvt->ambase, pvt->maxch, pvt->maxdimmperch);
  986. /* Get the Branch Map regs */
  987. pci_read_config_word(pvt->branchmap_werrors, TOLM, &pvt->tolm);
  988. pvt->tolm >>= 12;
  989. debugf2("\nTOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
  990. pvt->tolm);
  991. actual_tolm = pvt->tolm << 28;
  992. debugf2("Actual TOLM byte addr=%u (0x%x)\n", actual_tolm, actual_tolm);
  993. pci_read_config_word(pvt->branchmap_werrors, MIR0, &pvt->mir0);
  994. pci_read_config_word(pvt->branchmap_werrors, MIR1, &pvt->mir1);
  995. pci_read_config_word(pvt->branchmap_werrors, MIR2, &pvt->mir2);
  996. /* Get the MIR[0-2] regs */
  997. limit = (pvt->mir0 >> 4) & 0x0FFF;
  998. way0 = pvt->mir0 & 0x1;
  999. way1 = pvt->mir0 & 0x2;
  1000. debugf2("MIR0: limit= 0x%x WAY1= %u WAY0= %x\n", limit, way1, way0);
  1001. limit = (pvt->mir1 >> 4) & 0x0FFF;
  1002. way0 = pvt->mir1 & 0x1;
  1003. way1 = pvt->mir1 & 0x2;
  1004. debugf2("MIR1: limit= 0x%x WAY1= %u WAY0= %x\n", limit, way1, way0);
  1005. limit = (pvt->mir2 >> 4) & 0x0FFF;
  1006. way0 = pvt->mir2 & 0x1;
  1007. way1 = pvt->mir2 & 0x2;
  1008. debugf2("MIR2: limit= 0x%x WAY1= %u WAY0= %x\n", limit, way1, way0);
  1009. /* Get the MTR[0-3] regs */
  1010. for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
  1011. int where = MTR0 + (slot_row * sizeof(u32));
  1012. pci_read_config_word(pvt->branch_0, where,
  1013. &pvt->b0_mtr[slot_row]);
  1014. debugf2("MTR%d where=0x%x B0 value=0x%x\n", slot_row, where,
  1015. pvt->b0_mtr[slot_row]);
  1016. if (pvt->maxch >= CHANNELS_PER_BRANCH) {
  1017. pci_read_config_word(pvt->branch_1, where,
  1018. &pvt->b1_mtr[slot_row]);
  1019. debugf2("MTR%d where=0x%x B1 value=0x%x\n", slot_row,
  1020. where, pvt->b1_mtr[slot_row]);
  1021. } else {
  1022. pvt->b1_mtr[slot_row] = 0;
  1023. }
  1024. }
  1025. /* Read and dump branch 0's MTRs */
  1026. debugf2("\nMemory Technology Registers:\n");
  1027. debugf2(" Branch 0:\n");
  1028. for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
  1029. decode_mtr(slot_row, pvt->b0_mtr[slot_row]);
  1030. }
  1031. pci_read_config_word(pvt->branch_0, AMB_PRESENT_0,
  1032. &pvt->b0_ambpresent0);
  1033. debugf2("\t\tAMB-Branch 0-present0 0x%x:\n", pvt->b0_ambpresent0);
  1034. pci_read_config_word(pvt->branch_0, AMB_PRESENT_1,
  1035. &pvt->b0_ambpresent1);
  1036. debugf2("\t\tAMB-Branch 0-present1 0x%x:\n", pvt->b0_ambpresent1);
  1037. /* Only if we have 2 branchs (4 channels) */
  1038. if (pvt->maxch < CHANNELS_PER_BRANCH) {
  1039. pvt->b1_ambpresent0 = 0;
  1040. pvt->b1_ambpresent1 = 0;
  1041. } else {
  1042. /* Read and dump branch 1's MTRs */
  1043. debugf2(" Branch 1:\n");
  1044. for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
  1045. decode_mtr(slot_row, pvt->b1_mtr[slot_row]);
  1046. }
  1047. pci_read_config_word(pvt->branch_1, AMB_PRESENT_0,
  1048. &pvt->b1_ambpresent0);
  1049. debugf2("\t\tAMB-Branch 1-present0 0x%x:\n",
  1050. pvt->b1_ambpresent0);
  1051. pci_read_config_word(pvt->branch_1, AMB_PRESENT_1,
  1052. &pvt->b1_ambpresent1);
  1053. debugf2("\t\tAMB-Branch 1-present1 0x%x:\n",
  1054. pvt->b1_ambpresent1);
  1055. }
  1056. /* Go and determine the size of each DIMM and place in an
  1057. * orderly matrix */
  1058. calculate_dimm_size(pvt);
  1059. }
  1060. /*
  1061. * i5000_init_csrows Initialize the 'csrows' table within
  1062. * the mci control structure with the
  1063. * addressing of memory.
  1064. *
  1065. * return:
  1066. * 0 success
  1067. * 1 no actual memory found on this MC
  1068. */
  1069. static int i5000_init_csrows(struct mem_ctl_info *mci)
  1070. {
  1071. struct i5000_pvt *pvt;
  1072. struct csrow_info *p_csrow;
  1073. int empty, channel_count;
  1074. int max_csrows;
  1075. int mtr, mtr1;
  1076. int csrow_megs;
  1077. int channel;
  1078. int csrow;
  1079. pvt = mci->pvt_info;
  1080. channel_count = pvt->maxch;
  1081. max_csrows = pvt->maxdimmperch * 2;
  1082. empty = 1; /* Assume NO memory */
  1083. for (csrow = 0; csrow < max_csrows; csrow++) {
  1084. p_csrow = &mci->csrows[csrow];
  1085. p_csrow->csrow_idx = csrow;
  1086. /* use branch 0 for the basis */
  1087. mtr = pvt->b0_mtr[csrow >> 1];
  1088. mtr1 = pvt->b1_mtr[csrow >> 1];
  1089. /* if no DIMMS on this row, continue */
  1090. if (!MTR_DIMMS_PRESENT(mtr) && !MTR_DIMMS_PRESENT(mtr1))
  1091. continue;
  1092. /* FAKE OUT VALUES, FIXME */
  1093. p_csrow->first_page = 0 + csrow * 20;
  1094. p_csrow->last_page = 9 + csrow * 20;
  1095. p_csrow->page_mask = 0xFFF;
  1096. p_csrow->grain = 8;
  1097. csrow_megs = 0;
  1098. for (channel = 0; channel < pvt->maxch; channel++) {
  1099. csrow_megs += pvt->dimm_info[csrow][channel].megabytes;
  1100. }
  1101. p_csrow->nr_pages = csrow_megs << 8;
  1102. /* Assume DDR2 for now */
  1103. p_csrow->mtype = MEM_FB_DDR2;
  1104. /* ask what device type on this row */
  1105. if (MTR_DRAM_WIDTH(mtr))
  1106. p_csrow->dtype = DEV_X8;
  1107. else
  1108. p_csrow->dtype = DEV_X4;
  1109. p_csrow->edac_mode = EDAC_S8ECD8ED;
  1110. empty = 0;
  1111. }
  1112. return empty;
  1113. }
  1114. /*
  1115. * i5000_enable_error_reporting
  1116. * Turn on the memory reporting features of the hardware
  1117. */
  1118. static void i5000_enable_error_reporting(struct mem_ctl_info *mci)
  1119. {
  1120. struct i5000_pvt *pvt;
  1121. u32 fbd_error_mask;
  1122. pvt = mci->pvt_info;
  1123. /* Read the FBD Error Mask Register */
  1124. pci_read_config_dword(pvt->branchmap_werrors, EMASK_FBD,
  1125. &fbd_error_mask);
  1126. /* Enable with a '0' */
  1127. fbd_error_mask &= ~(ENABLE_EMASK_ALL);
  1128. pci_write_config_dword(pvt->branchmap_werrors, EMASK_FBD,
  1129. fbd_error_mask);
  1130. }
  1131. /*
  1132. * i5000_get_dimm_and_channel_counts(pdev, &num_csrows, &num_channels)
  1133. *
  1134. * ask the device how many channels are present and how many CSROWS
  1135. * as well
  1136. */
  1137. static void i5000_get_dimm_and_channel_counts(struct pci_dev *pdev,
  1138. int *num_dimms_per_channel,
  1139. int *num_channels)
  1140. {
  1141. u8 value;
  1142. /* Need to retrieve just how many channels and dimms per channel are
  1143. * supported on this memory controller
  1144. */
  1145. pci_read_config_byte(pdev, MAXDIMMPERCH, &value);
  1146. *num_dimms_per_channel = (int)value *2;
  1147. pci_read_config_byte(pdev, MAXCH, &value);
  1148. *num_channels = (int)value;
  1149. }
  1150. /*
  1151. * i5000_probe1 Probe for ONE instance of device to see if it is
  1152. * present.
  1153. * return:
  1154. * 0 for FOUND a device
  1155. * < 0 for error code
  1156. */
  1157. static int i5000_probe1(struct pci_dev *pdev, int dev_idx)
  1158. {
  1159. struct mem_ctl_info *mci;
  1160. struct i5000_pvt *pvt;
  1161. int num_channels;
  1162. int num_dimms_per_channel;
  1163. int num_csrows;
  1164. debugf0("MC: %s: %s(), pdev bus %u dev=0x%x fn=0x%x\n",
  1165. __FILE__, __func__,
  1166. pdev->bus->number,
  1167. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  1168. /* We only are looking for func 0 of the set */
  1169. if (PCI_FUNC(pdev->devfn) != 0)
  1170. return -ENODEV;
  1171. /* Ask the devices for the number of CSROWS and CHANNELS so
  1172. * that we can calculate the memory resources, etc
  1173. *
  1174. * The Chipset will report what it can handle which will be greater
  1175. * or equal to what the motherboard manufacturer will implement.
  1176. *
  1177. * As we don't have a motherboard identification routine to determine
  1178. * actual number of slots/dimms per channel, we thus utilize the
  1179. * resource as specified by the chipset. Thus, we might have
  1180. * have more DIMMs per channel than actually on the mobo, but this
  1181. * allows the driver to support up to the chipset max, without
  1182. * some fancy mobo determination.
  1183. */
  1184. i5000_get_dimm_and_channel_counts(pdev, &num_dimms_per_channel,
  1185. &num_channels);
  1186. num_csrows = num_dimms_per_channel * 2;
  1187. debugf0("MC: %s(): Number of - Channels= %d DIMMS= %d CSROWS= %d\n",
  1188. __func__, num_channels, num_dimms_per_channel, num_csrows);
  1189. /* allocate a new MC control structure */
  1190. mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0);
  1191. if (mci == NULL)
  1192. return -ENOMEM;
  1193. kobject_get(&mci->edac_mci_kobj);
  1194. debugf0("MC: %s: %s(): mci = %p\n", __FILE__, __func__, mci);
  1195. mci->dev = &pdev->dev; /* record ptr to the generic device */
  1196. pvt = mci->pvt_info;
  1197. pvt->system_address = pdev; /* Record this device in our private */
  1198. pvt->maxch = num_channels;
  1199. pvt->maxdimmperch = num_dimms_per_channel;
  1200. /* 'get' the pci devices we want to reserve for our use */
  1201. if (i5000_get_devices(mci, dev_idx))
  1202. goto fail0;
  1203. /* Time to get serious */
  1204. i5000_get_mc_regs(mci); /* retrieve the hardware registers */
  1205. mci->mc_idx = 0;
  1206. mci->mtype_cap = MEM_FLAG_FB_DDR2;
  1207. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  1208. mci->edac_cap = EDAC_FLAG_NONE;
  1209. mci->mod_name = "i5000_edac.c";
  1210. mci->mod_ver = I5000_REVISION;
  1211. mci->ctl_name = i5000_devs[dev_idx].ctl_name;
  1212. mci->dev_name = pci_name(pdev);
  1213. mci->ctl_page_to_phys = NULL;
  1214. /* Set the function pointer to an actual operation function */
  1215. mci->edac_check = i5000_check_error;
  1216. /* initialize the MC control structure 'csrows' table
  1217. * with the mapping and control information */
  1218. if (i5000_init_csrows(mci)) {
  1219. debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
  1220. " because i5000_init_csrows() returned nonzero "
  1221. "value\n");
  1222. mci->edac_cap = EDAC_FLAG_NONE; /* no csrows found */
  1223. } else {
  1224. debugf1("MC: Enable error reporting now\n");
  1225. i5000_enable_error_reporting(mci);
  1226. }
  1227. /* add this new MC control structure to EDAC's list of MCs */
  1228. if (edac_mc_add_mc(mci)) {
  1229. debugf0("MC: %s: %s(): failed edac_mc_add_mc()\n",
  1230. __FILE__, __func__);
  1231. /* FIXME: perhaps some code should go here that disables error
  1232. * reporting if we just enabled it
  1233. */
  1234. goto fail1;
  1235. }
  1236. i5000_clear_error(mci);
  1237. /* allocating generic PCI control info */
  1238. i5000_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  1239. if (!i5000_pci) {
  1240. printk(KERN_WARNING
  1241. "%s(): Unable to create PCI control\n",
  1242. __func__);
  1243. printk(KERN_WARNING
  1244. "%s(): PCI error report via EDAC not setup\n",
  1245. __func__);
  1246. }
  1247. return 0;
  1248. /* Error exit unwinding stack */
  1249. fail1:
  1250. i5000_put_devices(mci);
  1251. fail0:
  1252. kobject_put(&mci->edac_mci_kobj);
  1253. edac_mc_free(mci);
  1254. return -ENODEV;
  1255. }
  1256. /*
  1257. * i5000_init_one constructor for one instance of device
  1258. *
  1259. * returns:
  1260. * negative on error
  1261. * count (>= 0)
  1262. */
  1263. static int __devinit i5000_init_one(struct pci_dev *pdev,
  1264. const struct pci_device_id *id)
  1265. {
  1266. int rc;
  1267. debugf0("MC: %s: %s()\n", __FILE__, __func__);
  1268. /* wake up device */
  1269. rc = pci_enable_device(pdev);
  1270. if (rc)
  1271. return rc;
  1272. /* now probe and enable the device */
  1273. return i5000_probe1(pdev, id->driver_data);
  1274. }
  1275. /*
  1276. * i5000_remove_one destructor for one instance of device
  1277. *
  1278. */
  1279. static void __devexit i5000_remove_one(struct pci_dev *pdev)
  1280. {
  1281. struct mem_ctl_info *mci;
  1282. debugf0("%s: %s()\n", __FILE__, __func__);
  1283. if (i5000_pci)
  1284. edac_pci_release_generic_ctl(i5000_pci);
  1285. if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
  1286. return;
  1287. /* retrieve references to resources, and free those resources */
  1288. i5000_put_devices(mci);
  1289. kobject_put(&mci->edac_mci_kobj);
  1290. edac_mc_free(mci);
  1291. }
  1292. /*
  1293. * pci_device_id table for which devices we are looking for
  1294. *
  1295. * The "E500P" device is the first device supported.
  1296. */
  1297. static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
  1298. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
  1299. .driver_data = I5000P},
  1300. {0,} /* 0 terminated list. */
  1301. };
  1302. MODULE_DEVICE_TABLE(pci, i5000_pci_tbl);
  1303. /*
  1304. * i5000_driver pci_driver structure for this module
  1305. *
  1306. */
  1307. static struct pci_driver i5000_driver = {
  1308. .name = KBUILD_BASENAME,
  1309. .probe = i5000_init_one,
  1310. .remove = __devexit_p(i5000_remove_one),
  1311. .id_table = i5000_pci_tbl,
  1312. };
  1313. /*
  1314. * i5000_init Module entry function
  1315. * Try to initialize this module for its devices
  1316. */
  1317. static int __init i5000_init(void)
  1318. {
  1319. int pci_rc;
  1320. debugf2("MC: %s: %s()\n", __FILE__, __func__);
  1321. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1322. opstate_init();
  1323. pci_rc = pci_register_driver(&i5000_driver);
  1324. return (pci_rc < 0) ? pci_rc : 0;
  1325. }
  1326. /*
  1327. * i5000_exit() Module exit function
  1328. * Unregister the driver
  1329. */
  1330. static void __exit i5000_exit(void)
  1331. {
  1332. debugf2("MC: %s: %s()\n", __FILE__, __func__);
  1333. pci_unregister_driver(&i5000_driver);
  1334. }
  1335. module_init(i5000_init);
  1336. module_exit(i5000_exit);
  1337. MODULE_LICENSE("GPL");
  1338. MODULE_AUTHOR
  1339. ("Linux Networx (http://lnxi.com) Doug Thompson <norsk5@xmission.com>");
  1340. MODULE_DESCRIPTION("MC Driver for Intel I5000 memory controllers - "
  1341. I5000_REVISION);
  1342. module_param(edac_op_state, int, 0444);
  1343. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
  1344. module_param(misc_messages, int, 0444);
  1345. MODULE_PARM_DESC(misc_messages, "Log miscellaneous non fatal messages");