i5400_edac.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  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
  10. *
  11. * Red Hat Inc. https://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_module.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. /*
  249. * Defines to extract the various fields from the
  250. * MTRx - Memory Technology Registers
  251. */
  252. #define MTR_DIMMS_PRESENT(mtr) ((mtr) & (1 << 10))
  253. #define MTR_DIMMS_ETHROTTLE(mtr) ((mtr) & (1 << 9))
  254. #define MTR_DRAM_WIDTH(mtr) (((mtr) & (1 << 8)) ? 8 : 4)
  255. #define MTR_DRAM_BANKS(mtr) (((mtr) & (1 << 6)) ? 8 : 4)
  256. #define MTR_DRAM_BANKS_ADDR_BITS(mtr) ((MTR_DRAM_BANKS(mtr) == 8) ? 3 : 2)
  257. #define MTR_DIMM_RANK(mtr) (((mtr) >> 5) & 0x1)
  258. #define MTR_DIMM_RANK_ADDR_BITS(mtr) (MTR_DIMM_RANK(mtr) ? 2 : 1)
  259. #define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
  260. #define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
  261. #define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
  262. #define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
  263. /* This applies to FERR_NF_FB-DIMM as well as FERR_FAT_FB-DIMM */
  264. static inline int extract_fbdchan_indx(u32 x)
  265. {
  266. return (x>>28) & 0x3;
  267. }
  268. /* Device name and register DID (Device ID) */
  269. struct i5400_dev_info {
  270. const char *ctl_name; /* name for this device */
  271. u16 fsb_mapping_errors; /* DID for the branchmap,control */
  272. };
  273. /* Table of devices attributes supported by this driver */
  274. static const struct i5400_dev_info i5400_devs[] = {
  275. {
  276. .ctl_name = "I5400",
  277. .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_5400_ERR,
  278. },
  279. };
  280. struct i5400_dimm_info {
  281. int megabytes; /* size, 0 means not present */
  282. };
  283. /* driver private data structure */
  284. struct i5400_pvt {
  285. struct pci_dev *system_address; /* 16.0 */
  286. struct pci_dev *branchmap_werrors; /* 16.1 */
  287. struct pci_dev *fsb_error_regs; /* 16.2 */
  288. struct pci_dev *branch_0; /* 21.0 */
  289. struct pci_dev *branch_1; /* 22.0 */
  290. u16 tolm; /* top of low memory */
  291. union {
  292. u64 ambase; /* AMB BAR */
  293. struct {
  294. u32 ambase_bottom;
  295. u32 ambase_top;
  296. } u __packed;
  297. };
  298. u16 mir0, mir1;
  299. u16 b0_mtr[DIMMS_PER_CHANNEL]; /* Memory Technlogy Reg */
  300. u16 b0_ambpresent0; /* Branch 0, Channel 0 */
  301. u16 b0_ambpresent1; /* Brnach 0, Channel 1 */
  302. u16 b1_mtr[DIMMS_PER_CHANNEL]; /* Memory Technlogy Reg */
  303. u16 b1_ambpresent0; /* Branch 1, Channel 8 */
  304. u16 b1_ambpresent1; /* Branch 1, Channel 1 */
  305. /* DIMM information matrix, allocating architecture maximums */
  306. struct i5400_dimm_info dimm_info[DIMMS_PER_CHANNEL][MAX_CHANNELS];
  307. /* Actual values for this controller */
  308. int maxch; /* Max channels */
  309. int maxdimmperch; /* Max DIMMs per channel */
  310. };
  311. /* I5400 MCH error information retrieved from Hardware */
  312. struct i5400_error_info {
  313. /* These registers are always read from the MC */
  314. u32 ferr_fat_fbd; /* First Errors Fatal */
  315. u32 nerr_fat_fbd; /* Next Errors Fatal */
  316. u32 ferr_nf_fbd; /* First Errors Non-Fatal */
  317. u32 nerr_nf_fbd; /* Next Errors Non-Fatal */
  318. /* These registers are input ONLY if there was a Recoverable Error */
  319. u32 redmemb; /* Recoverable Mem Data Error log B */
  320. u16 recmema; /* Recoverable Mem Error log A */
  321. u32 recmemb; /* Recoverable Mem Error log B */
  322. /* These registers are input ONLY if there was a Non-Rec Error */
  323. u16 nrecmema; /* Non-Recoverable Mem log A */
  324. u32 nrecmemb; /* Non-Recoverable Mem log B */
  325. };
  326. /* note that nrec_rdwr changed from NRECMEMA to NRECMEMB between the 5000 and
  327. 5400 better to use an inline function than a macro in this case */
  328. static inline int nrec_bank(struct i5400_error_info *info)
  329. {
  330. return ((info->nrecmema) >> 12) & 0x7;
  331. }
  332. static inline int nrec_rank(struct i5400_error_info *info)
  333. {
  334. return ((info->nrecmema) >> 8) & 0xf;
  335. }
  336. static inline int nrec_buf_id(struct i5400_error_info *info)
  337. {
  338. return ((info->nrecmema)) & 0xff;
  339. }
  340. static inline int nrec_rdwr(struct i5400_error_info *info)
  341. {
  342. return (info->nrecmemb) >> 31;
  343. }
  344. /* This applies to both NREC and REC string so it can be used with nrec_rdwr
  345. and rec_rdwr */
  346. static inline const char *rdwr_str(int rdwr)
  347. {
  348. return rdwr ? "Write" : "Read";
  349. }
  350. static inline int nrec_cas(struct i5400_error_info *info)
  351. {
  352. return ((info->nrecmemb) >> 16) & 0x1fff;
  353. }
  354. static inline int nrec_ras(struct i5400_error_info *info)
  355. {
  356. return (info->nrecmemb) & 0xffff;
  357. }
  358. static inline int rec_bank(struct i5400_error_info *info)
  359. {
  360. return ((info->recmema) >> 12) & 0x7;
  361. }
  362. static inline int rec_rank(struct i5400_error_info *info)
  363. {
  364. return ((info->recmema) >> 8) & 0xf;
  365. }
  366. static inline int rec_rdwr(struct i5400_error_info *info)
  367. {
  368. return (info->recmemb) >> 31;
  369. }
  370. static inline int rec_cas(struct i5400_error_info *info)
  371. {
  372. return ((info->recmemb) >> 16) & 0x1fff;
  373. }
  374. static inline int rec_ras(struct i5400_error_info *info)
  375. {
  376. return (info->recmemb) & 0xffff;
  377. }
  378. static struct edac_pci_ctl_info *i5400_pci;
  379. /*
  380. * i5400_get_error_info Retrieve the hardware error information from
  381. * the hardware and cache it in the 'info'
  382. * structure
  383. */
  384. static void i5400_get_error_info(struct mem_ctl_info *mci,
  385. struct i5400_error_info *info)
  386. {
  387. struct i5400_pvt *pvt;
  388. u32 value;
  389. pvt = mci->pvt_info;
  390. /* read in the 1st FATAL error register */
  391. pci_read_config_dword(pvt->branchmap_werrors, FERR_FAT_FBD, &value);
  392. /* Mask only the bits that the doc says are valid
  393. */
  394. value &= (FERR_FAT_FBDCHAN | FERR_FAT_MASK);
  395. /* If there is an error, then read in the
  396. NEXT FATAL error register and the Memory Error Log Register A
  397. */
  398. if (value & FERR_FAT_MASK) {
  399. info->ferr_fat_fbd = value;
  400. /* harvest the various error data we need */
  401. pci_read_config_dword(pvt->branchmap_werrors,
  402. NERR_FAT_FBD, &info->nerr_fat_fbd);
  403. pci_read_config_word(pvt->branchmap_werrors,
  404. NRECMEMA, &info->nrecmema);
  405. pci_read_config_dword(pvt->branchmap_werrors,
  406. NRECMEMB, &info->nrecmemb);
  407. /* Clear the error bits, by writing them back */
  408. pci_write_config_dword(pvt->branchmap_werrors,
  409. FERR_FAT_FBD, value);
  410. } else {
  411. info->ferr_fat_fbd = 0;
  412. info->nerr_fat_fbd = 0;
  413. info->nrecmema = 0;
  414. info->nrecmemb = 0;
  415. }
  416. /* read in the 1st NON-FATAL error register */
  417. pci_read_config_dword(pvt->branchmap_werrors, FERR_NF_FBD, &value);
  418. /* If there is an error, then read in the 1st NON-FATAL error
  419. * register as well */
  420. if (value & FERR_NF_MASK) {
  421. info->ferr_nf_fbd = value;
  422. /* harvest the various error data we need */
  423. pci_read_config_dword(pvt->branchmap_werrors,
  424. NERR_NF_FBD, &info->nerr_nf_fbd);
  425. pci_read_config_word(pvt->branchmap_werrors,
  426. RECMEMA, &info->recmema);
  427. pci_read_config_dword(pvt->branchmap_werrors,
  428. RECMEMB, &info->recmemb);
  429. pci_read_config_dword(pvt->branchmap_werrors,
  430. REDMEMB, &info->redmemb);
  431. /* Clear the error bits, by writing them back */
  432. pci_write_config_dword(pvt->branchmap_werrors,
  433. FERR_NF_FBD, value);
  434. } else {
  435. info->ferr_nf_fbd = 0;
  436. info->nerr_nf_fbd = 0;
  437. info->recmema = 0;
  438. info->recmemb = 0;
  439. info->redmemb = 0;
  440. }
  441. }
  442. /*
  443. * i5400_proccess_non_recoverable_info(struct mem_ctl_info *mci,
  444. * struct i5400_error_info *info,
  445. * int handle_errors);
  446. *
  447. * handle the Intel FATAL and unrecoverable errors, if any
  448. */
  449. static void i5400_proccess_non_recoverable_info(struct mem_ctl_info *mci,
  450. struct i5400_error_info *info,
  451. unsigned long allErrors)
  452. {
  453. char msg[EDAC_MC_LABEL_LEN + 1 + 90 + 80];
  454. int branch;
  455. int channel;
  456. int bank;
  457. int buf_id;
  458. int rank;
  459. int rdwr;
  460. int ras, cas;
  461. int errnum;
  462. char *type = NULL;
  463. enum hw_event_mc_err_type tp_event = HW_EVENT_ERR_UNCORRECTED;
  464. if (!allErrors)
  465. return; /* if no error, return now */
  466. if (allErrors & ERROR_FAT_MASK) {
  467. type = "FATAL";
  468. tp_event = HW_EVENT_ERR_FATAL;
  469. } else if (allErrors & FERR_NF_UNCORRECTABLE)
  470. type = "NON-FATAL uncorrected";
  471. else
  472. type = "NON-FATAL recoverable";
  473. /* ONLY ONE of the possible error bits will be set, as per the docs */
  474. branch = extract_fbdchan_indx(info->ferr_fat_fbd);
  475. channel = branch;
  476. /* Use the NON-Recoverable macros to extract data */
  477. bank = nrec_bank(info);
  478. rank = nrec_rank(info);
  479. buf_id = nrec_buf_id(info);
  480. rdwr = nrec_rdwr(info);
  481. ras = nrec_ras(info);
  482. cas = nrec_cas(info);
  483. edac_dbg(0, "\t\t%s DIMM= %d Channels= %d,%d (Branch= %d DRAM Bank= %d Buffer ID = %d rdwr= %s ras= %d cas= %d)\n",
  484. type, rank, channel, channel + 1, branch >> 1, bank,
  485. buf_id, rdwr_str(rdwr), ras, cas);
  486. /* Only 1 bit will be on */
  487. errnum = find_first_bit(&allErrors, ARRAY_SIZE(error_name));
  488. /* Form out message */
  489. snprintf(msg, sizeof(msg),
  490. "Bank=%d Buffer ID = %d RAS=%d CAS=%d Err=0x%lx (%s)",
  491. bank, buf_id, ras, cas, allErrors, error_name[errnum]);
  492. edac_mc_handle_error(tp_event, mci, 1, 0, 0, 0,
  493. branch >> 1, -1, rank,
  494. rdwr ? "Write error" : "Read error",
  495. msg);
  496. }
  497. /*
  498. * i5400_process_fatal_error_info(struct mem_ctl_info *mci,
  499. * struct i5400_error_info *info,
  500. * int handle_errors);
  501. *
  502. * handle the Intel NON-FATAL errors, if any
  503. */
  504. static void i5400_process_nonfatal_error_info(struct mem_ctl_info *mci,
  505. struct i5400_error_info *info)
  506. {
  507. char msg[EDAC_MC_LABEL_LEN + 1 + 90 + 80];
  508. unsigned long allErrors;
  509. int branch;
  510. int channel;
  511. int bank;
  512. int rank;
  513. int rdwr;
  514. int ras, cas;
  515. int errnum;
  516. /* mask off the Error bits that are possible */
  517. allErrors = from_nf_ferr(info->ferr_nf_fbd & FERR_NF_MASK);
  518. if (!allErrors)
  519. return; /* if no error, return now */
  520. /* ONLY ONE of the possible error bits will be set, as per the docs */
  521. if (allErrors & (ERROR_NF_UNCORRECTABLE | ERROR_NF_RECOVERABLE)) {
  522. i5400_proccess_non_recoverable_info(mci, info, allErrors);
  523. return;
  524. }
  525. /* Correctable errors */
  526. if (allErrors & ERROR_NF_CORRECTABLE) {
  527. edac_dbg(0, "\tCorrected bits= 0x%lx\n", allErrors);
  528. branch = extract_fbdchan_indx(info->ferr_nf_fbd);
  529. channel = 0;
  530. if (REC_ECC_LOCATOR_ODD(info->redmemb))
  531. channel = 1;
  532. /* Convert channel to be based from zero, instead of
  533. * from branch base of 0 */
  534. channel += branch;
  535. bank = rec_bank(info);
  536. rank = rec_rank(info);
  537. rdwr = rec_rdwr(info);
  538. ras = rec_ras(info);
  539. cas = rec_cas(info);
  540. /* Only 1 bit will be on */
  541. errnum = find_first_bit(&allErrors, ARRAY_SIZE(error_name));
  542. edac_dbg(0, "\t\tDIMM= %d Channel= %d (Branch %d DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n",
  543. rank, channel, branch >> 1, bank,
  544. rdwr_str(rdwr), ras, cas);
  545. /* Form out message */
  546. snprintf(msg, sizeof(msg),
  547. "Corrected error (Branch=%d DRAM-Bank=%d RDWR=%s "
  548. "RAS=%d CAS=%d, CE Err=0x%lx (%s))",
  549. branch >> 1, bank, rdwr_str(rdwr), ras, cas,
  550. allErrors, error_name[errnum]);
  551. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1, 0, 0, 0,
  552. branch >> 1, channel % 2, rank,
  553. rdwr ? "Write error" : "Read error",
  554. msg);
  555. return;
  556. }
  557. /* Miscellaneous errors */
  558. errnum = find_first_bit(&allErrors, ARRAY_SIZE(error_name));
  559. branch = extract_fbdchan_indx(info->ferr_nf_fbd);
  560. i5400_mc_printk(mci, KERN_EMERG,
  561. "Non-Fatal misc error (Branch=%d Err=%#lx (%s))",
  562. branch >> 1, allErrors, error_name[errnum]);
  563. }
  564. /*
  565. * i5400_process_error_info Process the error info that is
  566. * in the 'info' structure, previously retrieved from hardware
  567. */
  568. static void i5400_process_error_info(struct mem_ctl_info *mci,
  569. struct i5400_error_info *info)
  570. { u32 allErrors;
  571. /* First handle any fatal errors that occurred */
  572. allErrors = (info->ferr_fat_fbd & FERR_FAT_MASK);
  573. i5400_proccess_non_recoverable_info(mci, info, allErrors);
  574. /* now handle any non-fatal errors that occurred */
  575. i5400_process_nonfatal_error_info(mci, info);
  576. }
  577. /*
  578. * i5400_clear_error Retrieve any error from the hardware
  579. * but do NOT process that error.
  580. * Used for 'clearing' out of previous errors
  581. * Called by the Core module.
  582. */
  583. static void i5400_clear_error(struct mem_ctl_info *mci)
  584. {
  585. struct i5400_error_info info;
  586. i5400_get_error_info(mci, &info);
  587. }
  588. /*
  589. * i5400_check_error Retrieve and process errors reported by the
  590. * hardware. Called by the Core module.
  591. */
  592. static void i5400_check_error(struct mem_ctl_info *mci)
  593. {
  594. struct i5400_error_info info;
  595. i5400_get_error_info(mci, &info);
  596. i5400_process_error_info(mci, &info);
  597. }
  598. /*
  599. * i5400_put_devices 'put' all the devices that we have
  600. * reserved via 'get'
  601. */
  602. static void i5400_put_devices(struct mem_ctl_info *mci)
  603. {
  604. struct i5400_pvt *pvt;
  605. pvt = mci->pvt_info;
  606. /* Decrement usage count for devices */
  607. pci_dev_put(pvt->branch_1);
  608. pci_dev_put(pvt->branch_0);
  609. pci_dev_put(pvt->fsb_error_regs);
  610. pci_dev_put(pvt->branchmap_werrors);
  611. }
  612. /*
  613. * i5400_get_devices Find and perform 'get' operation on the MCH's
  614. * device/functions we want to reference for this driver
  615. *
  616. * Need to 'get' device 16 func 1 and func 2
  617. */
  618. static int i5400_get_devices(struct mem_ctl_info *mci, int dev_idx)
  619. {
  620. struct i5400_pvt *pvt;
  621. struct pci_dev *pdev;
  622. pvt = mci->pvt_info;
  623. pvt->branchmap_werrors = NULL;
  624. pvt->fsb_error_regs = NULL;
  625. pvt->branch_0 = NULL;
  626. pvt->branch_1 = NULL;
  627. /* Attempt to 'get' the MCH register we want */
  628. pdev = NULL;
  629. while (1) {
  630. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  631. PCI_DEVICE_ID_INTEL_5400_ERR, pdev);
  632. if (!pdev) {
  633. /* End of list, leave */
  634. i5400_printk(KERN_ERR,
  635. "'system address,Process Bus' "
  636. "device not found:"
  637. "vendor 0x%x device 0x%x ERR func 1 "
  638. "(broken BIOS?)\n",
  639. PCI_VENDOR_ID_INTEL,
  640. PCI_DEVICE_ID_INTEL_5400_ERR);
  641. return -ENODEV;
  642. }
  643. /* Store device 16 func 1 */
  644. if (PCI_FUNC(pdev->devfn) == 1)
  645. break;
  646. }
  647. pvt->branchmap_werrors = pdev;
  648. pdev = NULL;
  649. while (1) {
  650. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  651. PCI_DEVICE_ID_INTEL_5400_ERR, pdev);
  652. if (!pdev) {
  653. /* End of list, leave */
  654. i5400_printk(KERN_ERR,
  655. "'system address,Process Bus' "
  656. "device not found:"
  657. "vendor 0x%x device 0x%x ERR func 2 "
  658. "(broken BIOS?)\n",
  659. PCI_VENDOR_ID_INTEL,
  660. PCI_DEVICE_ID_INTEL_5400_ERR);
  661. pci_dev_put(pvt->branchmap_werrors);
  662. return -ENODEV;
  663. }
  664. /* Store device 16 func 2 */
  665. if (PCI_FUNC(pdev->devfn) == 2)
  666. break;
  667. }
  668. pvt->fsb_error_regs = pdev;
  669. edac_dbg(1, "System Address, processor bus- PCI Bus ID: %s %x:%x\n",
  670. pci_name(pvt->system_address),
  671. pvt->system_address->vendor, pvt->system_address->device);
  672. edac_dbg(1, "Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
  673. pci_name(pvt->branchmap_werrors),
  674. pvt->branchmap_werrors->vendor,
  675. pvt->branchmap_werrors->device);
  676. edac_dbg(1, "FSB Error Regs - PCI Bus ID: %s %x:%x\n",
  677. pci_name(pvt->fsb_error_regs),
  678. pvt->fsb_error_regs->vendor, pvt->fsb_error_regs->device);
  679. pvt->branch_0 = pci_get_device(PCI_VENDOR_ID_INTEL,
  680. PCI_DEVICE_ID_INTEL_5400_FBD0, NULL);
  681. if (!pvt->branch_0) {
  682. i5400_printk(KERN_ERR,
  683. "MC: 'BRANCH 0' device not found:"
  684. "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
  685. PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_FBD0);
  686. pci_dev_put(pvt->fsb_error_regs);
  687. pci_dev_put(pvt->branchmap_werrors);
  688. return -ENODEV;
  689. }
  690. /* If this device claims to have more than 2 channels then
  691. * fetch Branch 1's information
  692. */
  693. if (pvt->maxch < CHANNELS_PER_BRANCH)
  694. return 0;
  695. pvt->branch_1 = pci_get_device(PCI_VENDOR_ID_INTEL,
  696. PCI_DEVICE_ID_INTEL_5400_FBD1, NULL);
  697. if (!pvt->branch_1) {
  698. i5400_printk(KERN_ERR,
  699. "MC: 'BRANCH 1' device not found:"
  700. "vendor 0x%x device 0x%x Func 0 "
  701. "(broken BIOS?)\n",
  702. PCI_VENDOR_ID_INTEL,
  703. PCI_DEVICE_ID_INTEL_5400_FBD1);
  704. pci_dev_put(pvt->branch_0);
  705. pci_dev_put(pvt->fsb_error_regs);
  706. pci_dev_put(pvt->branchmap_werrors);
  707. return -ENODEV;
  708. }
  709. return 0;
  710. }
  711. /*
  712. * determine_amb_present
  713. *
  714. * the information is contained in DIMMS_PER_CHANNEL different
  715. * registers determining which of the DIMMS_PER_CHANNEL requires
  716. * knowing which channel is in question
  717. *
  718. * 2 branches, each with 2 channels
  719. * b0_ambpresent0 for channel '0'
  720. * b0_ambpresent1 for channel '1'
  721. * b1_ambpresent0 for channel '2'
  722. * b1_ambpresent1 for channel '3'
  723. */
  724. static int determine_amb_present_reg(struct i5400_pvt *pvt, int channel)
  725. {
  726. int amb_present;
  727. if (channel < CHANNELS_PER_BRANCH) {
  728. if (channel & 0x1)
  729. amb_present = pvt->b0_ambpresent1;
  730. else
  731. amb_present = pvt->b0_ambpresent0;
  732. } else {
  733. if (channel & 0x1)
  734. amb_present = pvt->b1_ambpresent1;
  735. else
  736. amb_present = pvt->b1_ambpresent0;
  737. }
  738. return amb_present;
  739. }
  740. /*
  741. * determine_mtr(pvt, dimm, channel)
  742. *
  743. * return the proper MTR register as determine by the dimm and desired channel
  744. */
  745. static int determine_mtr(struct i5400_pvt *pvt, int dimm, int channel)
  746. {
  747. int mtr;
  748. int n;
  749. /* There is one MTR for each slot pair of FB-DIMMs,
  750. Each slot pair may be at branch 0 or branch 1.
  751. */
  752. n = dimm;
  753. if (n >= DIMMS_PER_CHANNEL) {
  754. edac_dbg(0, "ERROR: trying to access an invalid dimm: %d\n",
  755. dimm);
  756. return 0;
  757. }
  758. if (channel < CHANNELS_PER_BRANCH)
  759. mtr = pvt->b0_mtr[n];
  760. else
  761. mtr = pvt->b1_mtr[n];
  762. return mtr;
  763. }
  764. /*
  765. */
  766. static void decode_mtr(int slot_row, u16 mtr)
  767. {
  768. int ans;
  769. ans = MTR_DIMMS_PRESENT(mtr);
  770. edac_dbg(2, "\tMTR%d=0x%x: DIMMs are %sPresent\n",
  771. slot_row, mtr, ans ? "" : "NOT ");
  772. if (!ans)
  773. return;
  774. edac_dbg(2, "\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
  775. edac_dbg(2, "\t\tELECTRICAL THROTTLING is %s\n",
  776. MTR_DIMMS_ETHROTTLE(mtr) ? "enabled" : "disabled");
  777. edac_dbg(2, "\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
  778. edac_dbg(2, "\t\tNUMRANK: %s\n",
  779. MTR_DIMM_RANK(mtr) ? "double" : "single");
  780. edac_dbg(2, "\t\tNUMROW: %s\n",
  781. MTR_DIMM_ROWS(mtr) == 0 ? "8,192 - 13 rows" :
  782. MTR_DIMM_ROWS(mtr) == 1 ? "16,384 - 14 rows" :
  783. MTR_DIMM_ROWS(mtr) == 2 ? "32,768 - 15 rows" :
  784. "65,536 - 16 rows");
  785. edac_dbg(2, "\t\tNUMCOL: %s\n",
  786. MTR_DIMM_COLS(mtr) == 0 ? "1,024 - 10 columns" :
  787. MTR_DIMM_COLS(mtr) == 1 ? "2,048 - 11 columns" :
  788. MTR_DIMM_COLS(mtr) == 2 ? "4,096 - 12 columns" :
  789. "reserved");
  790. }
  791. static void handle_channel(struct i5400_pvt *pvt, int dimm, int channel,
  792. struct i5400_dimm_info *dinfo)
  793. {
  794. int mtr;
  795. int amb_present_reg;
  796. int addrBits;
  797. mtr = determine_mtr(pvt, dimm, channel);
  798. if (MTR_DIMMS_PRESENT(mtr)) {
  799. amb_present_reg = determine_amb_present_reg(pvt, channel);
  800. /* Determine if there is a DIMM present in this DIMM slot */
  801. if (amb_present_reg & (1 << dimm)) {
  802. /* Start with the number of bits for a Bank
  803. * on the DRAM */
  804. addrBits = MTR_DRAM_BANKS_ADDR_BITS(mtr);
  805. /* Add thenumber of ROW bits */
  806. addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
  807. /* add the number of COLUMN bits */
  808. addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
  809. /* add the number of RANK bits */
  810. addrBits += MTR_DIMM_RANK(mtr);
  811. addrBits += 6; /* add 64 bits per DIMM */
  812. addrBits -= 20; /* divide by 2^^20 */
  813. addrBits -= 3; /* 8 bits per bytes */
  814. dinfo->megabytes = 1 << addrBits;
  815. }
  816. }
  817. }
  818. /*
  819. * calculate_dimm_size
  820. *
  821. * also will output a DIMM matrix map, if debug is enabled, for viewing
  822. * how the DIMMs are populated
  823. */
  824. static void calculate_dimm_size(struct i5400_pvt *pvt)
  825. {
  826. struct i5400_dimm_info *dinfo;
  827. int dimm, max_dimms;
  828. char *p, *mem_buffer;
  829. int space, n;
  830. int channel, branch;
  831. /* ================= Generate some debug output ================= */
  832. space = PAGE_SIZE;
  833. mem_buffer = p = kmalloc(space, GFP_KERNEL);
  834. if (p == NULL) {
  835. i5400_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
  836. __FILE__, __func__);
  837. return;
  838. }
  839. /* Scan all the actual DIMMS
  840. * and calculate the information for each DIMM
  841. * Start with the highest dimm first, to display it first
  842. * and work toward the 0th dimm
  843. */
  844. max_dimms = pvt->maxdimmperch;
  845. for (dimm = max_dimms - 1; dimm >= 0; dimm--) {
  846. /* on an odd dimm, first output a 'boundary' marker,
  847. * then reset the message buffer */
  848. if (dimm & 0x1) {
  849. n = snprintf(p, space, "---------------------------"
  850. "-------------------------------");
  851. p += n;
  852. space -= n;
  853. edac_dbg(2, "%s\n", mem_buffer);
  854. p = mem_buffer;
  855. space = PAGE_SIZE;
  856. }
  857. n = snprintf(p, space, "dimm %2d ", dimm);
  858. p += n;
  859. space -= n;
  860. for (channel = 0; channel < pvt->maxch; channel++) {
  861. dinfo = &pvt->dimm_info[dimm][channel];
  862. handle_channel(pvt, dimm, channel, dinfo);
  863. n = snprintf(p, space, "%4d MB | ", dinfo->megabytes);
  864. p += n;
  865. space -= n;
  866. }
  867. edac_dbg(2, "%s\n", mem_buffer);
  868. p = mem_buffer;
  869. space = PAGE_SIZE;
  870. }
  871. /* Output the last bottom 'boundary' marker */
  872. n = snprintf(p, space, "---------------------------"
  873. "-------------------------------");
  874. p += n;
  875. space -= n;
  876. edac_dbg(2, "%s\n", mem_buffer);
  877. p = mem_buffer;
  878. space = PAGE_SIZE;
  879. /* now output the 'channel' labels */
  880. n = snprintf(p, space, " ");
  881. p += n;
  882. space -= n;
  883. for (channel = 0; channel < pvt->maxch; channel++) {
  884. n = snprintf(p, space, "channel %d | ", channel);
  885. p += n;
  886. space -= n;
  887. }
  888. space -= n;
  889. edac_dbg(2, "%s\n", mem_buffer);
  890. p = mem_buffer;
  891. space = PAGE_SIZE;
  892. n = snprintf(p, space, " ");
  893. p += n;
  894. for (branch = 0; branch < MAX_BRANCHES; branch++) {
  895. n = snprintf(p, space, " branch %d | ", branch);
  896. p += n;
  897. space -= n;
  898. }
  899. /* output the last message and free buffer */
  900. edac_dbg(2, "%s\n", mem_buffer);
  901. kfree(mem_buffer);
  902. }
  903. /*
  904. * i5400_get_mc_regs read in the necessary registers and
  905. * cache locally
  906. *
  907. * Fills in the private data members
  908. */
  909. static void i5400_get_mc_regs(struct mem_ctl_info *mci)
  910. {
  911. struct i5400_pvt *pvt;
  912. u32 actual_tolm;
  913. u16 limit;
  914. int slot_row;
  915. int way0, way1;
  916. pvt = mci->pvt_info;
  917. pci_read_config_dword(pvt->system_address, AMBASE,
  918. &pvt->u.ambase_bottom);
  919. pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
  920. &pvt->u.ambase_top);
  921. edac_dbg(2, "AMBASE= 0x%lx MAXCH= %d MAX-DIMM-Per-CH= %d\n",
  922. (long unsigned int)pvt->ambase, pvt->maxch, pvt->maxdimmperch);
  923. /* Get the Branch Map regs */
  924. pci_read_config_word(pvt->branchmap_werrors, TOLM, &pvt->tolm);
  925. pvt->tolm >>= 12;
  926. edac_dbg(2, "\nTOLM (number of 256M regions) =%u (0x%x)\n",
  927. pvt->tolm, pvt->tolm);
  928. actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28));
  929. edac_dbg(2, "Actual TOLM byte addr=%u.%03u GB (0x%x)\n",
  930. actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28);
  931. pci_read_config_word(pvt->branchmap_werrors, MIR0, &pvt->mir0);
  932. pci_read_config_word(pvt->branchmap_werrors, MIR1, &pvt->mir1);
  933. /* Get the MIR[0-1] regs */
  934. limit = (pvt->mir0 >> 4) & 0x0fff;
  935. way0 = pvt->mir0 & 0x1;
  936. way1 = pvt->mir0 & 0x2;
  937. edac_dbg(2, "MIR0: limit= 0x%x WAY1= %u WAY0= %x\n",
  938. limit, way1, way0);
  939. limit = (pvt->mir1 >> 4) & 0xfff;
  940. way0 = pvt->mir1 & 0x1;
  941. way1 = pvt->mir1 & 0x2;
  942. edac_dbg(2, "MIR1: limit= 0x%x WAY1= %u WAY0= %x\n",
  943. limit, way1, way0);
  944. /* Get the set of MTR[0-3] regs by each branch */
  945. for (slot_row = 0; slot_row < DIMMS_PER_CHANNEL; slot_row++) {
  946. int where = MTR0 + (slot_row * sizeof(u16));
  947. /* Branch 0 set of MTR registers */
  948. pci_read_config_word(pvt->branch_0, where,
  949. &pvt->b0_mtr[slot_row]);
  950. edac_dbg(2, "MTR%d where=0x%x B0 value=0x%x\n",
  951. slot_row, where, pvt->b0_mtr[slot_row]);
  952. if (pvt->maxch < CHANNELS_PER_BRANCH) {
  953. pvt->b1_mtr[slot_row] = 0;
  954. continue;
  955. }
  956. /* Branch 1 set of MTR registers */
  957. pci_read_config_word(pvt->branch_1, where,
  958. &pvt->b1_mtr[slot_row]);
  959. edac_dbg(2, "MTR%d where=0x%x B1 value=0x%x\n",
  960. slot_row, where, pvt->b1_mtr[slot_row]);
  961. }
  962. /* Read and dump branch 0's MTRs */
  963. edac_dbg(2, "Memory Technology Registers:\n");
  964. edac_dbg(2, " Branch 0:\n");
  965. for (slot_row = 0; slot_row < DIMMS_PER_CHANNEL; slot_row++)
  966. decode_mtr(slot_row, pvt->b0_mtr[slot_row]);
  967. pci_read_config_word(pvt->branch_0, AMBPRESENT_0,
  968. &pvt->b0_ambpresent0);
  969. edac_dbg(2, "\t\tAMB-Branch 0-present0 0x%x:\n", pvt->b0_ambpresent0);
  970. pci_read_config_word(pvt->branch_0, AMBPRESENT_1,
  971. &pvt->b0_ambpresent1);
  972. edac_dbg(2, "\t\tAMB-Branch 0-present1 0x%x:\n", pvt->b0_ambpresent1);
  973. /* Only if we have 2 branchs (4 channels) */
  974. if (pvt->maxch < CHANNELS_PER_BRANCH) {
  975. pvt->b1_ambpresent0 = 0;
  976. pvt->b1_ambpresent1 = 0;
  977. } else {
  978. /* Read and dump branch 1's MTRs */
  979. edac_dbg(2, " Branch 1:\n");
  980. for (slot_row = 0; slot_row < DIMMS_PER_CHANNEL; slot_row++)
  981. decode_mtr(slot_row, pvt->b1_mtr[slot_row]);
  982. pci_read_config_word(pvt->branch_1, AMBPRESENT_0,
  983. &pvt->b1_ambpresent0);
  984. edac_dbg(2, "\t\tAMB-Branch 1-present0 0x%x:\n",
  985. pvt->b1_ambpresent0);
  986. pci_read_config_word(pvt->branch_1, AMBPRESENT_1,
  987. &pvt->b1_ambpresent1);
  988. edac_dbg(2, "\t\tAMB-Branch 1-present1 0x%x:\n",
  989. pvt->b1_ambpresent1);
  990. }
  991. /* Go and determine the size of each DIMM and place in an
  992. * orderly matrix */
  993. calculate_dimm_size(pvt);
  994. }
  995. /*
  996. * i5400_init_dimms Initialize the 'dimms' table within
  997. * the mci control structure with the
  998. * addressing of memory.
  999. *
  1000. * return:
  1001. * 0 success
  1002. * 1 no actual memory found on this MC
  1003. */
  1004. static int i5400_init_dimms(struct mem_ctl_info *mci)
  1005. {
  1006. struct i5400_pvt *pvt;
  1007. struct dimm_info *dimm;
  1008. int ndimms;
  1009. int mtr;
  1010. int size_mb;
  1011. int channel, slot;
  1012. pvt = mci->pvt_info;
  1013. ndimms = 0;
  1014. /*
  1015. * FIXME: remove pvt->dimm_info[slot][channel] and use the 3
  1016. * layers here.
  1017. */
  1018. for (channel = 0; channel < mci->layers[0].size * mci->layers[1].size;
  1019. channel++) {
  1020. for (slot = 0; slot < mci->layers[2].size; slot++) {
  1021. mtr = determine_mtr(pvt, slot, channel);
  1022. /* if no DIMMS on this slot, continue */
  1023. if (!MTR_DIMMS_PRESENT(mtr))
  1024. continue;
  1025. dimm = edac_get_dimm(mci, channel / 2, channel % 2, slot);
  1026. size_mb = pvt->dimm_info[slot][channel].megabytes;
  1027. edac_dbg(2, "dimm (branch %d channel %d slot %d): %d.%03d GB\n",
  1028. channel / 2, channel % 2, slot,
  1029. size_mb / 1000, size_mb % 1000);
  1030. dimm->nr_pages = size_mb << 8;
  1031. dimm->grain = 8;
  1032. dimm->dtype = MTR_DRAM_WIDTH(mtr) == 8 ?
  1033. DEV_X8 : DEV_X4;
  1034. dimm->mtype = MEM_FB_DDR2;
  1035. /*
  1036. * The eccc mechanism is SDDC (aka SECC), with
  1037. * is similar to Chipkill.
  1038. */
  1039. dimm->edac_mode = MTR_DRAM_WIDTH(mtr) == 8 ?
  1040. EDAC_S8ECD8ED : EDAC_S4ECD4ED;
  1041. ndimms++;
  1042. }
  1043. }
  1044. /*
  1045. * When just one memory is provided, it should be at location (0,0,0).
  1046. * With such single-DIMM mode, the SDCC algorithm degrades to SECDEC+.
  1047. */
  1048. if (ndimms == 1)
  1049. mci->dimms[0]->edac_mode = EDAC_SECDED;
  1050. return (ndimms == 0);
  1051. }
  1052. /*
  1053. * i5400_enable_error_reporting
  1054. * Turn on the memory reporting features of the hardware
  1055. */
  1056. static void i5400_enable_error_reporting(struct mem_ctl_info *mci)
  1057. {
  1058. struct i5400_pvt *pvt;
  1059. u32 fbd_error_mask;
  1060. pvt = mci->pvt_info;
  1061. /* Read the FBD Error Mask Register */
  1062. pci_read_config_dword(pvt->branchmap_werrors, EMASK_FBD,
  1063. &fbd_error_mask);
  1064. /* Enable with a '0' */
  1065. fbd_error_mask &= ~(ENABLE_EMASK_ALL);
  1066. pci_write_config_dword(pvt->branchmap_werrors, EMASK_FBD,
  1067. fbd_error_mask);
  1068. }
  1069. /*
  1070. * i5400_probe1 Probe for ONE instance of device to see if it is
  1071. * present.
  1072. * return:
  1073. * 0 for FOUND a device
  1074. * < 0 for error code
  1075. */
  1076. static int i5400_probe1(struct pci_dev *pdev, int dev_idx)
  1077. {
  1078. struct mem_ctl_info *mci;
  1079. struct i5400_pvt *pvt;
  1080. struct edac_mc_layer layers[3];
  1081. if (dev_idx >= ARRAY_SIZE(i5400_devs))
  1082. return -EINVAL;
  1083. edac_dbg(0, "MC: pdev bus %u dev=0x%x fn=0x%x\n",
  1084. pdev->bus->number,
  1085. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  1086. /* We only are looking for func 0 of the set */
  1087. if (PCI_FUNC(pdev->devfn) != 0)
  1088. return -ENODEV;
  1089. /*
  1090. * allocate a new MC control structure
  1091. *
  1092. * This drivers uses the DIMM slot as "csrow" and the rest as "channel".
  1093. */
  1094. layers[0].type = EDAC_MC_LAYER_BRANCH;
  1095. layers[0].size = MAX_BRANCHES;
  1096. layers[0].is_virt_csrow = false;
  1097. layers[1].type = EDAC_MC_LAYER_CHANNEL;
  1098. layers[1].size = CHANNELS_PER_BRANCH;
  1099. layers[1].is_virt_csrow = false;
  1100. layers[2].type = EDAC_MC_LAYER_SLOT;
  1101. layers[2].size = DIMMS_PER_CHANNEL;
  1102. layers[2].is_virt_csrow = true;
  1103. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
  1104. if (mci == NULL)
  1105. return -ENOMEM;
  1106. edac_dbg(0, "MC: mci = %p\n", mci);
  1107. mci->pdev = &pdev->dev; /* record ptr to the generic device */
  1108. pvt = mci->pvt_info;
  1109. pvt->system_address = pdev; /* Record this device in our private */
  1110. pvt->maxch = MAX_CHANNELS;
  1111. pvt->maxdimmperch = DIMMS_PER_CHANNEL;
  1112. /* 'get' the pci devices we want to reserve for our use */
  1113. if (i5400_get_devices(mci, dev_idx))
  1114. goto fail0;
  1115. /* Time to get serious */
  1116. i5400_get_mc_regs(mci); /* retrieve the hardware registers */
  1117. mci->mc_idx = 0;
  1118. mci->mtype_cap = MEM_FLAG_FB_DDR2;
  1119. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  1120. mci->edac_cap = EDAC_FLAG_NONE;
  1121. mci->mod_name = "i5400_edac.c";
  1122. mci->ctl_name = i5400_devs[dev_idx].ctl_name;
  1123. mci->dev_name = pci_name(pdev);
  1124. mci->ctl_page_to_phys = NULL;
  1125. /* Set the function pointer to an actual operation function */
  1126. mci->edac_check = i5400_check_error;
  1127. /* initialize the MC control structure 'dimms' table
  1128. * with the mapping and control information */
  1129. if (i5400_init_dimms(mci)) {
  1130. edac_dbg(0, "MC: Setting mci->edac_cap to EDAC_FLAG_NONE because i5400_init_dimms() returned nonzero value\n");
  1131. mci->edac_cap = EDAC_FLAG_NONE; /* no dimms found */
  1132. } else {
  1133. edac_dbg(1, "MC: Enable error reporting now\n");
  1134. i5400_enable_error_reporting(mci);
  1135. }
  1136. /* add this new MC control structure to EDAC's list of MCs */
  1137. if (edac_mc_add_mc(mci)) {
  1138. edac_dbg(0, "MC: failed edac_mc_add_mc()\n");
  1139. /* FIXME: perhaps some code should go here that disables error
  1140. * reporting if we just enabled it
  1141. */
  1142. goto fail1;
  1143. }
  1144. i5400_clear_error(mci);
  1145. /* allocating generic PCI control info */
  1146. i5400_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  1147. if (!i5400_pci) {
  1148. printk(KERN_WARNING
  1149. "%s(): Unable to create PCI control\n",
  1150. __func__);
  1151. printk(KERN_WARNING
  1152. "%s(): PCI error report via EDAC not setup\n",
  1153. __func__);
  1154. }
  1155. return 0;
  1156. /* Error exit unwinding stack */
  1157. fail1:
  1158. i5400_put_devices(mci);
  1159. fail0:
  1160. edac_mc_free(mci);
  1161. return -ENODEV;
  1162. }
  1163. /*
  1164. * i5400_init_one constructor for one instance of device
  1165. *
  1166. * returns:
  1167. * negative on error
  1168. * count (>= 0)
  1169. */
  1170. static int i5400_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  1171. {
  1172. int rc;
  1173. edac_dbg(0, "MC:\n");
  1174. /* wake up device */
  1175. rc = pci_enable_device(pdev);
  1176. if (rc)
  1177. return rc;
  1178. /* now probe and enable the device */
  1179. return i5400_probe1(pdev, id->driver_data);
  1180. }
  1181. /*
  1182. * i5400_remove_one destructor for one instance of device
  1183. *
  1184. */
  1185. static void i5400_remove_one(struct pci_dev *pdev)
  1186. {
  1187. struct mem_ctl_info *mci;
  1188. edac_dbg(0, "\n");
  1189. if (i5400_pci)
  1190. edac_pci_release_generic_ctl(i5400_pci);
  1191. mci = edac_mc_del_mc(&pdev->dev);
  1192. if (!mci)
  1193. return;
  1194. /* retrieve references to resources, and free those resources */
  1195. i5400_put_devices(mci);
  1196. pci_disable_device(pdev);
  1197. edac_mc_free(mci);
  1198. }
  1199. /*
  1200. * pci_device_id table for which devices we are looking for
  1201. *
  1202. * The "E500P" device is the first device supported.
  1203. */
  1204. static const struct pci_device_id i5400_pci_tbl[] = {
  1205. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
  1206. {0,} /* 0 terminated list. */
  1207. };
  1208. MODULE_DEVICE_TABLE(pci, i5400_pci_tbl);
  1209. /*
  1210. * i5400_driver pci_driver structure for this module
  1211. *
  1212. */
  1213. static struct pci_driver i5400_driver = {
  1214. .name = "i5400_edac",
  1215. .probe = i5400_init_one,
  1216. .remove = i5400_remove_one,
  1217. .id_table = i5400_pci_tbl,
  1218. };
  1219. /*
  1220. * i5400_init Module entry function
  1221. * Try to initialize this module for its devices
  1222. */
  1223. static int __init i5400_init(void)
  1224. {
  1225. int pci_rc;
  1226. edac_dbg(2, "MC:\n");
  1227. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1228. opstate_init();
  1229. pci_rc = pci_register_driver(&i5400_driver);
  1230. return (pci_rc < 0) ? pci_rc : 0;
  1231. }
  1232. /*
  1233. * i5400_exit() Module exit function
  1234. * Unregister the driver
  1235. */
  1236. static void __exit i5400_exit(void)
  1237. {
  1238. edac_dbg(2, "MC:\n");
  1239. pci_unregister_driver(&i5400_driver);
  1240. }
  1241. module_init(i5400_init);
  1242. module_exit(i5400_exit);
  1243. MODULE_LICENSE("GPL");
  1244. MODULE_AUTHOR("Ben Woodard <woodard@redhat.com>");
  1245. MODULE_AUTHOR("Mauro Carvalho Chehab");
  1246. MODULE_AUTHOR("Red Hat Inc. (https://www.redhat.com)");
  1247. MODULE_DESCRIPTION("MC Driver for Intel I5400 memory controllers - "
  1248. I5400_REVISION);
  1249. module_param(edac_op_state, int, 0444);
  1250. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");