i5000_edac.c 42 KB

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