i5000_edac.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598
  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. #define MAX_BRANCHES 2
  248. /* Defines to extract the vaious fields from the
  249. * MTRx - Memory Technology Registers
  250. */
  251. #define MTR_DIMMS_PRESENT(mtr) ((mtr) & (0x1 << 8))
  252. #define MTR_DRAM_WIDTH(mtr) ((((mtr) >> 6) & 0x1) ? 8 : 4)
  253. #define MTR_DRAM_BANKS(mtr) ((((mtr) >> 5) & 0x1) ? 8 : 4)
  254. #define MTR_DRAM_BANKS_ADDR_BITS(mtr) ((MTR_DRAM_BANKS(mtr) == 8) ? 3 : 2)
  255. #define MTR_DIMM_RANK(mtr) (((mtr) >> 4) & 0x1)
  256. #define MTR_DIMM_RANK_ADDR_BITS(mtr) (MTR_DIMM_RANK(mtr) ? 2 : 1)
  257. #define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
  258. #define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
  259. #define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
  260. #define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
  261. #ifdef CONFIG_EDAC_DEBUG
  262. static char *numrow_toString[] = {
  263. "8,192 - 13 rows",
  264. "16,384 - 14 rows",
  265. "32,768 - 15 rows",
  266. "reserved"
  267. };
  268. static char *numcol_toString[] = {
  269. "1,024 - 10 columns",
  270. "2,048 - 11 columns",
  271. "4,096 - 12 columns",
  272. "reserved"
  273. };
  274. #endif
  275. /* enables the report of miscellaneous messages as CE errors - default off */
  276. static int misc_messages;
  277. /* Enumeration of supported devices */
  278. enum i5000_chips {
  279. I5000P = 0,
  280. I5000V = 1, /* future */
  281. I5000X = 2 /* future */
  282. };
  283. /* Device name and register DID (Device ID) */
  284. struct i5000_dev_info {
  285. const char *ctl_name; /* name for this device */
  286. u16 fsb_mapping_errors; /* DID for the branchmap,control */
  287. };
  288. /* Table of devices attributes supported by this driver */
  289. static const struct i5000_dev_info i5000_devs[] = {
  290. [I5000P] = {
  291. .ctl_name = "I5000",
  292. .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I5000_DEV16,
  293. },
  294. };
  295. struct i5000_dimm_info {
  296. int megabytes; /* size, 0 means not present */
  297. int dual_rank;
  298. };
  299. #define MAX_CHANNELS 6 /* max possible channels */
  300. #define MAX_CSROWS (8*2) /* max possible csrows per channel */
  301. /* driver private data structure */
  302. struct i5000_pvt {
  303. struct pci_dev *system_address; /* 16.0 */
  304. struct pci_dev *branchmap_werrors; /* 16.1 */
  305. struct pci_dev *fsb_error_regs; /* 16.2 */
  306. struct pci_dev *branch_0; /* 21.0 */
  307. struct pci_dev *branch_1; /* 22.0 */
  308. u16 tolm; /* top of low memory */
  309. u64 ambase; /* AMB BAR */
  310. u16 mir0, mir1, mir2;
  311. u16 b0_mtr[NUM_MTRS]; /* Memory Technlogy Reg */
  312. u16 b0_ambpresent0; /* Branch 0, Channel 0 */
  313. u16 b0_ambpresent1; /* Brnach 0, Channel 1 */
  314. u16 b1_mtr[NUM_MTRS]; /* Memory Technlogy Reg */
  315. u16 b1_ambpresent0; /* Branch 1, Channel 8 */
  316. u16 b1_ambpresent1; /* Branch 1, Channel 1 */
  317. /* DIMM information matrix, allocating architecture maximums */
  318. struct i5000_dimm_info dimm_info[MAX_CSROWS][MAX_CHANNELS];
  319. /* Actual values for this controller */
  320. int maxch; /* Max channels */
  321. int maxdimmperch; /* Max DIMMs per channel */
  322. };
  323. /* I5000 MCH error information retrieved from Hardware */
  324. struct i5000_error_info {
  325. /* These registers are always read from the MC */
  326. u32 ferr_fat_fbd; /* First Errors Fatal */
  327. u32 nerr_fat_fbd; /* Next Errors Fatal */
  328. u32 ferr_nf_fbd; /* First Errors Non-Fatal */
  329. u32 nerr_nf_fbd; /* Next Errors Non-Fatal */
  330. /* These registers are input ONLY if there was a Recoverable Error */
  331. u32 redmemb; /* Recoverable Mem Data Error log B */
  332. u16 recmema; /* Recoverable Mem Error log A */
  333. u32 recmemb; /* Recoverable Mem Error log B */
  334. /* These registers are input ONLY if there was a
  335. * Non-Recoverable Error */
  336. u16 nrecmema; /* Non-Recoverable Mem log A */
  337. u16 nrecmemb; /* Non-Recoverable Mem log B */
  338. };
  339. static struct edac_pci_ctl_info *i5000_pci;
  340. /*
  341. * i5000_get_error_info Retrieve the hardware error information from
  342. * the hardware and cache it in the 'info'
  343. * structure
  344. */
  345. static void i5000_get_error_info(struct mem_ctl_info *mci,
  346. struct i5000_error_info *info)
  347. {
  348. struct i5000_pvt *pvt;
  349. u32 value;
  350. pvt = mci->pvt_info;
  351. /* read in the 1st FATAL error register */
  352. pci_read_config_dword(pvt->branchmap_werrors, FERR_FAT_FBD, &value);
  353. /* Mask only the bits that the doc says are valid
  354. */
  355. value &= (FERR_FAT_FBDCHAN | FERR_FAT_MASK);
  356. /* If there is an error, then read in the */
  357. /* NEXT FATAL error register and the Memory Error Log Register A */
  358. if (value & FERR_FAT_MASK) {
  359. info->ferr_fat_fbd = value;
  360. /* harvest the various error data we need */
  361. pci_read_config_dword(pvt->branchmap_werrors,
  362. NERR_FAT_FBD, &info->nerr_fat_fbd);
  363. pci_read_config_word(pvt->branchmap_werrors,
  364. NRECMEMA, &info->nrecmema);
  365. pci_read_config_word(pvt->branchmap_werrors,
  366. NRECMEMB, &info->nrecmemb);
  367. /* Clear the error bits, by writing them back */
  368. pci_write_config_dword(pvt->branchmap_werrors,
  369. FERR_FAT_FBD, value);
  370. } else {
  371. info->ferr_fat_fbd = 0;
  372. info->nerr_fat_fbd = 0;
  373. info->nrecmema = 0;
  374. info->nrecmemb = 0;
  375. }
  376. /* read in the 1st NON-FATAL error register */
  377. pci_read_config_dword(pvt->branchmap_werrors, FERR_NF_FBD, &value);
  378. /* If there is an error, then read in the 1st NON-FATAL error
  379. * register as well */
  380. if (value & FERR_NF_MASK) {
  381. info->ferr_nf_fbd = value;
  382. /* harvest the various error data we need */
  383. pci_read_config_dword(pvt->branchmap_werrors,
  384. NERR_NF_FBD, &info->nerr_nf_fbd);
  385. pci_read_config_word(pvt->branchmap_werrors,
  386. RECMEMA, &info->recmema);
  387. pci_read_config_dword(pvt->branchmap_werrors,
  388. RECMEMB, &info->recmemb);
  389. pci_read_config_dword(pvt->branchmap_werrors,
  390. REDMEMB, &info->redmemb);
  391. /* Clear the error bits, by writing them back */
  392. pci_write_config_dword(pvt->branchmap_werrors,
  393. FERR_NF_FBD, value);
  394. } else {
  395. info->ferr_nf_fbd = 0;
  396. info->nerr_nf_fbd = 0;
  397. info->recmema = 0;
  398. info->recmemb = 0;
  399. info->redmemb = 0;
  400. }
  401. }
  402. /*
  403. * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
  404. * struct i5000_error_info *info,
  405. * int handle_errors);
  406. *
  407. * handle the Intel FATAL errors, if any
  408. */
  409. static void i5000_process_fatal_error_info(struct mem_ctl_info *mci,
  410. struct i5000_error_info *info,
  411. int handle_errors)
  412. {
  413. char msg[EDAC_MC_LABEL_LEN + 1 + 160];
  414. char *specific = NULL;
  415. u32 allErrors;
  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. channel = EXTRACT_FBDCHAN_INDX(info->ferr_fat_fbd);
  426. /* Use the NON-Recoverable macros to extract data */
  427. bank = NREC_BANK(info->nrecmema);
  428. rank = NREC_RANK(info->nrecmema);
  429. rdwr = NREC_RDWR(info->nrecmema);
  430. ras = NREC_RAS(info->nrecmemb);
  431. cas = NREC_CAS(info->nrecmemb);
  432. debugf0("\t\tCSROW= %d Channel= %d "
  433. "(DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  434. rank, channel, bank,
  435. rdwr ? "Write" : "Read", ras, cas);
  436. /* Only 1 bit will be on */
  437. switch (allErrors) {
  438. case FERR_FAT_M1ERR:
  439. specific = "Alert on non-redundant retry or fast "
  440. "reset timeout";
  441. break;
  442. case FERR_FAT_M2ERR:
  443. specific = "Northbound CRC error on non-redundant "
  444. "retry";
  445. break;
  446. case FERR_FAT_M3ERR:
  447. {
  448. static int done;
  449. /*
  450. * This error is generated to inform that the intelligent
  451. * throttling is disabled and the temperature passed the
  452. * specified middle point. Since this is something the BIOS
  453. * should take care of, we'll warn only once to avoid
  454. * worthlessly flooding the log.
  455. */
  456. if (done)
  457. return;
  458. done++;
  459. specific = ">Tmid Thermal event with intelligent "
  460. "throttling disabled";
  461. }
  462. break;
  463. }
  464. /* Form out message */
  465. snprintf(msg, sizeof(msg),
  466. "Bank=%d RAS=%d CAS=%d FATAL Err=0x%x (%s)",
  467. bank, ras, cas, allErrors, specific);
  468. /* Call the helper to output message */
  469. edac_mc_handle_error(HW_EVENT_ERR_FATAL, mci, 0, 0, 0,
  470. channel >> 1, channel & 1, rank,
  471. rdwr ? "Write error" : "Read error",
  472. msg, NULL);
  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. "Rank=%d Bank=%d RAS=%d CAS=%d, UE Err=0x%x (%s)",
  558. rank, bank, ras, cas, ue_errors, specific);
  559. /* Call the helper to output message */
  560. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 0, 0, 0,
  561. channel >> 1, -1, rank,
  562. rdwr ? "Write error" : "Read error",
  563. msg, NULL);
  564. }
  565. /* Check correctable errors */
  566. ce_errors = allErrors & FERR_NF_CORRECTABLE;
  567. if (ce_errors) {
  568. debugf0("\tCorrected bits= 0x%x\n", ce_errors);
  569. branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
  570. channel = 0;
  571. if (REC_ECC_LOCATOR_ODD(info->redmemb))
  572. channel = 1;
  573. /* Convert channel to be based from zero, instead of
  574. * from branch base of 0 */
  575. channel += branch;
  576. bank = REC_BANK(info->recmema);
  577. rank = REC_RANK(info->recmema);
  578. rdwr = REC_RDWR(info->recmema);
  579. ras = REC_RAS(info->recmemb);
  580. cas = REC_CAS(info->recmemb);
  581. debugf0("\t\tCSROW= %d Channel= %d (Branch %d "
  582. "DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  583. rank, channel, branch >> 1, bank,
  584. rdwr ? "Write" : "Read", ras, cas);
  585. switch (ce_errors) {
  586. case FERR_NF_M17ERR:
  587. specific = "Correctable Non-Mirrored Demand Data ECC";
  588. break;
  589. case FERR_NF_M18ERR:
  590. specific = "Correctable Mirrored Demand Data ECC";
  591. break;
  592. case FERR_NF_M19ERR:
  593. specific = "Correctable Spare-Copy Data ECC";
  594. break;
  595. case FERR_NF_M20ERR:
  596. specific = "Correctable Patrol Data ECC";
  597. break;
  598. }
  599. /* Form out message */
  600. snprintf(msg, sizeof(msg),
  601. "Rank=%d Bank=%d RDWR=%s RAS=%d "
  602. "CAS=%d, CE Err=0x%x (%s))", branch >> 1, bank,
  603. rdwr ? "Write" : "Read", ras, cas, ce_errors,
  604. specific);
  605. /* Call the helper to output message */
  606. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 0, 0, 0,
  607. channel >> 1, channel % 2, rank,
  608. rdwr ? "Write error" : "Read error",
  609. msg, NULL);
  610. }
  611. if (!misc_messages)
  612. return;
  613. misc_errors = allErrors & (FERR_NF_NON_RETRY | FERR_NF_NORTH_CRC |
  614. FERR_NF_SPD_PROTOCOL | FERR_NF_DIMM_SPARE);
  615. if (misc_errors) {
  616. switch (misc_errors) {
  617. case FERR_NF_M13ERR:
  618. specific = "Non-Retry or Redundant Retry FBD Memory "
  619. "Alert or Redundant Fast Reset Timeout";
  620. break;
  621. case FERR_NF_M14ERR:
  622. specific = "Non-Retry or Redundant Retry FBD "
  623. "Configuration Alert";
  624. break;
  625. case FERR_NF_M15ERR:
  626. specific = "Non-Retry or Redundant Retry FBD "
  627. "Northbound CRC error on read data";
  628. break;
  629. case FERR_NF_M21ERR:
  630. specific = "FBD Northbound CRC error on "
  631. "FBD Sync Status";
  632. break;
  633. case FERR_NF_M22ERR:
  634. specific = "SPD protocol error";
  635. break;
  636. case FERR_NF_M27ERR:
  637. specific = "DIMM-spare copy started";
  638. break;
  639. case FERR_NF_M28ERR:
  640. specific = "DIMM-spare copy completed";
  641. break;
  642. }
  643. branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
  644. /* Form out message */
  645. snprintf(msg, sizeof(msg),
  646. "Err=%#x (%s)", misc_errors, specific);
  647. /* Call the helper to output message */
  648. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 0, 0, 0,
  649. branch >> 1, -1, -1,
  650. "Misc error", msg, NULL);
  651. }
  652. }
  653. /*
  654. * i5000_process_error_info Process the error info that is
  655. * in the 'info' structure, previously retrieved from hardware
  656. */
  657. static void i5000_process_error_info(struct mem_ctl_info *mci,
  658. struct i5000_error_info *info,
  659. int handle_errors)
  660. {
  661. /* First handle any fatal errors that occurred */
  662. i5000_process_fatal_error_info(mci, info, handle_errors);
  663. /* now handle any non-fatal errors that occurred */
  664. i5000_process_nonfatal_error_info(mci, info, handle_errors);
  665. }
  666. /*
  667. * i5000_clear_error Retrieve any error from the hardware
  668. * but do NOT process that error.
  669. * Used for 'clearing' out of previous errors
  670. * Called by the Core module.
  671. */
  672. static void i5000_clear_error(struct mem_ctl_info *mci)
  673. {
  674. struct i5000_error_info info;
  675. i5000_get_error_info(mci, &info);
  676. }
  677. /*
  678. * i5000_check_error Retrieve and process errors reported by the
  679. * hardware. Called by the Core module.
  680. */
  681. static void i5000_check_error(struct mem_ctl_info *mci)
  682. {
  683. struct i5000_error_info info;
  684. debugf4("MC%d: %s: %s()\n", mci->mc_idx, __FILE__, __func__);
  685. i5000_get_error_info(mci, &info);
  686. i5000_process_error_info(mci, &info, 1);
  687. }
  688. /*
  689. * i5000_get_devices Find and perform 'get' operation on the MCH's
  690. * device/functions we want to reference for this driver
  691. *
  692. * Need to 'get' device 16 func 1 and func 2
  693. */
  694. static int i5000_get_devices(struct mem_ctl_info *mci, int dev_idx)
  695. {
  696. //const struct i5000_dev_info *i5000_dev = &i5000_devs[dev_idx];
  697. struct i5000_pvt *pvt;
  698. struct pci_dev *pdev;
  699. pvt = mci->pvt_info;
  700. /* Attempt to 'get' the MCH register we want */
  701. pdev = NULL;
  702. while (1) {
  703. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  704. PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
  705. /* End of list, leave */
  706. if (pdev == NULL) {
  707. i5000_printk(KERN_ERR,
  708. "'system address,Process Bus' "
  709. "device not found:"
  710. "vendor 0x%x device 0x%x FUNC 1 "
  711. "(broken BIOS?)\n",
  712. PCI_VENDOR_ID_INTEL,
  713. PCI_DEVICE_ID_INTEL_I5000_DEV16);
  714. return 1;
  715. }
  716. /* Scan for device 16 func 1 */
  717. if (PCI_FUNC(pdev->devfn) == 1)
  718. break;
  719. }
  720. pvt->branchmap_werrors = pdev;
  721. /* Attempt to 'get' the MCH register we want */
  722. pdev = NULL;
  723. while (1) {
  724. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  725. PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
  726. if (pdev == NULL) {
  727. i5000_printk(KERN_ERR,
  728. "MC: 'branchmap,control,errors' "
  729. "device not found:"
  730. "vendor 0x%x device 0x%x Func 2 "
  731. "(broken BIOS?)\n",
  732. PCI_VENDOR_ID_INTEL,
  733. PCI_DEVICE_ID_INTEL_I5000_DEV16);
  734. pci_dev_put(pvt->branchmap_werrors);
  735. return 1;
  736. }
  737. /* Scan for device 16 func 1 */
  738. if (PCI_FUNC(pdev->devfn) == 2)
  739. break;
  740. }
  741. pvt->fsb_error_regs = pdev;
  742. debugf1("System Address, processor bus- PCI Bus ID: %s %x:%x\n",
  743. pci_name(pvt->system_address),
  744. pvt->system_address->vendor, pvt->system_address->device);
  745. debugf1("Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
  746. pci_name(pvt->branchmap_werrors),
  747. pvt->branchmap_werrors->vendor, pvt->branchmap_werrors->device);
  748. debugf1("FSB Error Regs - PCI Bus ID: %s %x:%x\n",
  749. pci_name(pvt->fsb_error_regs),
  750. pvt->fsb_error_regs->vendor, pvt->fsb_error_regs->device);
  751. pdev = NULL;
  752. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  753. PCI_DEVICE_ID_I5000_BRANCH_0, pdev);
  754. if (pdev == NULL) {
  755. i5000_printk(KERN_ERR,
  756. "MC: 'BRANCH 0' device not found:"
  757. "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
  758. PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_I5000_BRANCH_0);
  759. pci_dev_put(pvt->branchmap_werrors);
  760. pci_dev_put(pvt->fsb_error_regs);
  761. return 1;
  762. }
  763. pvt->branch_0 = pdev;
  764. /* If this device claims to have more than 2 channels then
  765. * fetch Branch 1's information
  766. */
  767. if (pvt->maxch >= CHANNELS_PER_BRANCH) {
  768. pdev = NULL;
  769. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  770. PCI_DEVICE_ID_I5000_BRANCH_1, pdev);
  771. if (pdev == NULL) {
  772. i5000_printk(KERN_ERR,
  773. "MC: 'BRANCH 1' device not found:"
  774. "vendor 0x%x device 0x%x Func 0 "
  775. "(broken BIOS?)\n",
  776. PCI_VENDOR_ID_INTEL,
  777. PCI_DEVICE_ID_I5000_BRANCH_1);
  778. pci_dev_put(pvt->branchmap_werrors);
  779. pci_dev_put(pvt->fsb_error_regs);
  780. pci_dev_put(pvt->branch_0);
  781. return 1;
  782. }
  783. pvt->branch_1 = pdev;
  784. }
  785. return 0;
  786. }
  787. /*
  788. * i5000_put_devices 'put' all the devices that we have
  789. * reserved via 'get'
  790. */
  791. static void i5000_put_devices(struct mem_ctl_info *mci)
  792. {
  793. struct i5000_pvt *pvt;
  794. pvt = mci->pvt_info;
  795. pci_dev_put(pvt->branchmap_werrors); /* FUNC 1 */
  796. pci_dev_put(pvt->fsb_error_regs); /* FUNC 2 */
  797. pci_dev_put(pvt->branch_0); /* DEV 21 */
  798. /* Only if more than 2 channels do we release the second branch */
  799. if (pvt->maxch >= CHANNELS_PER_BRANCH)
  800. pci_dev_put(pvt->branch_1); /* DEV 22 */
  801. }
  802. /*
  803. * determine_amb_resent
  804. *
  805. * the information is contained in NUM_MTRS different registers
  806. * determineing which of the NUM_MTRS requires knowing
  807. * which channel is in question
  808. *
  809. * 2 branches, each with 2 channels
  810. * b0_ambpresent0 for channel '0'
  811. * b0_ambpresent1 for channel '1'
  812. * b1_ambpresent0 for channel '2'
  813. * b1_ambpresent1 for channel '3'
  814. */
  815. static int determine_amb_present_reg(struct i5000_pvt *pvt, int channel)
  816. {
  817. int amb_present;
  818. if (channel < CHANNELS_PER_BRANCH) {
  819. if (channel & 0x1)
  820. amb_present = pvt->b0_ambpresent1;
  821. else
  822. amb_present = pvt->b0_ambpresent0;
  823. } else {
  824. if (channel & 0x1)
  825. amb_present = pvt->b1_ambpresent1;
  826. else
  827. amb_present = pvt->b1_ambpresent0;
  828. }
  829. return amb_present;
  830. }
  831. /*
  832. * determine_mtr(pvt, csrow, channel)
  833. *
  834. * return the proper MTR register as determine by the csrow and channel desired
  835. */
  836. static int determine_mtr(struct i5000_pvt *pvt, int slot, int channel)
  837. {
  838. int mtr;
  839. if (channel < CHANNELS_PER_BRANCH)
  840. mtr = pvt->b0_mtr[slot];
  841. else
  842. mtr = pvt->b1_mtr[slot];
  843. return mtr;
  844. }
  845. /*
  846. */
  847. static void decode_mtr(int slot_row, u16 mtr)
  848. {
  849. int ans;
  850. ans = MTR_DIMMS_PRESENT(mtr);
  851. debugf2("\tMTR%d=0x%x: DIMMs are %s\n", slot_row, mtr,
  852. ans ? "Present" : "NOT Present");
  853. if (!ans)
  854. return;
  855. debugf2("\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
  856. debugf2("\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
  857. debugf2("\t\tNUMRANK: %s\n", MTR_DIMM_RANK(mtr) ? "double" : "single");
  858. debugf2("\t\tNUMROW: %s\n", numrow_toString[MTR_DIMM_ROWS(mtr)]);
  859. debugf2("\t\tNUMCOL: %s\n", numcol_toString[MTR_DIMM_COLS(mtr)]);
  860. }
  861. static void handle_channel(struct i5000_pvt *pvt, int slot, int channel,
  862. struct i5000_dimm_info *dinfo)
  863. {
  864. int mtr;
  865. int amb_present_reg;
  866. int addrBits;
  867. mtr = determine_mtr(pvt, slot, channel);
  868. if (MTR_DIMMS_PRESENT(mtr)) {
  869. amb_present_reg = determine_amb_present_reg(pvt, channel);
  870. /* Determine if there is a DIMM present in this DIMM slot */
  871. if (amb_present_reg) {
  872. dinfo->dual_rank = MTR_DIMM_RANK(mtr);
  873. /* Start with the number of bits for a Bank
  874. * on the DRAM */
  875. addrBits = MTR_DRAM_BANKS_ADDR_BITS(mtr);
  876. /* Add the number of ROW bits */
  877. addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
  878. /* add the number of COLUMN bits */
  879. addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
  880. addrBits += 6; /* add 64 bits per DIMM */
  881. addrBits -= 20; /* divide by 2^^20 */
  882. addrBits -= 3; /* 8 bits per bytes */
  883. dinfo->megabytes = 1 << addrBits;
  884. }
  885. }
  886. }
  887. /*
  888. * calculate_dimm_size
  889. *
  890. * also will output a DIMM matrix map, if debug is enabled, for viewing
  891. * how the DIMMs are populated
  892. */
  893. static void calculate_dimm_size(struct i5000_pvt *pvt)
  894. {
  895. struct i5000_dimm_info *dinfo;
  896. int slot, channel, branch;
  897. char *p, *mem_buffer;
  898. int space, n;
  899. /* ================= Generate some debug output ================= */
  900. space = PAGE_SIZE;
  901. mem_buffer = p = kmalloc(space, GFP_KERNEL);
  902. if (p == NULL) {
  903. i5000_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
  904. __FILE__, __func__);
  905. return;
  906. }
  907. /* Scan all the actual slots
  908. * and calculate the information for each DIMM
  909. * Start with the highest slot first, to display it first
  910. * and work toward the 0th slot
  911. */
  912. for (slot = pvt->maxdimmperch - 1; slot >= 0; slot--) {
  913. /* on an odd slot, first output a 'boundary' marker,
  914. * then reset the message buffer */
  915. if (slot & 0x1) {
  916. n = snprintf(p, space, "--------------------------"
  917. "--------------------------------");
  918. p += n;
  919. space -= n;
  920. debugf2("%s\n", mem_buffer);
  921. p = mem_buffer;
  922. space = PAGE_SIZE;
  923. }
  924. n = snprintf(p, space, "slot %2d ", slot);
  925. p += n;
  926. space -= n;
  927. for (channel = 0; channel < pvt->maxch; channel++) {
  928. dinfo = &pvt->dimm_info[slot][channel];
  929. handle_channel(pvt, slot, channel, dinfo);
  930. if (dinfo->megabytes)
  931. n = snprintf(p, space, "%4d MB %dR| ",
  932. dinfo->megabytes, dinfo->dual_rank + 1);
  933. else
  934. n = snprintf(p, space, "%4d MB | ", 0);
  935. p += n;
  936. space -= n;
  937. }
  938. p += n;
  939. space -= n;
  940. debugf2("%s\n", mem_buffer);
  941. p = mem_buffer;
  942. space = PAGE_SIZE;
  943. }
  944. /* Output the last bottom 'boundary' marker */
  945. n = snprintf(p, space, "--------------------------"
  946. "--------------------------------");
  947. p += n;
  948. space -= n;
  949. debugf2("%s\n", mem_buffer);
  950. p = mem_buffer;
  951. space = PAGE_SIZE;
  952. /* now output the 'channel' labels */
  953. n = snprintf(p, space, " ");
  954. p += n;
  955. space -= n;
  956. for (channel = 0; channel < pvt->maxch; channel++) {
  957. n = snprintf(p, space, "channel %d | ", channel);
  958. p += n;
  959. space -= n;
  960. }
  961. debugf2("%s\n", mem_buffer);
  962. p = mem_buffer;
  963. space = PAGE_SIZE;
  964. n = snprintf(p, space, " ");
  965. p += n;
  966. for (branch = 0; branch < MAX_BRANCHES; branch++) {
  967. n = snprintf(p, space, " branch %d | ", branch);
  968. p += n;
  969. space -= n;
  970. }
  971. /* output the last message and free buffer */
  972. debugf2("%s\n", mem_buffer);
  973. kfree(mem_buffer);
  974. }
  975. /*
  976. * i5000_get_mc_regs read in the necessary registers and
  977. * cache locally
  978. *
  979. * Fills in the private data members
  980. */
  981. static void i5000_get_mc_regs(struct mem_ctl_info *mci)
  982. {
  983. struct i5000_pvt *pvt;
  984. u32 actual_tolm;
  985. u16 limit;
  986. int slot_row;
  987. int maxch;
  988. int maxdimmperch;
  989. int way0, way1;
  990. pvt = mci->pvt_info;
  991. pci_read_config_dword(pvt->system_address, AMBASE,
  992. (u32 *) & pvt->ambase);
  993. pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
  994. ((u32 *) & pvt->ambase) + sizeof(u32));
  995. maxdimmperch = pvt->maxdimmperch;
  996. maxch = pvt->maxch;
  997. debugf2("AMBASE= 0x%lx MAXCH= %d MAX-DIMM-Per-CH= %d\n",
  998. (long unsigned int)pvt->ambase, pvt->maxch, pvt->maxdimmperch);
  999. /* Get the Branch Map regs */
  1000. pci_read_config_word(pvt->branchmap_werrors, TOLM, &pvt->tolm);
  1001. pvt->tolm >>= 12;
  1002. debugf2("\nTOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
  1003. pvt->tolm);
  1004. actual_tolm = pvt->tolm << 28;
  1005. debugf2("Actual TOLM byte addr=%u (0x%x)\n", actual_tolm, actual_tolm);
  1006. pci_read_config_word(pvt->branchmap_werrors, MIR0, &pvt->mir0);
  1007. pci_read_config_word(pvt->branchmap_werrors, MIR1, &pvt->mir1);
  1008. pci_read_config_word(pvt->branchmap_werrors, MIR2, &pvt->mir2);
  1009. /* Get the MIR[0-2] regs */
  1010. limit = (pvt->mir0 >> 4) & 0x0FFF;
  1011. way0 = pvt->mir0 & 0x1;
  1012. way1 = pvt->mir0 & 0x2;
  1013. debugf2("MIR0: limit= 0x%x WAY1= %u WAY0= %x\n", limit, way1, way0);
  1014. limit = (pvt->mir1 >> 4) & 0x0FFF;
  1015. way0 = pvt->mir1 & 0x1;
  1016. way1 = pvt->mir1 & 0x2;
  1017. debugf2("MIR1: limit= 0x%x WAY1= %u WAY0= %x\n", limit, way1, way0);
  1018. limit = (pvt->mir2 >> 4) & 0x0FFF;
  1019. way0 = pvt->mir2 & 0x1;
  1020. way1 = pvt->mir2 & 0x2;
  1021. debugf2("MIR2: limit= 0x%x WAY1= %u WAY0= %x\n", limit, way1, way0);
  1022. /* Get the MTR[0-3] regs */
  1023. for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
  1024. int where = MTR0 + (slot_row * sizeof(u32));
  1025. pci_read_config_word(pvt->branch_0, where,
  1026. &pvt->b0_mtr[slot_row]);
  1027. debugf2("MTR%d where=0x%x B0 value=0x%x\n", slot_row, where,
  1028. pvt->b0_mtr[slot_row]);
  1029. if (pvt->maxch >= CHANNELS_PER_BRANCH) {
  1030. pci_read_config_word(pvt->branch_1, where,
  1031. &pvt->b1_mtr[slot_row]);
  1032. debugf2("MTR%d where=0x%x B1 value=0x%x\n", slot_row,
  1033. where, pvt->b1_mtr[slot_row]);
  1034. } else {
  1035. pvt->b1_mtr[slot_row] = 0;
  1036. }
  1037. }
  1038. /* Read and dump branch 0's MTRs */
  1039. debugf2("\nMemory Technology Registers:\n");
  1040. debugf2(" Branch 0:\n");
  1041. for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
  1042. decode_mtr(slot_row, pvt->b0_mtr[slot_row]);
  1043. }
  1044. pci_read_config_word(pvt->branch_0, AMB_PRESENT_0,
  1045. &pvt->b0_ambpresent0);
  1046. debugf2("\t\tAMB-Branch 0-present0 0x%x:\n", pvt->b0_ambpresent0);
  1047. pci_read_config_word(pvt->branch_0, AMB_PRESENT_1,
  1048. &pvt->b0_ambpresent1);
  1049. debugf2("\t\tAMB-Branch 0-present1 0x%x:\n", pvt->b0_ambpresent1);
  1050. /* Only if we have 2 branchs (4 channels) */
  1051. if (pvt->maxch < CHANNELS_PER_BRANCH) {
  1052. pvt->b1_ambpresent0 = 0;
  1053. pvt->b1_ambpresent1 = 0;
  1054. } else {
  1055. /* Read and dump branch 1's MTRs */
  1056. debugf2(" Branch 1:\n");
  1057. for (slot_row = 0; slot_row < NUM_MTRS; slot_row++) {
  1058. decode_mtr(slot_row, pvt->b1_mtr[slot_row]);
  1059. }
  1060. pci_read_config_word(pvt->branch_1, AMB_PRESENT_0,
  1061. &pvt->b1_ambpresent0);
  1062. debugf2("\t\tAMB-Branch 1-present0 0x%x:\n",
  1063. pvt->b1_ambpresent0);
  1064. pci_read_config_word(pvt->branch_1, AMB_PRESENT_1,
  1065. &pvt->b1_ambpresent1);
  1066. debugf2("\t\tAMB-Branch 1-present1 0x%x:\n",
  1067. pvt->b1_ambpresent1);
  1068. }
  1069. /* Go and determine the size of each DIMM and place in an
  1070. * orderly matrix */
  1071. calculate_dimm_size(pvt);
  1072. }
  1073. /*
  1074. * i5000_init_csrows Initialize the 'csrows' table within
  1075. * the mci control structure with the
  1076. * addressing of memory.
  1077. *
  1078. * return:
  1079. * 0 success
  1080. * 1 no actual memory found on this MC
  1081. */
  1082. static int i5000_init_csrows(struct mem_ctl_info *mci)
  1083. {
  1084. struct i5000_pvt *pvt;
  1085. struct dimm_info *dimm;
  1086. int empty, channel_count;
  1087. int max_csrows;
  1088. int mtr;
  1089. int csrow_megs;
  1090. int channel;
  1091. int slot;
  1092. pvt = mci->pvt_info;
  1093. channel_count = pvt->maxch;
  1094. max_csrows = pvt->maxdimmperch * 2;
  1095. empty = 1; /* Assume NO memory */
  1096. /*
  1097. * FIXME: The memory layout used to map slot/channel into the
  1098. * real memory architecture is weird: branch+slot are "csrows"
  1099. * and channel is channel. That required an extra array (dimm_info)
  1100. * to map the dimms. A good cleanup would be to remove this array,
  1101. * and do a loop here with branch, channel, slot
  1102. */
  1103. for (slot = 0; slot < max_csrows; slot++) {
  1104. for (channel = 0; channel < pvt->maxch; channel++) {
  1105. mtr = determine_mtr(pvt, slot, channel);
  1106. if (!MTR_DIMMS_PRESENT(mtr))
  1107. continue;
  1108. dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, mci->n_layers,
  1109. channel / MAX_BRANCHES,
  1110. channel % MAX_BRANCHES, slot);
  1111. csrow_megs = pvt->dimm_info[slot][channel].megabytes;
  1112. dimm->grain = 8;
  1113. /* Assume DDR2 for now */
  1114. dimm->mtype = MEM_FB_DDR2;
  1115. /* ask what device type on this row */
  1116. if (MTR_DRAM_WIDTH(mtr))
  1117. dimm->dtype = DEV_X8;
  1118. else
  1119. dimm->dtype = DEV_X4;
  1120. dimm->edac_mode = EDAC_S8ECD8ED;
  1121. dimm->nr_pages = csrow_megs << 8;
  1122. }
  1123. empty = 0;
  1124. }
  1125. return empty;
  1126. }
  1127. /*
  1128. * i5000_enable_error_reporting
  1129. * Turn on the memory reporting features of the hardware
  1130. */
  1131. static void i5000_enable_error_reporting(struct mem_ctl_info *mci)
  1132. {
  1133. struct i5000_pvt *pvt;
  1134. u32 fbd_error_mask;
  1135. pvt = mci->pvt_info;
  1136. /* Read the FBD Error Mask Register */
  1137. pci_read_config_dword(pvt->branchmap_werrors, EMASK_FBD,
  1138. &fbd_error_mask);
  1139. /* Enable with a '0' */
  1140. fbd_error_mask &= ~(ENABLE_EMASK_ALL);
  1141. pci_write_config_dword(pvt->branchmap_werrors, EMASK_FBD,
  1142. fbd_error_mask);
  1143. }
  1144. /*
  1145. * i5000_get_dimm_and_channel_counts(pdev, &nr_csrows, &num_channels)
  1146. *
  1147. * ask the device how many channels are present and how many CSROWS
  1148. * as well
  1149. */
  1150. static void i5000_get_dimm_and_channel_counts(struct pci_dev *pdev,
  1151. int *num_dimms_per_channel,
  1152. int *num_channels)
  1153. {
  1154. u8 value;
  1155. /* Need to retrieve just how many channels and dimms per channel are
  1156. * supported on this memory controller
  1157. */
  1158. pci_read_config_byte(pdev, MAXDIMMPERCH, &value);
  1159. *num_dimms_per_channel = (int)value;
  1160. pci_read_config_byte(pdev, MAXCH, &value);
  1161. *num_channels = (int)value;
  1162. }
  1163. /*
  1164. * i5000_probe1 Probe for ONE instance of device to see if it is
  1165. * present.
  1166. * return:
  1167. * 0 for FOUND a device
  1168. * < 0 for error code
  1169. */
  1170. static int i5000_probe1(struct pci_dev *pdev, int dev_idx)
  1171. {
  1172. struct mem_ctl_info *mci;
  1173. struct edac_mc_layer layers[3];
  1174. struct i5000_pvt *pvt;
  1175. int num_channels;
  1176. int num_dimms_per_channel;
  1177. debugf0("MC: %s: %s(), pdev bus %u dev=0x%x fn=0x%x\n",
  1178. __FILE__, __func__,
  1179. pdev->bus->number,
  1180. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  1181. /* We only are looking for func 0 of the set */
  1182. if (PCI_FUNC(pdev->devfn) != 0)
  1183. return -ENODEV;
  1184. /* Ask the devices for the number of CSROWS and CHANNELS so
  1185. * that we can calculate the memory resources, etc
  1186. *
  1187. * The Chipset will report what it can handle which will be greater
  1188. * or equal to what the motherboard manufacturer will implement.
  1189. *
  1190. * As we don't have a motherboard identification routine to determine
  1191. * actual number of slots/dimms per channel, we thus utilize the
  1192. * resource as specified by the chipset. Thus, we might have
  1193. * have more DIMMs per channel than actually on the mobo, but this
  1194. * allows the driver to support up to the chipset max, without
  1195. * some fancy mobo determination.
  1196. */
  1197. i5000_get_dimm_and_channel_counts(pdev, &num_dimms_per_channel,
  1198. &num_channels);
  1199. debugf0("MC: %s(): Number of Branches=2 Channels= %d DIMMS= %d\n",
  1200. __func__, num_channels, num_dimms_per_channel);
  1201. /* allocate a new MC control structure */
  1202. layers[0].type = EDAC_MC_LAYER_BRANCH;
  1203. layers[0].size = MAX_BRANCHES;
  1204. layers[0].is_virt_csrow = false;
  1205. layers[1].type = EDAC_MC_LAYER_CHANNEL;
  1206. layers[1].size = num_channels / MAX_BRANCHES;
  1207. layers[1].is_virt_csrow = false;
  1208. layers[2].type = EDAC_MC_LAYER_SLOT;
  1209. layers[2].size = num_dimms_per_channel;
  1210. layers[2].is_virt_csrow = true;
  1211. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
  1212. if (mci == NULL)
  1213. return -ENOMEM;
  1214. kobject_get(&mci->edac_mci_kobj);
  1215. debugf0("MC: %s: %s(): mci = %p\n", __FILE__, __func__, mci);
  1216. mci->dev = &pdev->dev; /* record ptr to the generic device */
  1217. pvt = mci->pvt_info;
  1218. pvt->system_address = pdev; /* Record this device in our private */
  1219. pvt->maxch = num_channels;
  1220. pvt->maxdimmperch = num_dimms_per_channel;
  1221. /* 'get' the pci devices we want to reserve for our use */
  1222. if (i5000_get_devices(mci, dev_idx))
  1223. goto fail0;
  1224. /* Time to get serious */
  1225. i5000_get_mc_regs(mci); /* retrieve the hardware registers */
  1226. mci->mc_idx = 0;
  1227. mci->mtype_cap = MEM_FLAG_FB_DDR2;
  1228. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  1229. mci->edac_cap = EDAC_FLAG_NONE;
  1230. mci->mod_name = "i5000_edac.c";
  1231. mci->mod_ver = I5000_REVISION;
  1232. mci->ctl_name = i5000_devs[dev_idx].ctl_name;
  1233. mci->dev_name = pci_name(pdev);
  1234. mci->ctl_page_to_phys = NULL;
  1235. /* Set the function pointer to an actual operation function */
  1236. mci->edac_check = i5000_check_error;
  1237. /* initialize the MC control structure 'csrows' table
  1238. * with the mapping and control information */
  1239. if (i5000_init_csrows(mci)) {
  1240. debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
  1241. " because i5000_init_csrows() returned nonzero "
  1242. "value\n");
  1243. mci->edac_cap = EDAC_FLAG_NONE; /* no csrows found */
  1244. } else {
  1245. debugf1("MC: Enable error reporting now\n");
  1246. i5000_enable_error_reporting(mci);
  1247. }
  1248. /* add this new MC control structure to EDAC's list of MCs */
  1249. if (edac_mc_add_mc(mci)) {
  1250. debugf0("MC: %s: %s(): failed edac_mc_add_mc()\n",
  1251. __FILE__, __func__);
  1252. /* FIXME: perhaps some code should go here that disables error
  1253. * reporting if we just enabled it
  1254. */
  1255. goto fail1;
  1256. }
  1257. i5000_clear_error(mci);
  1258. /* allocating generic PCI control info */
  1259. i5000_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  1260. if (!i5000_pci) {
  1261. printk(KERN_WARNING
  1262. "%s(): Unable to create PCI control\n",
  1263. __func__);
  1264. printk(KERN_WARNING
  1265. "%s(): PCI error report via EDAC not setup\n",
  1266. __func__);
  1267. }
  1268. return 0;
  1269. /* Error exit unwinding stack */
  1270. fail1:
  1271. i5000_put_devices(mci);
  1272. fail0:
  1273. kobject_put(&mci->edac_mci_kobj);
  1274. edac_mc_free(mci);
  1275. return -ENODEV;
  1276. }
  1277. /*
  1278. * i5000_init_one constructor for one instance of device
  1279. *
  1280. * returns:
  1281. * negative on error
  1282. * count (>= 0)
  1283. */
  1284. static int __devinit i5000_init_one(struct pci_dev *pdev,
  1285. const struct pci_device_id *id)
  1286. {
  1287. int rc;
  1288. debugf0("MC: %s: %s()\n", __FILE__, __func__);
  1289. /* wake up device */
  1290. rc = pci_enable_device(pdev);
  1291. if (rc)
  1292. return rc;
  1293. /* now probe and enable the device */
  1294. return i5000_probe1(pdev, id->driver_data);
  1295. }
  1296. /*
  1297. * i5000_remove_one destructor for one instance of device
  1298. *
  1299. */
  1300. static void __devexit i5000_remove_one(struct pci_dev *pdev)
  1301. {
  1302. struct mem_ctl_info *mci;
  1303. debugf0("%s: %s()\n", __FILE__, __func__);
  1304. if (i5000_pci)
  1305. edac_pci_release_generic_ctl(i5000_pci);
  1306. if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
  1307. return;
  1308. /* retrieve references to resources, and free those resources */
  1309. i5000_put_devices(mci);
  1310. kobject_put(&mci->edac_mci_kobj);
  1311. edac_mc_free(mci);
  1312. }
  1313. /*
  1314. * pci_device_id table for which devices we are looking for
  1315. *
  1316. * The "E500P" device is the first device supported.
  1317. */
  1318. static DEFINE_PCI_DEVICE_TABLE(i5000_pci_tbl) = {
  1319. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
  1320. .driver_data = I5000P},
  1321. {0,} /* 0 terminated list. */
  1322. };
  1323. MODULE_DEVICE_TABLE(pci, i5000_pci_tbl);
  1324. /*
  1325. * i5000_driver pci_driver structure for this module
  1326. *
  1327. */
  1328. static struct pci_driver i5000_driver = {
  1329. .name = KBUILD_BASENAME,
  1330. .probe = i5000_init_one,
  1331. .remove = __devexit_p(i5000_remove_one),
  1332. .id_table = i5000_pci_tbl,
  1333. };
  1334. /*
  1335. * i5000_init Module entry function
  1336. * Try to initialize this module for its devices
  1337. */
  1338. static int __init i5000_init(void)
  1339. {
  1340. int pci_rc;
  1341. debugf2("MC: %s: %s()\n", __FILE__, __func__);
  1342. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1343. opstate_init();
  1344. pci_rc = pci_register_driver(&i5000_driver);
  1345. return (pci_rc < 0) ? pci_rc : 0;
  1346. }
  1347. /*
  1348. * i5000_exit() Module exit function
  1349. * Unregister the driver
  1350. */
  1351. static void __exit i5000_exit(void)
  1352. {
  1353. debugf2("MC: %s: %s()\n", __FILE__, __func__);
  1354. pci_unregister_driver(&i5000_driver);
  1355. }
  1356. module_init(i5000_init);
  1357. module_exit(i5000_exit);
  1358. MODULE_LICENSE("GPL");
  1359. MODULE_AUTHOR
  1360. ("Linux Networx (http://lnxi.com) Doug Thompson <norsk5@xmission.com>");
  1361. MODULE_DESCRIPTION("MC Driver for Intel I5000 memory controllers - "
  1362. I5000_REVISION);
  1363. module_param(edac_op_state, int, 0444);
  1364. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
  1365. module_param(misc_messages, int, 0444);
  1366. MODULE_PARM_DESC(misc_messages, "Log miscellaneous non fatal messages");