i5400_edac.c 40 KB

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