i5000_edac.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499
  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. 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 information 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. static struct edac_pci_ctl_info *i5000_pci;
  336. /*
  337. * i5000_get_error_info Retrieve the hardware error information from
  338. * the hardware and cache it in the 'info'
  339. * structure
  340. */
  341. static void i5000_get_error_info(struct mem_ctl_info *mci,
  342. struct i5000_error_info *info)
  343. {
  344. struct i5000_pvt *pvt;
  345. u32 value;
  346. pvt = mci->pvt_info;
  347. /* read in the 1st FATAL error register */
  348. pci_read_config_dword(pvt->branchmap_werrors, FERR_FAT_FBD, &value);
  349. /* Mask only the bits that the doc says are valid
  350. */
  351. value &= (FERR_FAT_FBDCHAN | FERR_FAT_MASK);
  352. /* If there is an error, then read in the */
  353. /* NEXT FATAL error register and the Memory Error Log Register A */
  354. if (value & FERR_FAT_MASK) {
  355. info->ferr_fat_fbd = value;
  356. /* harvest the various error data we need */
  357. pci_read_config_dword(pvt->branchmap_werrors,
  358. NERR_FAT_FBD, &info->nerr_fat_fbd);
  359. pci_read_config_word(pvt->branchmap_werrors,
  360. NRECMEMA, &info->nrecmema);
  361. pci_read_config_word(pvt->branchmap_werrors,
  362. NRECMEMB, &info->nrecmemb);
  363. /* Clear the error bits, by writing them back */
  364. pci_write_config_dword(pvt->branchmap_werrors,
  365. FERR_FAT_FBD, value);
  366. } else {
  367. info->ferr_fat_fbd = 0;
  368. info->nerr_fat_fbd = 0;
  369. info->nrecmema = 0;
  370. info->nrecmemb = 0;
  371. }
  372. /* read in the 1st NON-FATAL error register */
  373. pci_read_config_dword(pvt->branchmap_werrors, FERR_NF_FBD, &value);
  374. /* If there is an error, then read in the 1st NON-FATAL error
  375. * register as well */
  376. if (value & FERR_NF_MASK) {
  377. info->ferr_nf_fbd = value;
  378. /* harvest the various error data we need */
  379. pci_read_config_dword(pvt->branchmap_werrors,
  380. NERR_NF_FBD, &info->nerr_nf_fbd);
  381. pci_read_config_word(pvt->branchmap_werrors,
  382. RECMEMA, &info->recmema);
  383. pci_read_config_dword(pvt->branchmap_werrors,
  384. RECMEMB, &info->recmemb);
  385. pci_read_config_dword(pvt->branchmap_werrors,
  386. REDMEMB, &info->redmemb);
  387. /* Clear the error bits, by writing them back */
  388. pci_write_config_dword(pvt->branchmap_werrors,
  389. FERR_NF_FBD, value);
  390. } else {
  391. info->ferr_nf_fbd = 0;
  392. info->nerr_nf_fbd = 0;
  393. info->recmema = 0;
  394. info->recmemb = 0;
  395. info->redmemb = 0;
  396. }
  397. }
  398. /*
  399. * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
  400. * struct i5000_error_info *info,
  401. * int handle_errors);
  402. *
  403. * handle the Intel FATAL errors, if any
  404. */
  405. static void i5000_process_fatal_error_info(struct mem_ctl_info *mci,
  406. struct i5000_error_info *info,
  407. int handle_errors)
  408. {
  409. char msg[EDAC_MC_LABEL_LEN + 1 + 90];
  410. u32 allErrors;
  411. int branch;
  412. int channel;
  413. int bank;
  414. int rank;
  415. int rdwr;
  416. int ras, cas;
  417. /* mask off the Error bits that are possible */
  418. allErrors = (info->ferr_fat_fbd & FERR_FAT_MASK);
  419. if (!allErrors)
  420. return; /* if no error, return now */
  421. /* ONLY ONE of the possible error bits will be set, as per the docs */
  422. i5000_mc_printk(mci, KERN_ERR,
  423. "FATAL ERRORS Found!!! 1st FATAL Err Reg= 0x%x\n",
  424. allErrors);
  425. branch = EXTRACT_FBDCHAN_INDX(info->ferr_fat_fbd);
  426. channel = branch;
  427. /* Use the NON-Recoverable macros to extract data */
  428. bank = NREC_BANK(info->nrecmema);
  429. rank = NREC_RANK(info->nrecmema);
  430. rdwr = NREC_RDWR(info->nrecmema);
  431. ras = NREC_RAS(info->nrecmemb);
  432. cas = NREC_CAS(info->nrecmemb);
  433. debugf0("\t\tCSROW= %d Channels= %d,%d (Branch= %d "
  434. "DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  435. rank, channel, channel + 1, branch >> 1, bank,
  436. rdwr ? "Write" : "Read", ras, cas);
  437. /* Only 1 bit will be on */
  438. if (allErrors & FERR_FAT_M1ERR) {
  439. i5000_mc_printk(mci, KERN_ERR,
  440. "Alert on non-redundant retry or fast "
  441. "reset timeout\n");
  442. } else if (allErrors & FERR_FAT_M2ERR) {
  443. i5000_mc_printk(mci, KERN_ERR,
  444. "Northbound CRC error on non-redundant "
  445. "retry\n");
  446. } else if (allErrors & FERR_FAT_M3ERR) {
  447. i5000_mc_printk(mci, KERN_ERR,
  448. ">Tmid Thermal event with intelligent "
  449. "throttling disabled\n");
  450. }
  451. /* Form out message */
  452. snprintf(msg, sizeof(msg),
  453. "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d CAS=%d "
  454. "FATAL Err=0x%x)",
  455. branch >> 1, bank, rdwr ? "Write" : "Read", ras, cas,
  456. allErrors);
  457. /* Call the helper to output message */
  458. edac_mc_handle_fbd_ue(mci, rank, channel, channel + 1, msg);
  459. }
  460. /*
  461. * i5000_process_fatal_error_info(struct mem_ctl_info *mci,
  462. * struct i5000_error_info *info,
  463. * int handle_errors);
  464. *
  465. * handle the Intel NON-FATAL errors, if any
  466. */
  467. static void i5000_process_nonfatal_error_info(struct mem_ctl_info *mci,
  468. struct i5000_error_info *info,
  469. int handle_errors)
  470. {
  471. char msg[EDAC_MC_LABEL_LEN + 1 + 90];
  472. u32 allErrors;
  473. u32 ue_errors;
  474. u32 ce_errors;
  475. u32 misc_errors;
  476. int branch;
  477. int channel;
  478. int bank;
  479. int rank;
  480. int rdwr;
  481. int ras, cas;
  482. /* mask off the Error bits that are possible */
  483. allErrors = (info->ferr_nf_fbd & FERR_NF_MASK);
  484. if (!allErrors)
  485. return; /* if no error, return now */
  486. /* ONLY ONE of the possible error bits will be set, as per the docs */
  487. i5000_mc_printk(mci, KERN_WARNING,
  488. "NON-FATAL ERRORS Found!!! 1st NON-FATAL Err "
  489. "Reg= 0x%x\n", allErrors);
  490. ue_errors = allErrors & FERR_NF_UNCORRECTABLE;
  491. if (ue_errors) {
  492. debugf0("\tUncorrected bits= 0x%x\n", ue_errors);
  493. branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
  494. channel = branch;
  495. bank = NREC_BANK(info->nrecmema);
  496. rank = NREC_RANK(info->nrecmema);
  497. rdwr = NREC_RDWR(info->nrecmema);
  498. ras = NREC_RAS(info->nrecmemb);
  499. cas = NREC_CAS(info->nrecmemb);
  500. debugf0
  501. ("\t\tCSROW= %d Channels= %d,%d (Branch= %d "
  502. "DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  503. rank, channel, channel + 1, branch >> 1, bank,
  504. rdwr ? "Write" : "Read", ras, cas);
  505. /* Form out message */
  506. snprintf(msg, sizeof(msg),
  507. "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d "
  508. "CAS=%d, UE Err=0x%x)",
  509. branch >> 1, bank, rdwr ? "Write" : "Read", ras, cas,
  510. ue_errors);
  511. /* Call the helper to output message */
  512. edac_mc_handle_fbd_ue(mci, rank, channel, channel + 1, msg);
  513. }
  514. /* Check correctable errors */
  515. ce_errors = allErrors & FERR_NF_CORRECTABLE;
  516. if (ce_errors) {
  517. debugf0("\tCorrected bits= 0x%x\n", ce_errors);
  518. branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
  519. channel = 0;
  520. if (REC_ECC_LOCATOR_ODD(info->redmemb))
  521. channel = 1;
  522. /* Convert channel to be based from zero, instead of
  523. * from branch base of 0 */
  524. channel += branch;
  525. bank = REC_BANK(info->recmema);
  526. rank = REC_RANK(info->recmema);
  527. rdwr = REC_RDWR(info->recmema);
  528. ras = REC_RAS(info->recmemb);
  529. cas = REC_CAS(info->recmemb);
  530. debugf0("\t\tCSROW= %d Channel= %d (Branch %d "
  531. "DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  532. rank, channel, branch >> 1, bank,
  533. rdwr ? "Write" : "Read", ras, cas);
  534. /* Form out message */
  535. snprintf(msg, sizeof(msg),
  536. "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d "
  537. "CAS=%d, CE Err=0x%x)", branch >> 1, bank,
  538. rdwr ? "Write" : "Read", ras, cas, ce_errors);
  539. /* Call the helper to output message */
  540. edac_mc_handle_fbd_ce(mci, rank, channel, msg);
  541. }
  542. /* See if any of the thermal errors have fired */
  543. misc_errors = allErrors & FERR_NF_THERMAL;
  544. if (misc_errors) {
  545. i5000_printk(KERN_WARNING, "\tTHERMAL Error, bits= 0x%x\n",
  546. misc_errors);
  547. }
  548. /* See if any of the thermal errors have fired */
  549. misc_errors = allErrors & FERR_NF_NON_RETRY;
  550. if (misc_errors) {
  551. i5000_printk(KERN_WARNING, "\tNON-Retry Errors, bits= 0x%x\n",
  552. misc_errors);
  553. }
  554. /* See if any of the thermal errors have fired */
  555. misc_errors = allErrors & FERR_NF_NORTH_CRC;
  556. if (misc_errors) {
  557. i5000_printk(KERN_WARNING,
  558. "\tNORTHBOUND CRC Error, bits= 0x%x\n",
  559. misc_errors);
  560. }
  561. /* See if any of the thermal errors have fired */
  562. misc_errors = allErrors & FERR_NF_SPD_PROTOCOL;
  563. if (misc_errors) {
  564. i5000_printk(KERN_WARNING,
  565. "\tSPD Protocol Error, bits= 0x%x\n",
  566. misc_errors);
  567. }
  568. /* See if any of the thermal errors have fired */
  569. misc_errors = allErrors & FERR_NF_DIMM_SPARE;
  570. if (misc_errors) {
  571. i5000_printk(KERN_WARNING, "\tDIMM-Spare Error, bits= 0x%x\n",
  572. misc_errors);
  573. }
  574. }
  575. /*
  576. * i5000_process_error_info Process the error info that is
  577. * in the 'info' structure, previously retrieved from hardware
  578. */
  579. static void i5000_process_error_info(struct mem_ctl_info *mci,
  580. struct i5000_error_info *info,
  581. int handle_errors)
  582. {
  583. /* First handle any fatal errors that occurred */
  584. i5000_process_fatal_error_info(mci, info, handle_errors);
  585. /* now handle any non-fatal errors that occurred */
  586. i5000_process_nonfatal_error_info(mci, info, handle_errors);
  587. }
  588. /*
  589. * i5000_clear_error Retrieve any error from the hardware
  590. * but do NOT process that error.
  591. * Used for 'clearing' out of previous errors
  592. * Called by the Core module.
  593. */
  594. static void i5000_clear_error(struct mem_ctl_info *mci)
  595. {
  596. struct i5000_error_info info;
  597. i5000_get_error_info(mci, &info);
  598. }
  599. /*
  600. * i5000_check_error Retrieve and process errors reported by the
  601. * hardware. Called by the Core module.
  602. */
  603. static void i5000_check_error(struct mem_ctl_info *mci)
  604. {
  605. struct i5000_error_info info;
  606. debugf4("MC%d: " __FILE__ ": %s()\n", mci->mc_idx, __func__);
  607. i5000_get_error_info(mci, &info);
  608. i5000_process_error_info(mci, &info, 1);
  609. }
  610. /*
  611. * i5000_get_devices Find and perform 'get' operation on the MCH's
  612. * device/functions we want to reference for this driver
  613. *
  614. * Need to 'get' device 16 func 1 and func 2
  615. */
  616. static int i5000_get_devices(struct mem_ctl_info *mci, int dev_idx)
  617. {
  618. //const struct i5000_dev_info *i5000_dev = &i5000_devs[dev_idx];
  619. struct i5000_pvt *pvt;
  620. struct pci_dev *pdev;
  621. pvt = mci->pvt_info;
  622. /* Attempt to 'get' the MCH register we want */
  623. pdev = NULL;
  624. while (1) {
  625. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  626. PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
  627. /* End of list, leave */
  628. if (pdev == NULL) {
  629. i5000_printk(KERN_ERR,
  630. "'system address,Process Bus' "
  631. "device not found:"
  632. "vendor 0x%x device 0x%x FUNC 1 "
  633. "(broken BIOS?)\n",
  634. PCI_VENDOR_ID_INTEL,
  635. PCI_DEVICE_ID_INTEL_I5000_DEV16);
  636. return 1;
  637. }
  638. /* Scan for device 16 func 1 */
  639. if (PCI_FUNC(pdev->devfn) == 1)
  640. break;
  641. }
  642. pvt->branchmap_werrors = pdev;
  643. /* Attempt to 'get' the MCH register we want */
  644. pdev = NULL;
  645. while (1) {
  646. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  647. PCI_DEVICE_ID_INTEL_I5000_DEV16, pdev);
  648. if (pdev == NULL) {
  649. i5000_printk(KERN_ERR,
  650. "MC: 'branchmap,control,errors' "
  651. "device not found:"
  652. "vendor 0x%x device 0x%x Func 2 "
  653. "(broken BIOS?)\n",
  654. PCI_VENDOR_ID_INTEL,
  655. PCI_DEVICE_ID_INTEL_I5000_DEV16);
  656. pci_dev_put(pvt->branchmap_werrors);
  657. return 1;
  658. }
  659. /* Scan for device 16 func 1 */
  660. if (PCI_FUNC(pdev->devfn) == 2)
  661. break;
  662. }
  663. pvt->fsb_error_regs = pdev;
  664. debugf1("System Address, processor bus- PCI Bus ID: %s %x:%x\n",
  665. pci_name(pvt->system_address),
  666. pvt->system_address->vendor, pvt->system_address->device);
  667. debugf1("Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
  668. pci_name(pvt->branchmap_werrors),
  669. pvt->branchmap_werrors->vendor, pvt->branchmap_werrors->device);
  670. debugf1("FSB Error Regs - PCI Bus ID: %s %x:%x\n",
  671. pci_name(pvt->fsb_error_regs),
  672. pvt->fsb_error_regs->vendor, pvt->fsb_error_regs->device);
  673. pdev = NULL;
  674. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  675. PCI_DEVICE_ID_I5000_BRANCH_0, pdev);
  676. if (pdev == NULL) {
  677. i5000_printk(KERN_ERR,
  678. "MC: 'BRANCH 0' device not found:"
  679. "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
  680. PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_I5000_BRANCH_0);
  681. pci_dev_put(pvt->branchmap_werrors);
  682. pci_dev_put(pvt->fsb_error_regs);
  683. return 1;
  684. }
  685. pvt->branch_0 = pdev;
  686. /* If this device claims to have more than 2 channels then
  687. * fetch Branch 1's information
  688. */
  689. if (pvt->maxch >= CHANNELS_PER_BRANCH) {
  690. pdev = NULL;
  691. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  692. PCI_DEVICE_ID_I5000_BRANCH_1, pdev);
  693. if (pdev == NULL) {
  694. i5000_printk(KERN_ERR,
  695. "MC: 'BRANCH 1' device not found:"
  696. "vendor 0x%x device 0x%x Func 0 "
  697. "(broken BIOS?)\n",
  698. PCI_VENDOR_ID_INTEL,
  699. PCI_DEVICE_ID_I5000_BRANCH_1);
  700. pci_dev_put(pvt->branchmap_werrors);
  701. pci_dev_put(pvt->fsb_error_regs);
  702. pci_dev_put(pvt->branch_0);
  703. return 1;
  704. }
  705. pvt->branch_1 = pdev;
  706. }
  707. return 0;
  708. }
  709. /*
  710. * i5000_put_devices 'put' all the devices that we have
  711. * reserved via 'get'
  712. */
  713. static void i5000_put_devices(struct mem_ctl_info *mci)
  714. {
  715. struct i5000_pvt *pvt;
  716. pvt = mci->pvt_info;
  717. pci_dev_put(pvt->branchmap_werrors); /* FUNC 1 */
  718. pci_dev_put(pvt->fsb_error_regs); /* FUNC 2 */
  719. pci_dev_put(pvt->branch_0); /* DEV 21 */
  720. /* Only if more than 2 channels do we release the second branch */
  721. if (pvt->maxch >= CHANNELS_PER_BRANCH)
  722. pci_dev_put(pvt->branch_1); /* DEV 22 */
  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 = 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 = 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 = 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. /* Ask the devices for the number of CSROWS and CHANNELS so
  1098. * that we can calculate the memory resources, etc
  1099. *
  1100. * The Chipset will report what it can handle which will be greater
  1101. * or equal to what the motherboard manufacturer will implement.
  1102. *
  1103. * As we don't have a motherboard identification routine to determine
  1104. * actual number of slots/dimms per channel, we thus utilize the
  1105. * resource as specified by the chipset. Thus, we might have
  1106. * have more DIMMs per channel than actually on the mobo, but this
  1107. * allows the driver to support upto the chipset max, without
  1108. * some fancy mobo determination.
  1109. */
  1110. i5000_get_dimm_and_channel_counts(pdev, &num_dimms_per_channel,
  1111. &num_channels);
  1112. num_csrows = num_dimms_per_channel * 2;
  1113. debugf0("MC: %s(): Number of - Channels= %d DIMMS= %d CSROWS= %d\n",
  1114. __func__, num_channels, num_dimms_per_channel, num_csrows);
  1115. /* allocate a new MC control structure */
  1116. mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0);
  1117. if (mci == NULL)
  1118. return -ENOMEM;
  1119. debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
  1120. mci->dev = &pdev->dev; /* record ptr to the generic device */
  1121. pvt = mci->pvt_info;
  1122. pvt->system_address = pdev; /* Record this device in our private */
  1123. pvt->maxch = num_channels;
  1124. pvt->maxdimmperch = num_dimms_per_channel;
  1125. /* 'get' the pci devices we want to reserve for our use */
  1126. if (i5000_get_devices(mci, dev_idx))
  1127. goto fail0;
  1128. /* Time to get serious */
  1129. i5000_get_mc_regs(mci); /* retrieve the hardware registers */
  1130. mci->mc_idx = 0;
  1131. mci->mtype_cap = MEM_FLAG_FB_DDR2;
  1132. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  1133. mci->edac_cap = EDAC_FLAG_NONE;
  1134. mci->mod_name = "i5000_edac.c";
  1135. mci->mod_ver = I5000_REVISION;
  1136. mci->ctl_name = i5000_devs[dev_idx].ctl_name;
  1137. mci->dev_name = pci_name(pdev);
  1138. mci->ctl_page_to_phys = NULL;
  1139. /* Set the function pointer to an actual operation function */
  1140. mci->edac_check = i5000_check_error;
  1141. /* initialize the MC control structure 'csrows' table
  1142. * with the mapping and control information */
  1143. if (i5000_init_csrows(mci)) {
  1144. debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
  1145. " because i5000_init_csrows() returned nonzero "
  1146. "value\n");
  1147. mci->edac_cap = EDAC_FLAG_NONE; /* no csrows found */
  1148. } else {
  1149. debugf1("MC: Enable error reporting now\n");
  1150. i5000_enable_error_reporting(mci);
  1151. }
  1152. /* add this new MC control structure to EDAC's list of MCs */
  1153. if (edac_mc_add_mc(mci)) {
  1154. debugf0("MC: " __FILE__
  1155. ": %s(): failed edac_mc_add_mc()\n", __func__);
  1156. /* FIXME: perhaps some code should go here that disables error
  1157. * reporting if we just enabled it
  1158. */
  1159. goto fail1;
  1160. }
  1161. i5000_clear_error(mci);
  1162. /* allocating generic PCI control info */
  1163. i5000_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  1164. if (!i5000_pci) {
  1165. printk(KERN_WARNING
  1166. "%s(): Unable to create PCI control\n",
  1167. __func__);
  1168. printk(KERN_WARNING
  1169. "%s(): PCI error report via EDAC not setup\n",
  1170. __func__);
  1171. }
  1172. return 0;
  1173. /* Error exit unwinding stack */
  1174. fail1:
  1175. i5000_put_devices(mci);
  1176. fail0:
  1177. edac_mc_free(mci);
  1178. return -ENODEV;
  1179. }
  1180. /*
  1181. * i5000_init_one constructor for one instance of device
  1182. *
  1183. * returns:
  1184. * negative on error
  1185. * count (>= 0)
  1186. */
  1187. static int __devinit i5000_init_one(struct pci_dev *pdev,
  1188. const struct pci_device_id *id)
  1189. {
  1190. int rc;
  1191. debugf0("MC: " __FILE__ ": %s()\n", __func__);
  1192. /* wake up device */
  1193. rc = pci_enable_device(pdev);
  1194. if (rc == -EIO)
  1195. return rc;
  1196. /* now probe and enable the device */
  1197. return i5000_probe1(pdev, id->driver_data);
  1198. }
  1199. /*
  1200. * i5000_remove_one destructor for one instance of device
  1201. *
  1202. */
  1203. static void __devexit i5000_remove_one(struct pci_dev *pdev)
  1204. {
  1205. struct mem_ctl_info *mci;
  1206. debugf0(__FILE__ ": %s()\n", __func__);
  1207. if (i5000_pci)
  1208. edac_pci_release_generic_ctl(i5000_pci);
  1209. if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
  1210. return;
  1211. /* retrieve references to resources, and free those resources */
  1212. i5000_put_devices(mci);
  1213. edac_mc_free(mci);
  1214. }
  1215. /*
  1216. * pci_device_id table for which devices we are looking for
  1217. *
  1218. * The "E500P" device is the first device supported.
  1219. */
  1220. static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
  1221. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
  1222. .driver_data = I5000P},
  1223. {0,} /* 0 terminated list. */
  1224. };
  1225. MODULE_DEVICE_TABLE(pci, i5000_pci_tbl);
  1226. /*
  1227. * i5000_driver pci_driver structure for this module
  1228. *
  1229. */
  1230. static struct pci_driver i5000_driver = {
  1231. .name = KBUILD_BASENAME,
  1232. .probe = i5000_init_one,
  1233. .remove = __devexit_p(i5000_remove_one),
  1234. .id_table = i5000_pci_tbl,
  1235. };
  1236. /*
  1237. * i5000_init Module entry function
  1238. * Try to initialize this module for its devices
  1239. */
  1240. static int __init i5000_init(void)
  1241. {
  1242. int pci_rc;
  1243. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  1244. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1245. opstate_init();
  1246. pci_rc = pci_register_driver(&i5000_driver);
  1247. return (pci_rc < 0) ? pci_rc : 0;
  1248. }
  1249. /*
  1250. * i5000_exit() Module exit function
  1251. * Unregister the driver
  1252. */
  1253. static void __exit i5000_exit(void)
  1254. {
  1255. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  1256. pci_unregister_driver(&i5000_driver);
  1257. }
  1258. module_init(i5000_init);
  1259. module_exit(i5000_exit);
  1260. MODULE_LICENSE("GPL");
  1261. MODULE_AUTHOR
  1262. ("Linux Networx (http://lnxi.com) Doug Thompson <norsk5@xmission.com>");
  1263. MODULE_DESCRIPTION("MC Driver for Intel I5000 memory controllers - "
  1264. I5000_REVISION);
  1265. module_param(edac_op_state, int, 0444);
  1266. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");