i5400_edac.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484
  1. /*
  2. * Intel 5400 class Memory Controllers kernel module (Seaburg)
  3. *
  4. * This file may be distributed under the terms of the
  5. * GNU General Public License.
  6. *
  7. * Copyright (c) 2008 by:
  8. * Ben Woodard <woodard@redhat.com>
  9. * Mauro Carvalho Chehab <mchehab@redhat.com>
  10. *
  11. * Red Hat Inc. http://www.redhat.com
  12. *
  13. * Forked and adapted from the i5000_edac driver which was
  14. * written by Douglas Thompson Linux Networx <norsk5@xmission.com>
  15. *
  16. * This module is based on the following document:
  17. *
  18. * Intel 5400 Chipset Memory Controller Hub (MCH) - Datasheet
  19. * http://developer.intel.com/design/chipsets/datashts/313070.htm
  20. *
  21. * This Memory Controller manages DDR2 FB-DIMMs. It has 2 branches, each with
  22. * 2 channels operating in lockstep no-mirror mode. Each channel can have up to
  23. * 4 dimm's, each with up to 8GB.
  24. *
  25. */
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/pci.h>
  29. #include <linux/pci_ids.h>
  30. #include <linux/slab.h>
  31. #include <linux/edac.h>
  32. #include <linux/mmzone.h>
  33. #include "edac_core.h"
  34. /*
  35. * Alter this version for the I5400 module when modifications are made
  36. */
  37. #define I5400_REVISION " Ver: 1.0.0"
  38. #define EDAC_MOD_STR "i5400_edac"
  39. #define i5400_printk(level, fmt, arg...) \
  40. edac_printk(level, "i5400", fmt, ##arg)
  41. #define i5400_mc_printk(mci, level, fmt, arg...) \
  42. edac_mc_chipset_printk(mci, level, "i5400", fmt, ##arg)
  43. /* Limits for i5400 */
  44. #define MAX_BRANCHES 2
  45. #define CHANNELS_PER_BRANCH 2
  46. #define DIMMS_PER_CHANNEL 4
  47. #define MAX_CHANNELS (MAX_BRANCHES * CHANNELS_PER_BRANCH)
  48. /* Device 16,
  49. * Function 0: System Address
  50. * Function 1: Memory Branch Map, Control, Errors Register
  51. * Function 2: FSB Error Registers
  52. *
  53. * All 3 functions of Device 16 (0,1,2) share the SAME DID and
  54. * uses PCI_DEVICE_ID_INTEL_5400_ERR for device 16 (0,1,2),
  55. * PCI_DEVICE_ID_INTEL_5400_FBD0 and PCI_DEVICE_ID_INTEL_5400_FBD1
  56. * for device 21 (0,1).
  57. */
  58. /* OFFSETS for Function 0 */
  59. #define AMBASE 0x48 /* AMB Mem Mapped Reg Region Base */
  60. #define MAXCH 0x56 /* Max Channel Number */
  61. #define MAXDIMMPERCH 0x57 /* Max DIMM PER Channel Number */
  62. /* OFFSETS for Function 1 */
  63. #define TOLM 0x6C
  64. #define REDMEMB 0x7C
  65. #define REC_ECC_LOCATOR_ODD(x) ((x) & 0x3fe00) /* bits [17:9] indicate ODD, [8:0] indicate EVEN */
  66. #define MIR0 0x80
  67. #define MIR1 0x84
  68. #define AMIR0 0x8c
  69. #define AMIR1 0x90
  70. /* Fatal error registers */
  71. #define FERR_FAT_FBD 0x98 /* also called as FERR_FAT_FB_DIMM at datasheet */
  72. #define FERR_FAT_FBDCHAN (3<<28) /* channel index where the highest-order error occurred */
  73. #define NERR_FAT_FBD 0x9c
  74. #define FERR_NF_FBD 0xa0 /* also called as FERR_NFAT_FB_DIMM at datasheet */
  75. /* Non-fatal error register */
  76. #define NERR_NF_FBD 0xa4
  77. /* Enable error mask */
  78. #define EMASK_FBD 0xa8
  79. #define ERR0_FBD 0xac
  80. #define ERR1_FBD 0xb0
  81. #define ERR2_FBD 0xb4
  82. #define MCERR_FBD 0xb8
  83. /* No OFFSETS for Device 16 Function 2 */
  84. /*
  85. * Device 21,
  86. * Function 0: Memory Map Branch 0
  87. *
  88. * Device 22,
  89. * Function 0: Memory Map Branch 1
  90. */
  91. /* OFFSETS for Function 0 */
  92. #define AMBPRESENT_0 0x64
  93. #define AMBPRESENT_1 0x66
  94. #define MTR0 0x80
  95. #define MTR1 0x82
  96. #define MTR2 0x84
  97. #define MTR3 0x86
  98. /* OFFSETS for Function 1 */
  99. #define NRECFGLOG 0x74
  100. #define RECFGLOG 0x78
  101. #define NRECMEMA 0xbe
  102. #define NRECMEMB 0xc0
  103. #define NRECFB_DIMMA 0xc4
  104. #define NRECFB_DIMMB 0xc8
  105. #define NRECFB_DIMMC 0xcc
  106. #define NRECFB_DIMMD 0xd0
  107. #define NRECFB_DIMME 0xd4
  108. #define NRECFB_DIMMF 0xd8
  109. #define REDMEMA 0xdC
  110. #define RECMEMA 0xf0
  111. #define RECMEMB 0xf4
  112. #define RECFB_DIMMA 0xf8
  113. #define RECFB_DIMMB 0xec
  114. #define RECFB_DIMMC 0xf0
  115. #define RECFB_DIMMD 0xf4
  116. #define RECFB_DIMME 0xf8
  117. #define RECFB_DIMMF 0xfC
  118. /*
  119. * Error indicator bits and masks
  120. * Error masks are according with Table 5-17 of i5400 datasheet
  121. */
  122. enum error_mask {
  123. EMASK_M1 = 1<<0, /* Memory Write error on non-redundant retry */
  124. EMASK_M2 = 1<<1, /* Memory or FB-DIMM configuration CRC read error */
  125. EMASK_M3 = 1<<2, /* Reserved */
  126. EMASK_M4 = 1<<3, /* Uncorrectable Data ECC on Replay */
  127. EMASK_M5 = 1<<4, /* Aliased Uncorrectable Non-Mirrored Demand Data ECC */
  128. EMASK_M6 = 1<<5, /* Unsupported on i5400 */
  129. EMASK_M7 = 1<<6, /* Aliased Uncorrectable Resilver- or Spare-Copy Data ECC */
  130. EMASK_M8 = 1<<7, /* Aliased Uncorrectable Patrol Data ECC */
  131. EMASK_M9 = 1<<8, /* Non-Aliased Uncorrectable Non-Mirrored Demand Data ECC */
  132. EMASK_M10 = 1<<9, /* Unsupported on i5400 */
  133. EMASK_M11 = 1<<10, /* Non-Aliased Uncorrectable Resilver- or Spare-Copy Data ECC */
  134. EMASK_M12 = 1<<11, /* Non-Aliased Uncorrectable Patrol Data ECC */
  135. EMASK_M13 = 1<<12, /* Memory Write error on first attempt */
  136. EMASK_M14 = 1<<13, /* FB-DIMM Configuration Write error on first attempt */
  137. EMASK_M15 = 1<<14, /* Memory or FB-DIMM configuration CRC read error */
  138. EMASK_M16 = 1<<15, /* Channel Failed-Over Occurred */
  139. EMASK_M17 = 1<<16, /* Correctable Non-Mirrored Demand Data ECC */
  140. EMASK_M18 = 1<<17, /* Unsupported on i5400 */
  141. EMASK_M19 = 1<<18, /* Correctable Resilver- or Spare-Copy Data ECC */
  142. EMASK_M20 = 1<<19, /* Correctable Patrol Data ECC */
  143. EMASK_M21 = 1<<20, /* FB-DIMM Northbound parity error on FB-DIMM Sync Status */
  144. EMASK_M22 = 1<<21, /* SPD protocol Error */
  145. EMASK_M23 = 1<<22, /* Non-Redundant Fast Reset Timeout */
  146. EMASK_M24 = 1<<23, /* Refresh error */
  147. EMASK_M25 = 1<<24, /* Memory Write error on redundant retry */
  148. EMASK_M26 = 1<<25, /* Redundant Fast Reset Timeout */
  149. EMASK_M27 = 1<<26, /* Correctable Counter Threshold Exceeded */
  150. EMASK_M28 = 1<<27, /* DIMM-Spare Copy Completed */
  151. EMASK_M29 = 1<<28, /* DIMM-Isolation Completed */
  152. };
  153. /*
  154. * Names to translate bit error into something useful
  155. */
  156. static const char *error_name[] = {
  157. [0] = "Memory Write error on non-redundant retry",
  158. [1] = "Memory or FB-DIMM configuration CRC read error",
  159. /* Reserved */
  160. [3] = "Uncorrectable Data ECC on Replay",
  161. [4] = "Aliased Uncorrectable Non-Mirrored Demand Data ECC",
  162. /* M6 Unsupported on i5400 */
  163. [6] = "Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
  164. [7] = "Aliased Uncorrectable Patrol Data ECC",
  165. [8] = "Non-Aliased Uncorrectable Non-Mirrored Demand Data ECC",
  166. /* M10 Unsupported on i5400 */
  167. [10] = "Non-Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
  168. [11] = "Non-Aliased Uncorrectable Patrol Data ECC",
  169. [12] = "Memory Write error on first attempt",
  170. [13] = "FB-DIMM Configuration Write error on first attempt",
  171. [14] = "Memory or FB-DIMM configuration CRC read error",
  172. [15] = "Channel Failed-Over Occurred",
  173. [16] = "Correctable Non-Mirrored Demand Data ECC",
  174. /* M18 Unsupported on i5400 */
  175. [18] = "Correctable Resilver- or Spare-Copy Data ECC",
  176. [19] = "Correctable Patrol Data ECC",
  177. [20] = "FB-DIMM Northbound parity error on FB-DIMM Sync Status",
  178. [21] = "SPD protocol Error",
  179. [22] = "Non-Redundant Fast Reset Timeout",
  180. [23] = "Refresh error",
  181. [24] = "Memory Write error on redundant retry",
  182. [25] = "Redundant Fast Reset Timeout",
  183. [26] = "Correctable Counter Threshold Exceeded",
  184. [27] = "DIMM-Spare Copy Completed",
  185. [28] = "DIMM-Isolation Completed",
  186. };
  187. /* Fatal errors */
  188. #define ERROR_FAT_MASK (EMASK_M1 | \
  189. EMASK_M2 | \
  190. EMASK_M23)
  191. /* Correctable errors */
  192. #define ERROR_NF_CORRECTABLE (EMASK_M27 | \
  193. EMASK_M20 | \
  194. EMASK_M19 | \
  195. EMASK_M18 | \
  196. EMASK_M17 | \
  197. EMASK_M16)
  198. #define ERROR_NF_DIMM_SPARE (EMASK_M29 | \
  199. EMASK_M28)
  200. #define ERROR_NF_SPD_PROTOCOL (EMASK_M22)
  201. #define ERROR_NF_NORTH_CRC (EMASK_M21)
  202. /* Recoverable errors */
  203. #define ERROR_NF_RECOVERABLE (EMASK_M26 | \
  204. EMASK_M25 | \
  205. EMASK_M24 | \
  206. EMASK_M15 | \
  207. EMASK_M14 | \
  208. EMASK_M13 | \
  209. EMASK_M12 | \
  210. EMASK_M11 | \
  211. EMASK_M9 | \
  212. EMASK_M8 | \
  213. EMASK_M7 | \
  214. EMASK_M5)
  215. /* uncorrectable errors */
  216. #define ERROR_NF_UNCORRECTABLE (EMASK_M4)
  217. /* mask to all non-fatal errors */
  218. #define ERROR_NF_MASK (ERROR_NF_CORRECTABLE | \
  219. ERROR_NF_UNCORRECTABLE | \
  220. ERROR_NF_RECOVERABLE | \
  221. ERROR_NF_DIMM_SPARE | \
  222. ERROR_NF_SPD_PROTOCOL | \
  223. ERROR_NF_NORTH_CRC)
  224. /*
  225. * Define error masks for the several registers
  226. */
  227. /* Enable all fatal and non fatal errors */
  228. #define ENABLE_EMASK_ALL (ERROR_FAT_MASK | ERROR_NF_MASK)
  229. /* mask for fatal error registers */
  230. #define FERR_FAT_MASK ERROR_FAT_MASK
  231. /* masks for non-fatal error register */
  232. static inline int to_nf_mask(unsigned int mask)
  233. {
  234. return (mask & EMASK_M29) | (mask >> 3);
  235. };
  236. static inline int from_nf_ferr(unsigned int mask)
  237. {
  238. return (mask & EMASK_M29) | /* Bit 28 */
  239. (mask & ((1 << 28) - 1) << 3); /* Bits 0 to 27 */
  240. };
  241. #define FERR_NF_MASK to_nf_mask(ERROR_NF_MASK)
  242. #define FERR_NF_CORRECTABLE to_nf_mask(ERROR_NF_CORRECTABLE)
  243. #define FERR_NF_DIMM_SPARE to_nf_mask(ERROR_NF_DIMM_SPARE)
  244. #define FERR_NF_SPD_PROTOCOL to_nf_mask(ERROR_NF_SPD_PROTOCOL)
  245. #define FERR_NF_NORTH_CRC to_nf_mask(ERROR_NF_NORTH_CRC)
  246. #define FERR_NF_RECOVERABLE to_nf_mask(ERROR_NF_RECOVERABLE)
  247. #define FERR_NF_UNCORRECTABLE to_nf_mask(ERROR_NF_UNCORRECTABLE)
  248. /* Defines to extract the vaious fields from the
  249. * MTRx - Memory Technology Registers
  250. */
  251. #define MTR_DIMMS_PRESENT(mtr) ((mtr) & (1 << 10))
  252. #define MTR_DIMMS_ETHROTTLE(mtr) ((mtr) & (1 << 9))
  253. #define MTR_DRAM_WIDTH(mtr) (((mtr) & (1 << 8)) ? 8 : 4)
  254. #define MTR_DRAM_BANKS(mtr) (((mtr) & (1 << 6)) ? 8 : 4)
  255. #define MTR_DRAM_BANKS_ADDR_BITS(mtr) ((MTR_DRAM_BANKS(mtr) == 8) ? 3 : 2)
  256. #define MTR_DIMM_RANK(mtr) (((mtr) >> 5) & 0x1)
  257. #define MTR_DIMM_RANK_ADDR_BITS(mtr) (MTR_DIMM_RANK(mtr) ? 2 : 1)
  258. #define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
  259. #define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
  260. #define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
  261. #define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
  262. /* This applies to FERR_NF_FB-DIMM as well as FERR_FAT_FB-DIMM */
  263. static inline int extract_fbdchan_indx(u32 x)
  264. {
  265. return (x>>28) & 0x3;
  266. }
  267. #ifdef CONFIG_EDAC_DEBUG
  268. /* MTR NUMROW */
  269. static const char *numrow_toString[] = {
  270. "8,192 - 13 rows",
  271. "16,384 - 14 rows",
  272. "32,768 - 15 rows",
  273. "65,536 - 16 rows"
  274. };
  275. /* MTR NUMCOL */
  276. static const char *numcol_toString[] = {
  277. "1,024 - 10 columns",
  278. "2,048 - 11 columns",
  279. "4,096 - 12 columns",
  280. "reserved"
  281. };
  282. #endif
  283. /* Device name and register DID (Device ID) */
  284. struct i5400_dev_info {
  285. const char *ctl_name; /* name for this device */
  286. u16 fsb_mapping_errors; /* DID for the branchmap,control */
  287. };
  288. /* Table of devices attributes supported by this driver */
  289. static const struct i5400_dev_info i5400_devs[] = {
  290. {
  291. .ctl_name = "I5400",
  292. .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_5400_ERR,
  293. },
  294. };
  295. struct i5400_dimm_info {
  296. int megabytes; /* size, 0 means not present */
  297. };
  298. /* driver private data structure */
  299. struct i5400_pvt {
  300. struct pci_dev *system_address; /* 16.0 */
  301. struct pci_dev *branchmap_werrors; /* 16.1 */
  302. struct pci_dev *fsb_error_regs; /* 16.2 */
  303. struct pci_dev *branch_0; /* 21.0 */
  304. struct pci_dev *branch_1; /* 22.0 */
  305. u16 tolm; /* top of low memory */
  306. u64 ambase; /* AMB BAR */
  307. u16 mir0, mir1;
  308. u16 b0_mtr[DIMMS_PER_CHANNEL]; /* Memory Technlogy Reg */
  309. u16 b0_ambpresent0; /* Branch 0, Channel 0 */
  310. u16 b0_ambpresent1; /* Brnach 0, Channel 1 */
  311. u16 b1_mtr[DIMMS_PER_CHANNEL]; /* Memory Technlogy Reg */
  312. u16 b1_ambpresent0; /* Branch 1, Channel 8 */
  313. u16 b1_ambpresent1; /* Branch 1, Channel 1 */
  314. /* DIMM information matrix, allocating architecture maximums */
  315. struct i5400_dimm_info dimm_info[DIMMS_PER_CHANNEL][MAX_CHANNELS];
  316. /* Actual values for this controller */
  317. int maxch; /* Max channels */
  318. int maxdimmperch; /* Max DIMMs per channel */
  319. };
  320. /* I5400 MCH error information retrieved from Hardware */
  321. struct i5400_error_info {
  322. /* These registers are always read from the MC */
  323. u32 ferr_fat_fbd; /* First Errors Fatal */
  324. u32 nerr_fat_fbd; /* Next Errors Fatal */
  325. u32 ferr_nf_fbd; /* First Errors Non-Fatal */
  326. u32 nerr_nf_fbd; /* Next Errors Non-Fatal */
  327. /* These registers are input ONLY if there was a Recoverable Error */
  328. u32 redmemb; /* Recoverable Mem Data Error log B */
  329. u16 recmema; /* Recoverable Mem Error log A */
  330. u32 recmemb; /* Recoverable Mem Error log B */
  331. /* These registers are input ONLY if there was a Non-Rec Error */
  332. u16 nrecmema; /* Non-Recoverable Mem log A */
  333. u16 nrecmemb; /* Non-Recoverable Mem log B */
  334. };
  335. /* note that nrec_rdwr changed from NRECMEMA to NRECMEMB between the 5000 and
  336. 5400 better to use an inline function than a macro in this case */
  337. static inline int nrec_bank(struct i5400_error_info *info)
  338. {
  339. return ((info->nrecmema) >> 12) & 0x7;
  340. }
  341. static inline int nrec_rank(struct i5400_error_info *info)
  342. {
  343. return ((info->nrecmema) >> 8) & 0xf;
  344. }
  345. static inline int nrec_buf_id(struct i5400_error_info *info)
  346. {
  347. return ((info->nrecmema)) & 0xff;
  348. }
  349. static inline int nrec_rdwr(struct i5400_error_info *info)
  350. {
  351. return (info->nrecmemb) >> 31;
  352. }
  353. /* This applies to both NREC and REC string so it can be used with nrec_rdwr
  354. and rec_rdwr */
  355. static inline const char *rdwr_str(int rdwr)
  356. {
  357. return rdwr ? "Write" : "Read";
  358. }
  359. static inline int nrec_cas(struct i5400_error_info *info)
  360. {
  361. return ((info->nrecmemb) >> 16) & 0x1fff;
  362. }
  363. static inline int nrec_ras(struct i5400_error_info *info)
  364. {
  365. return (info->nrecmemb) & 0xffff;
  366. }
  367. static inline int rec_bank(struct i5400_error_info *info)
  368. {
  369. return ((info->recmema) >> 12) & 0x7;
  370. }
  371. static inline int rec_rank(struct i5400_error_info *info)
  372. {
  373. return ((info->recmema) >> 8) & 0xf;
  374. }
  375. static inline int rec_rdwr(struct i5400_error_info *info)
  376. {
  377. return (info->recmemb) >> 31;
  378. }
  379. static inline int rec_cas(struct i5400_error_info *info)
  380. {
  381. return ((info->recmemb) >> 16) & 0x1fff;
  382. }
  383. static inline int rec_ras(struct i5400_error_info *info)
  384. {
  385. return (info->recmemb) & 0xffff;
  386. }
  387. static struct edac_pci_ctl_info *i5400_pci;
  388. /*
  389. * i5400_get_error_info Retrieve the hardware error information from
  390. * the hardware and cache it in the 'info'
  391. * structure
  392. */
  393. static void i5400_get_error_info(struct mem_ctl_info *mci,
  394. struct i5400_error_info *info)
  395. {
  396. struct i5400_pvt *pvt;
  397. u32 value;
  398. pvt = mci->pvt_info;
  399. /* read in the 1st FATAL error register */
  400. pci_read_config_dword(pvt->branchmap_werrors, FERR_FAT_FBD, &value);
  401. /* Mask only the bits that the doc says are valid
  402. */
  403. value &= (FERR_FAT_FBDCHAN | FERR_FAT_MASK);
  404. /* If there is an error, then read in the
  405. NEXT FATAL error register and the Memory Error Log Register A
  406. */
  407. if (value & FERR_FAT_MASK) {
  408. info->ferr_fat_fbd = value;
  409. /* harvest the various error data we need */
  410. pci_read_config_dword(pvt->branchmap_werrors,
  411. NERR_FAT_FBD, &info->nerr_fat_fbd);
  412. pci_read_config_word(pvt->branchmap_werrors,
  413. NRECMEMA, &info->nrecmema);
  414. pci_read_config_word(pvt->branchmap_werrors,
  415. NRECMEMB, &info->nrecmemb);
  416. /* Clear the error bits, by writing them back */
  417. pci_write_config_dword(pvt->branchmap_werrors,
  418. FERR_FAT_FBD, value);
  419. } else {
  420. info->ferr_fat_fbd = 0;
  421. info->nerr_fat_fbd = 0;
  422. info->nrecmema = 0;
  423. info->nrecmemb = 0;
  424. }
  425. /* read in the 1st NON-FATAL error register */
  426. pci_read_config_dword(pvt->branchmap_werrors, FERR_NF_FBD, &value);
  427. /* If there is an error, then read in the 1st NON-FATAL error
  428. * register as well */
  429. if (value & FERR_NF_MASK) {
  430. info->ferr_nf_fbd = value;
  431. /* harvest the various error data we need */
  432. pci_read_config_dword(pvt->branchmap_werrors,
  433. NERR_NF_FBD, &info->nerr_nf_fbd);
  434. pci_read_config_word(pvt->branchmap_werrors,
  435. RECMEMA, &info->recmema);
  436. pci_read_config_dword(pvt->branchmap_werrors,
  437. RECMEMB, &info->recmemb);
  438. pci_read_config_dword(pvt->branchmap_werrors,
  439. REDMEMB, &info->redmemb);
  440. /* Clear the error bits, by writing them back */
  441. pci_write_config_dword(pvt->branchmap_werrors,
  442. FERR_NF_FBD, value);
  443. } else {
  444. info->ferr_nf_fbd = 0;
  445. info->nerr_nf_fbd = 0;
  446. info->recmema = 0;
  447. info->recmemb = 0;
  448. info->redmemb = 0;
  449. }
  450. }
  451. /*
  452. * i5400_proccess_non_recoverable_info(struct mem_ctl_info *mci,
  453. * struct i5400_error_info *info,
  454. * int handle_errors);
  455. *
  456. * handle the Intel FATAL and unrecoverable errors, if any
  457. */
  458. static void i5400_proccess_non_recoverable_info(struct mem_ctl_info *mci,
  459. struct i5400_error_info *info,
  460. unsigned long allErrors)
  461. {
  462. char msg[EDAC_MC_LABEL_LEN + 1 + 90 + 80];
  463. int branch;
  464. int channel;
  465. int bank;
  466. int buf_id;
  467. int rank;
  468. int rdwr;
  469. int ras, cas;
  470. int errnum;
  471. char *type = NULL;
  472. enum hw_event_mc_err_type tp_event = HW_EVENT_ERR_UNCORRECTED;
  473. if (!allErrors)
  474. return; /* if no error, return now */
  475. if (allErrors & ERROR_FAT_MASK) {
  476. type = "FATAL";
  477. tp_event = HW_EVENT_ERR_FATAL;
  478. } else if (allErrors & FERR_NF_UNCORRECTABLE)
  479. type = "NON-FATAL uncorrected";
  480. else
  481. type = "NON-FATAL recoverable";
  482. /* ONLY ONE of the possible error bits will be set, as per the docs */
  483. branch = extract_fbdchan_indx(info->ferr_fat_fbd);
  484. channel = branch;
  485. /* Use the NON-Recoverable macros to extract data */
  486. bank = nrec_bank(info);
  487. rank = nrec_rank(info);
  488. buf_id = nrec_buf_id(info);
  489. rdwr = nrec_rdwr(info);
  490. ras = nrec_ras(info);
  491. cas = nrec_cas(info);
  492. debugf0("\t\tDIMM= %d Channels= %d,%d (Branch= %d "
  493. "DRAM Bank= %d Buffer ID = %d rdwr= %s ras= %d cas= %d)\n",
  494. rank, channel, channel + 1, branch >> 1, bank,
  495. buf_id, rdwr_str(rdwr), ras, cas);
  496. /* Only 1 bit will be on */
  497. errnum = find_first_bit(&allErrors, ARRAY_SIZE(error_name));
  498. /* Form out message */
  499. snprintf(msg, sizeof(msg),
  500. "Bank=%d Buffer ID = %d RAS=%d CAS=%d Err=0x%lx (%s)",
  501. bank, buf_id, ras, cas, allErrors, error_name[errnum]);
  502. edac_mc_handle_error(tp_event, mci, 0, 0, 0,
  503. branch >> 1, -1, rank,
  504. rdwr ? "Write error" : "Read error",
  505. msg, NULL);
  506. }
  507. /*
  508. * i5400_process_fatal_error_info(struct mem_ctl_info *mci,
  509. * struct i5400_error_info *info,
  510. * int handle_errors);
  511. *
  512. * handle the Intel NON-FATAL errors, if any
  513. */
  514. static void i5400_process_nonfatal_error_info(struct mem_ctl_info *mci,
  515. struct i5400_error_info *info)
  516. {
  517. char msg[EDAC_MC_LABEL_LEN + 1 + 90 + 80];
  518. unsigned long allErrors;
  519. int branch;
  520. int channel;
  521. int bank;
  522. int rank;
  523. int rdwr;
  524. int ras, cas;
  525. int errnum;
  526. /* mask off the Error bits that are possible */
  527. allErrors = from_nf_ferr(info->ferr_nf_fbd & FERR_NF_MASK);
  528. if (!allErrors)
  529. return; /* if no error, return now */
  530. /* ONLY ONE of the possible error bits will be set, as per the docs */
  531. if (allErrors & (ERROR_NF_UNCORRECTABLE | ERROR_NF_RECOVERABLE)) {
  532. i5400_proccess_non_recoverable_info(mci, info, allErrors);
  533. return;
  534. }
  535. /* Correctable errors */
  536. if (allErrors & ERROR_NF_CORRECTABLE) {
  537. debugf0("\tCorrected bits= 0x%lx\n", allErrors);
  538. branch = extract_fbdchan_indx(info->ferr_nf_fbd);
  539. channel = 0;
  540. if (REC_ECC_LOCATOR_ODD(info->redmemb))
  541. channel = 1;
  542. /* Convert channel to be based from zero, instead of
  543. * from branch base of 0 */
  544. channel += branch;
  545. bank = rec_bank(info);
  546. rank = rec_rank(info);
  547. rdwr = rec_rdwr(info);
  548. ras = rec_ras(info);
  549. cas = rec_cas(info);
  550. /* Only 1 bit will be on */
  551. errnum = find_first_bit(&allErrors, ARRAY_SIZE(error_name));
  552. debugf0("\t\tDIMM= %d Channel= %d (Branch %d "
  553. "DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  554. rank, channel, branch >> 1, bank,
  555. rdwr_str(rdwr), ras, cas);
  556. /* Form out message */
  557. snprintf(msg, sizeof(msg),
  558. "Corrected error (Branch=%d DRAM-Bank=%d RDWR=%s "
  559. "RAS=%d CAS=%d, CE Err=0x%lx (%s))",
  560. branch >> 1, bank, rdwr_str(rdwr), ras, cas,
  561. allErrors, error_name[errnum]);
  562. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 0, 0, 0,
  563. branch >> 1, channel % 2, rank,
  564. rdwr ? "Write error" : "Read error",
  565. msg, NULL);
  566. return;
  567. }
  568. /* Miscellaneous errors */
  569. errnum = find_first_bit(&allErrors, ARRAY_SIZE(error_name));
  570. branch = extract_fbdchan_indx(info->ferr_nf_fbd);
  571. i5400_mc_printk(mci, KERN_EMERG,
  572. "Non-Fatal misc error (Branch=%d Err=%#lx (%s))",
  573. branch >> 1, allErrors, error_name[errnum]);
  574. }
  575. /*
  576. * i5400_process_error_info Process the error info that is
  577. * in the 'info' structure, previously retrieved from hardware
  578. */
  579. static void i5400_process_error_info(struct mem_ctl_info *mci,
  580. struct i5400_error_info *info)
  581. { u32 allErrors;
  582. /* First handle any fatal errors that occurred */
  583. allErrors = (info->ferr_fat_fbd & FERR_FAT_MASK);
  584. i5400_proccess_non_recoverable_info(mci, info, allErrors);
  585. /* now handle any non-fatal errors that occurred */
  586. i5400_process_nonfatal_error_info(mci, info);
  587. }
  588. /*
  589. * i5400_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 i5400_clear_error(struct mem_ctl_info *mci)
  595. {
  596. struct i5400_error_info info;
  597. i5400_get_error_info(mci, &info);
  598. }
  599. /*
  600. * i5400_check_error Retrieve and process errors reported by the
  601. * hardware. Called by the Core module.
  602. */
  603. static void i5400_check_error(struct mem_ctl_info *mci)
  604. {
  605. struct i5400_error_info info;
  606. debugf4("MC%d: %s: %s()\n", mci->mc_idx, __FILE__, __func__);
  607. i5400_get_error_info(mci, &info);
  608. i5400_process_error_info(mci, &info);
  609. }
  610. /*
  611. * i5400_put_devices 'put' all the devices that we have
  612. * reserved via 'get'
  613. */
  614. static void i5400_put_devices(struct mem_ctl_info *mci)
  615. {
  616. struct i5400_pvt *pvt;
  617. pvt = mci->pvt_info;
  618. /* Decrement usage count for devices */
  619. pci_dev_put(pvt->branch_1);
  620. pci_dev_put(pvt->branch_0);
  621. pci_dev_put(pvt->fsb_error_regs);
  622. pci_dev_put(pvt->branchmap_werrors);
  623. }
  624. /*
  625. * i5400_get_devices Find and perform 'get' operation on the MCH's
  626. * device/functions we want to reference for this driver
  627. *
  628. * Need to 'get' device 16 func 1 and func 2
  629. */
  630. static int i5400_get_devices(struct mem_ctl_info *mci, int dev_idx)
  631. {
  632. struct i5400_pvt *pvt;
  633. struct pci_dev *pdev;
  634. pvt = mci->pvt_info;
  635. pvt->branchmap_werrors = NULL;
  636. pvt->fsb_error_regs = NULL;
  637. pvt->branch_0 = NULL;
  638. pvt->branch_1 = NULL;
  639. /* Attempt to 'get' the MCH register we want */
  640. pdev = NULL;
  641. while (1) {
  642. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  643. PCI_DEVICE_ID_INTEL_5400_ERR, pdev);
  644. if (!pdev) {
  645. /* End of list, leave */
  646. i5400_printk(KERN_ERR,
  647. "'system address,Process Bus' "
  648. "device not found:"
  649. "vendor 0x%x device 0x%x ERR func 1 "
  650. "(broken BIOS?)\n",
  651. PCI_VENDOR_ID_INTEL,
  652. PCI_DEVICE_ID_INTEL_5400_ERR);
  653. return -ENODEV;
  654. }
  655. /* Store device 16 func 1 */
  656. if (PCI_FUNC(pdev->devfn) == 1)
  657. break;
  658. }
  659. pvt->branchmap_werrors = pdev;
  660. pdev = NULL;
  661. while (1) {
  662. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  663. PCI_DEVICE_ID_INTEL_5400_ERR, pdev);
  664. if (!pdev) {
  665. /* End of list, leave */
  666. i5400_printk(KERN_ERR,
  667. "'system address,Process Bus' "
  668. "device not found:"
  669. "vendor 0x%x device 0x%x ERR func 2 "
  670. "(broken BIOS?)\n",
  671. PCI_VENDOR_ID_INTEL,
  672. PCI_DEVICE_ID_INTEL_5400_ERR);
  673. pci_dev_put(pvt->branchmap_werrors);
  674. return -ENODEV;
  675. }
  676. /* Store device 16 func 2 */
  677. if (PCI_FUNC(pdev->devfn) == 2)
  678. break;
  679. }
  680. pvt->fsb_error_regs = pdev;
  681. debugf1("System Address, processor bus- PCI Bus ID: %s %x:%x\n",
  682. pci_name(pvt->system_address),
  683. pvt->system_address->vendor, pvt->system_address->device);
  684. debugf1("Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
  685. pci_name(pvt->branchmap_werrors),
  686. pvt->branchmap_werrors->vendor, pvt->branchmap_werrors->device);
  687. debugf1("FSB Error Regs - PCI Bus ID: %s %x:%x\n",
  688. pci_name(pvt->fsb_error_regs),
  689. pvt->fsb_error_regs->vendor, pvt->fsb_error_regs->device);
  690. pvt->branch_0 = pci_get_device(PCI_VENDOR_ID_INTEL,
  691. PCI_DEVICE_ID_INTEL_5400_FBD0, NULL);
  692. if (!pvt->branch_0) {
  693. i5400_printk(KERN_ERR,
  694. "MC: 'BRANCH 0' device not found:"
  695. "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
  696. PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_FBD0);
  697. pci_dev_put(pvt->fsb_error_regs);
  698. pci_dev_put(pvt->branchmap_werrors);
  699. return -ENODEV;
  700. }
  701. /* If this device claims to have more than 2 channels then
  702. * fetch Branch 1's information
  703. */
  704. if (pvt->maxch < CHANNELS_PER_BRANCH)
  705. return 0;
  706. pvt->branch_1 = pci_get_device(PCI_VENDOR_ID_INTEL,
  707. PCI_DEVICE_ID_INTEL_5400_FBD1, NULL);
  708. if (!pvt->branch_1) {
  709. i5400_printk(KERN_ERR,
  710. "MC: 'BRANCH 1' device not found:"
  711. "vendor 0x%x device 0x%x Func 0 "
  712. "(broken BIOS?)\n",
  713. PCI_VENDOR_ID_INTEL,
  714. PCI_DEVICE_ID_INTEL_5400_FBD1);
  715. pci_dev_put(pvt->branch_0);
  716. pci_dev_put(pvt->fsb_error_regs);
  717. pci_dev_put(pvt->branchmap_werrors);
  718. return -ENODEV;
  719. }
  720. return 0;
  721. }
  722. /*
  723. * determine_amb_present
  724. *
  725. * the information is contained in DIMMS_PER_CHANNEL different
  726. * registers determining which of the DIMMS_PER_CHANNEL requires
  727. * knowing which channel is in question
  728. *
  729. * 2 branches, each with 2 channels
  730. * b0_ambpresent0 for channel '0'
  731. * b0_ambpresent1 for channel '1'
  732. * b1_ambpresent0 for channel '2'
  733. * b1_ambpresent1 for channel '3'
  734. */
  735. static int determine_amb_present_reg(struct i5400_pvt *pvt, int channel)
  736. {
  737. int amb_present;
  738. if (channel < CHANNELS_PER_BRANCH) {
  739. if (channel & 0x1)
  740. amb_present = pvt->b0_ambpresent1;
  741. else
  742. amb_present = pvt->b0_ambpresent0;
  743. } else {
  744. if (channel & 0x1)
  745. amb_present = pvt->b1_ambpresent1;
  746. else
  747. amb_present = pvt->b1_ambpresent0;
  748. }
  749. return amb_present;
  750. }
  751. /*
  752. * determine_mtr(pvt, dimm, channel)
  753. *
  754. * return the proper MTR register as determine by the dimm and desired channel
  755. */
  756. static int determine_mtr(struct i5400_pvt *pvt, int dimm, int channel)
  757. {
  758. int mtr;
  759. int n;
  760. /* There is one MTR for each slot pair of FB-DIMMs,
  761. Each slot pair may be at branch 0 or branch 1.
  762. */
  763. n = dimm;
  764. if (n >= DIMMS_PER_CHANNEL) {
  765. debugf0("ERROR: trying to access an invalid dimm: %d\n",
  766. dimm);
  767. return 0;
  768. }
  769. if (channel < CHANNELS_PER_BRANCH)
  770. mtr = pvt->b0_mtr[n];
  771. else
  772. mtr = pvt->b1_mtr[n];
  773. return mtr;
  774. }
  775. /*
  776. */
  777. static void decode_mtr(int slot_row, u16 mtr)
  778. {
  779. int ans;
  780. ans = MTR_DIMMS_PRESENT(mtr);
  781. debugf2("\tMTR%d=0x%x: DIMMs are %s\n", slot_row, mtr,
  782. ans ? "Present" : "NOT Present");
  783. if (!ans)
  784. return;
  785. debugf2("\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
  786. debugf2("\t\tELECTRICAL THROTTLING is %s\n",
  787. MTR_DIMMS_ETHROTTLE(mtr) ? "enabled" : "disabled");
  788. debugf2("\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
  789. debugf2("\t\tNUMRANK: %s\n", MTR_DIMM_RANK(mtr) ? "double" : "single");
  790. debugf2("\t\tNUMROW: %s\n", numrow_toString[MTR_DIMM_ROWS(mtr)]);
  791. debugf2("\t\tNUMCOL: %s\n", numcol_toString[MTR_DIMM_COLS(mtr)]);
  792. }
  793. static void handle_channel(struct i5400_pvt *pvt, int dimm, int channel,
  794. struct i5400_dimm_info *dinfo)
  795. {
  796. int mtr;
  797. int amb_present_reg;
  798. int addrBits;
  799. mtr = determine_mtr(pvt, dimm, channel);
  800. if (MTR_DIMMS_PRESENT(mtr)) {
  801. amb_present_reg = determine_amb_present_reg(pvt, channel);
  802. /* Determine if there is a DIMM present in this DIMM slot */
  803. if (amb_present_reg & (1 << dimm)) {
  804. /* Start with the number of bits for a Bank
  805. * on the DRAM */
  806. addrBits = MTR_DRAM_BANKS_ADDR_BITS(mtr);
  807. /* Add thenumber of ROW bits */
  808. addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
  809. /* add the number of COLUMN bits */
  810. addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
  811. /* add the number of RANK bits */
  812. addrBits += MTR_DIMM_RANK(mtr);
  813. addrBits += 6; /* add 64 bits per DIMM */
  814. addrBits -= 20; /* divide by 2^^20 */
  815. addrBits -= 3; /* 8 bits per bytes */
  816. dinfo->megabytes = 1 << addrBits;
  817. }
  818. }
  819. }
  820. /*
  821. * calculate_dimm_size
  822. *
  823. * also will output a DIMM matrix map, if debug is enabled, for viewing
  824. * how the DIMMs are populated
  825. */
  826. static void calculate_dimm_size(struct i5400_pvt *pvt)
  827. {
  828. struct i5400_dimm_info *dinfo;
  829. int dimm, max_dimms;
  830. char *p, *mem_buffer;
  831. int space, n;
  832. int channel, branch;
  833. /* ================= Generate some debug output ================= */
  834. space = PAGE_SIZE;
  835. mem_buffer = p = kmalloc(space, GFP_KERNEL);
  836. if (p == NULL) {
  837. i5400_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
  838. __FILE__, __func__);
  839. return;
  840. }
  841. /* Scan all the actual DIMMS
  842. * and calculate the information for each DIMM
  843. * Start with the highest dimm first, to display it first
  844. * and work toward the 0th dimm
  845. */
  846. max_dimms = pvt->maxdimmperch;
  847. for (dimm = max_dimms - 1; dimm >= 0; dimm--) {
  848. /* on an odd dimm, first output a 'boundary' marker,
  849. * then reset the message buffer */
  850. if (dimm & 0x1) {
  851. n = snprintf(p, space, "---------------------------"
  852. "-------------------------------");
  853. p += n;
  854. space -= n;
  855. debugf2("%s\n", mem_buffer);
  856. p = mem_buffer;
  857. space = PAGE_SIZE;
  858. }
  859. n = snprintf(p, space, "dimm %2d ", dimm);
  860. p += n;
  861. space -= n;
  862. for (channel = 0; channel < pvt->maxch; channel++) {
  863. dinfo = &pvt->dimm_info[dimm][channel];
  864. handle_channel(pvt, dimm, channel, dinfo);
  865. n = snprintf(p, space, "%4d MB | ", dinfo->megabytes);
  866. p += n;
  867. space -= n;
  868. }
  869. debugf2("%s\n", mem_buffer);
  870. p = mem_buffer;
  871. space = PAGE_SIZE;
  872. }
  873. /* Output the last bottom 'boundary' marker */
  874. n = snprintf(p, space, "---------------------------"
  875. "-------------------------------");
  876. p += n;
  877. space -= n;
  878. debugf2("%s\n", mem_buffer);
  879. p = mem_buffer;
  880. space = PAGE_SIZE;
  881. /* now output the 'channel' labels */
  882. n = snprintf(p, space, " ");
  883. p += n;
  884. space -= n;
  885. for (channel = 0; channel < pvt->maxch; channel++) {
  886. n = snprintf(p, space, "channel %d | ", channel);
  887. p += n;
  888. space -= n;
  889. }
  890. space -= n;
  891. debugf2("%s\n", mem_buffer);
  892. p = mem_buffer;
  893. space = PAGE_SIZE;
  894. n = snprintf(p, space, " ");
  895. p += n;
  896. for (branch = 0; branch < MAX_BRANCHES; branch++) {
  897. n = snprintf(p, space, " branch %d | ", branch);
  898. p += n;
  899. space -= n;
  900. }
  901. /* output the last message and free buffer */
  902. debugf2("%s\n", mem_buffer);
  903. kfree(mem_buffer);
  904. }
  905. /*
  906. * i5400_get_mc_regs read in the necessary registers and
  907. * cache locally
  908. *
  909. * Fills in the private data members
  910. */
  911. static void i5400_get_mc_regs(struct mem_ctl_info *mci)
  912. {
  913. struct i5400_pvt *pvt;
  914. u32 actual_tolm;
  915. u16 limit;
  916. int slot_row;
  917. int maxch;
  918. int maxdimmperch;
  919. int way0, way1;
  920. pvt = mci->pvt_info;
  921. pci_read_config_dword(pvt->system_address, AMBASE,
  922. (u32 *) &pvt->ambase);
  923. pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
  924. ((u32 *) &pvt->ambase) + sizeof(u32));
  925. maxdimmperch = pvt->maxdimmperch;
  926. maxch = pvt->maxch;
  927. debugf2("AMBASE= 0x%lx MAXCH= %d MAX-DIMM-Per-CH= %d\n",
  928. (long unsigned int)pvt->ambase, pvt->maxch, pvt->maxdimmperch);
  929. /* Get the Branch Map regs */
  930. pci_read_config_word(pvt->branchmap_werrors, TOLM, &pvt->tolm);
  931. pvt->tolm >>= 12;
  932. debugf2("\nTOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
  933. pvt->tolm);
  934. actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28));
  935. debugf2("Actual TOLM byte addr=%u.%03u GB (0x%x)\n",
  936. actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28);
  937. pci_read_config_word(pvt->branchmap_werrors, MIR0, &pvt->mir0);
  938. pci_read_config_word(pvt->branchmap_werrors, MIR1, &pvt->mir1);
  939. /* Get the MIR[0-1] regs */
  940. limit = (pvt->mir0 >> 4) & 0x0fff;
  941. way0 = pvt->mir0 & 0x1;
  942. way1 = pvt->mir0 & 0x2;
  943. debugf2("MIR0: limit= 0x%x WAY1= %u WAY0= %x\n", limit, way1, way0);
  944. limit = (pvt->mir1 >> 4) & 0xfff;
  945. way0 = pvt->mir1 & 0x1;
  946. way1 = pvt->mir1 & 0x2;
  947. debugf2("MIR1: limit= 0x%x WAY1= %u WAY0= %x\n", limit, way1, way0);
  948. /* Get the set of MTR[0-3] regs by each branch */
  949. for (slot_row = 0; slot_row < DIMMS_PER_CHANNEL; slot_row++) {
  950. int where = MTR0 + (slot_row * sizeof(u16));
  951. /* Branch 0 set of MTR registers */
  952. pci_read_config_word(pvt->branch_0, where,
  953. &pvt->b0_mtr[slot_row]);
  954. debugf2("MTR%d where=0x%x B0 value=0x%x\n", slot_row, where,
  955. pvt->b0_mtr[slot_row]);
  956. if (pvt->maxch < CHANNELS_PER_BRANCH) {
  957. pvt->b1_mtr[slot_row] = 0;
  958. continue;
  959. }
  960. /* Branch 1 set of MTR registers */
  961. pci_read_config_word(pvt->branch_1, where,
  962. &pvt->b1_mtr[slot_row]);
  963. debugf2("MTR%d where=0x%x B1 value=0x%x\n", slot_row, where,
  964. pvt->b1_mtr[slot_row]);
  965. }
  966. /* Read and dump branch 0's MTRs */
  967. debugf2("\nMemory Technology Registers:\n");
  968. debugf2(" Branch 0:\n");
  969. for (slot_row = 0; slot_row < DIMMS_PER_CHANNEL; slot_row++)
  970. decode_mtr(slot_row, pvt->b0_mtr[slot_row]);
  971. pci_read_config_word(pvt->branch_0, AMBPRESENT_0,
  972. &pvt->b0_ambpresent0);
  973. debugf2("\t\tAMB-Branch 0-present0 0x%x:\n", pvt->b0_ambpresent0);
  974. pci_read_config_word(pvt->branch_0, AMBPRESENT_1,
  975. &pvt->b0_ambpresent1);
  976. debugf2("\t\tAMB-Branch 0-present1 0x%x:\n", pvt->b0_ambpresent1);
  977. /* Only if we have 2 branchs (4 channels) */
  978. if (pvt->maxch < CHANNELS_PER_BRANCH) {
  979. pvt->b1_ambpresent0 = 0;
  980. pvt->b1_ambpresent1 = 0;
  981. } else {
  982. /* Read and dump branch 1's MTRs */
  983. debugf2(" Branch 1:\n");
  984. for (slot_row = 0; slot_row < DIMMS_PER_CHANNEL; slot_row++)
  985. decode_mtr(slot_row, pvt->b1_mtr[slot_row]);
  986. pci_read_config_word(pvt->branch_1, AMBPRESENT_0,
  987. &pvt->b1_ambpresent0);
  988. debugf2("\t\tAMB-Branch 1-present0 0x%x:\n",
  989. pvt->b1_ambpresent0);
  990. pci_read_config_word(pvt->branch_1, AMBPRESENT_1,
  991. &pvt->b1_ambpresent1);
  992. debugf2("\t\tAMB-Branch 1-present1 0x%x:\n",
  993. pvt->b1_ambpresent1);
  994. }
  995. /* Go and determine the size of each DIMM and place in an
  996. * orderly matrix */
  997. calculate_dimm_size(pvt);
  998. }
  999. /*
  1000. * i5400_init_dimms Initialize the 'dimms' table within
  1001. * the mci control structure with the
  1002. * addressing of memory.
  1003. *
  1004. * return:
  1005. * 0 success
  1006. * 1 no actual memory found on this MC
  1007. */
  1008. static int i5400_init_dimms(struct mem_ctl_info *mci)
  1009. {
  1010. struct i5400_pvt *pvt;
  1011. struct dimm_info *dimm;
  1012. int ndimms, channel_count;
  1013. int max_dimms;
  1014. int mtr;
  1015. int size_mb;
  1016. int channel, slot;
  1017. pvt = mci->pvt_info;
  1018. channel_count = pvt->maxch;
  1019. max_dimms = pvt->maxdimmperch;
  1020. ndimms = 0;
  1021. /*
  1022. * FIXME: remove pvt->dimm_info[slot][channel] and use the 3
  1023. * layers here.
  1024. */
  1025. for (channel = 0; channel < mci->layers[0].size * mci->layers[1].size;
  1026. channel++) {
  1027. for (slot = 0; slot < mci->layers[2].size; slot++) {
  1028. mtr = determine_mtr(pvt, slot, channel);
  1029. /* if no DIMMS on this slot, continue */
  1030. if (!MTR_DIMMS_PRESENT(mtr))
  1031. continue;
  1032. dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, mci->n_layers,
  1033. channel / 2, channel % 2, slot);
  1034. size_mb = pvt->dimm_info[slot][channel].megabytes;
  1035. debugf2("%s: dimm%zd (branch %d channel %d slot %d): %d.%03d GB\n",
  1036. __func__, dimm - mci->dimms,
  1037. channel / 2, channel % 2, slot,
  1038. size_mb / 1000, size_mb % 1000);
  1039. dimm->nr_pages = size_mb << 8;
  1040. dimm->grain = 8;
  1041. dimm->dtype = MTR_DRAM_WIDTH(mtr) ? DEV_X8 : DEV_X4;
  1042. dimm->mtype = MEM_FB_DDR2;
  1043. /*
  1044. * The eccc mechanism is SDDC (aka SECC), with
  1045. * is similar to Chipkill.
  1046. */
  1047. dimm->edac_mode = MTR_DRAM_WIDTH(mtr) ?
  1048. EDAC_S8ECD8ED : EDAC_S4ECD4ED;
  1049. ndimms++;
  1050. }
  1051. }
  1052. /*
  1053. * When just one memory is provided, it should be at location (0,0,0).
  1054. * With such single-DIMM mode, the SDCC algorithm degrades to SECDEC+.
  1055. */
  1056. if (ndimms == 1)
  1057. mci->dimms[0].edac_mode = EDAC_SECDED;
  1058. return (ndimms == 0);
  1059. }
  1060. /*
  1061. * i5400_enable_error_reporting
  1062. * Turn on the memory reporting features of the hardware
  1063. */
  1064. static void i5400_enable_error_reporting(struct mem_ctl_info *mci)
  1065. {
  1066. struct i5400_pvt *pvt;
  1067. u32 fbd_error_mask;
  1068. pvt = mci->pvt_info;
  1069. /* Read the FBD Error Mask Register */
  1070. pci_read_config_dword(pvt->branchmap_werrors, EMASK_FBD,
  1071. &fbd_error_mask);
  1072. /* Enable with a '0' */
  1073. fbd_error_mask &= ~(ENABLE_EMASK_ALL);
  1074. pci_write_config_dword(pvt->branchmap_werrors, EMASK_FBD,
  1075. fbd_error_mask);
  1076. }
  1077. /*
  1078. * i5400_probe1 Probe for ONE instance of device to see if it is
  1079. * present.
  1080. * return:
  1081. * 0 for FOUND a device
  1082. * < 0 for error code
  1083. */
  1084. static int i5400_probe1(struct pci_dev *pdev, int dev_idx)
  1085. {
  1086. struct mem_ctl_info *mci;
  1087. struct i5400_pvt *pvt;
  1088. struct edac_mc_layer layers[3];
  1089. if (dev_idx >= ARRAY_SIZE(i5400_devs))
  1090. return -EINVAL;
  1091. debugf0("MC: %s: %s(), pdev bus %u dev=0x%x fn=0x%x\n",
  1092. __FILE__, __func__,
  1093. pdev->bus->number,
  1094. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  1095. /* We only are looking for func 0 of the set */
  1096. if (PCI_FUNC(pdev->devfn) != 0)
  1097. return -ENODEV;
  1098. /*
  1099. * allocate a new MC control structure
  1100. *
  1101. * This drivers uses the DIMM slot as "csrow" and the rest as "channel".
  1102. */
  1103. layers[0].type = EDAC_MC_LAYER_BRANCH;
  1104. layers[0].size = MAX_BRANCHES;
  1105. layers[0].is_virt_csrow = false;
  1106. layers[1].type = EDAC_MC_LAYER_CHANNEL;
  1107. layers[1].size = CHANNELS_PER_BRANCH;
  1108. layers[1].is_virt_csrow = false;
  1109. layers[2].type = EDAC_MC_LAYER_SLOT;
  1110. layers[2].size = DIMMS_PER_CHANNEL;
  1111. layers[2].is_virt_csrow = true;
  1112. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
  1113. if (mci == NULL)
  1114. return -ENOMEM;
  1115. debugf0("MC: %s: %s(): mci = %p\n", __FILE__, __func__, mci);
  1116. mci->dev = &pdev->dev; /* record ptr to the generic device */
  1117. pvt = mci->pvt_info;
  1118. pvt->system_address = pdev; /* Record this device in our private */
  1119. pvt->maxch = MAX_CHANNELS;
  1120. pvt->maxdimmperch = DIMMS_PER_CHANNEL;
  1121. /* 'get' the pci devices we want to reserve for our use */
  1122. if (i5400_get_devices(mci, dev_idx))
  1123. goto fail0;
  1124. /* Time to get serious */
  1125. i5400_get_mc_regs(mci); /* retrieve the hardware registers */
  1126. mci->mc_idx = 0;
  1127. mci->mtype_cap = MEM_FLAG_FB_DDR2;
  1128. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  1129. mci->edac_cap = EDAC_FLAG_NONE;
  1130. mci->mod_name = "i5400_edac.c";
  1131. mci->mod_ver = I5400_REVISION;
  1132. mci->ctl_name = i5400_devs[dev_idx].ctl_name;
  1133. mci->dev_name = pci_name(pdev);
  1134. mci->ctl_page_to_phys = NULL;
  1135. /* Set the function pointer to an actual operation function */
  1136. mci->edac_check = i5400_check_error;
  1137. /* initialize the MC control structure 'dimms' table
  1138. * with the mapping and control information */
  1139. if (i5400_init_dimms(mci)) {
  1140. debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
  1141. " because i5400_init_dimms() returned nonzero "
  1142. "value\n");
  1143. mci->edac_cap = EDAC_FLAG_NONE; /* no dimms found */
  1144. } else {
  1145. debugf1("MC: Enable error reporting now\n");
  1146. i5400_enable_error_reporting(mci);
  1147. }
  1148. /* add this new MC control structure to EDAC's list of MCs */
  1149. if (edac_mc_add_mc(mci)) {
  1150. debugf0("MC: %s: %s(): failed edac_mc_add_mc()\n",
  1151. __FILE__, __func__);
  1152. /* FIXME: perhaps some code should go here that disables error
  1153. * reporting if we just enabled it
  1154. */
  1155. goto fail1;
  1156. }
  1157. i5400_clear_error(mci);
  1158. /* allocating generic PCI control info */
  1159. i5400_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  1160. if (!i5400_pci) {
  1161. printk(KERN_WARNING
  1162. "%s(): Unable to create PCI control\n",
  1163. __func__);
  1164. printk(KERN_WARNING
  1165. "%s(): PCI error report via EDAC not setup\n",
  1166. __func__);
  1167. }
  1168. return 0;
  1169. /* Error exit unwinding stack */
  1170. fail1:
  1171. i5400_put_devices(mci);
  1172. fail0:
  1173. edac_mc_free(mci);
  1174. return -ENODEV;
  1175. }
  1176. /*
  1177. * i5400_init_one constructor for one instance of device
  1178. *
  1179. * returns:
  1180. * negative on error
  1181. * count (>= 0)
  1182. */
  1183. static int __devinit i5400_init_one(struct pci_dev *pdev,
  1184. const struct pci_device_id *id)
  1185. {
  1186. int rc;
  1187. debugf0("MC: %s: %s()\n", __FILE__, __func__);
  1188. /* wake up device */
  1189. rc = pci_enable_device(pdev);
  1190. if (rc)
  1191. return rc;
  1192. /* now probe and enable the device */
  1193. return i5400_probe1(pdev, id->driver_data);
  1194. }
  1195. /*
  1196. * i5400_remove_one destructor for one instance of device
  1197. *
  1198. */
  1199. static void __devexit i5400_remove_one(struct pci_dev *pdev)
  1200. {
  1201. struct mem_ctl_info *mci;
  1202. debugf0("%s: %s()\n", __FILE__, __func__);
  1203. if (i5400_pci)
  1204. edac_pci_release_generic_ctl(i5400_pci);
  1205. mci = edac_mc_del_mc(&pdev->dev);
  1206. if (!mci)
  1207. return;
  1208. /* retrieve references to resources, and free those resources */
  1209. i5400_put_devices(mci);
  1210. edac_mc_free(mci);
  1211. }
  1212. /*
  1213. * pci_device_id table for which devices we are looking for
  1214. *
  1215. * The "E500P" device is the first device supported.
  1216. */
  1217. static DEFINE_PCI_DEVICE_TABLE(i5400_pci_tbl) = {
  1218. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
  1219. {0,} /* 0 terminated list. */
  1220. };
  1221. MODULE_DEVICE_TABLE(pci, i5400_pci_tbl);
  1222. /*
  1223. * i5400_driver pci_driver structure for this module
  1224. *
  1225. */
  1226. static struct pci_driver i5400_driver = {
  1227. .name = "i5400_edac",
  1228. .probe = i5400_init_one,
  1229. .remove = __devexit_p(i5400_remove_one),
  1230. .id_table = i5400_pci_tbl,
  1231. };
  1232. /*
  1233. * i5400_init Module entry function
  1234. * Try to initialize this module for its devices
  1235. */
  1236. static int __init i5400_init(void)
  1237. {
  1238. int pci_rc;
  1239. debugf2("MC: %s: %s()\n", __FILE__, __func__);
  1240. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1241. opstate_init();
  1242. pci_rc = pci_register_driver(&i5400_driver);
  1243. return (pci_rc < 0) ? pci_rc : 0;
  1244. }
  1245. /*
  1246. * i5400_exit() Module exit function
  1247. * Unregister the driver
  1248. */
  1249. static void __exit i5400_exit(void)
  1250. {
  1251. debugf2("MC: %s: %s()\n", __FILE__, __func__);
  1252. pci_unregister_driver(&i5400_driver);
  1253. }
  1254. module_init(i5400_init);
  1255. module_exit(i5400_exit);
  1256. MODULE_LICENSE("GPL");
  1257. MODULE_AUTHOR("Ben Woodard <woodard@redhat.com>");
  1258. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
  1259. MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
  1260. MODULE_DESCRIPTION("MC Driver for Intel I5400 memory controllers - "
  1261. I5400_REVISION);
  1262. module_param(edac_op_state, int, 0444);
  1263. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");