i5000_edac.c 42 KB

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