i7300_edac.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. /*
  2. * Intel 7300 class Memory Controllers kernel module (Clarksboro)
  3. *
  4. * This file may be distributed under the terms of the
  5. * GNU General Public License version 2 only.
  6. *
  7. * Copyright (c) 2010 by:
  8. * Mauro Carvalho Chehab <mchehab@redhat.com>
  9. *
  10. * Red Hat Inc. http://www.redhat.com
  11. *
  12. * Intel 7300 Chipset Memory Controller Hub (MCH) - Datasheet
  13. * http://www.intel.com/Assets/PDF/datasheet/318082.pdf
  14. *
  15. * TODO: The chipset allow checking for PCI Express errors also. Currently,
  16. * the driver covers only memory error errors
  17. *
  18. * This driver uses "csrows" EDAC attribute to represent DIMM slot#
  19. */
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/pci.h>
  23. #include <linux/pci_ids.h>
  24. #include <linux/slab.h>
  25. #include <linux/edac.h>
  26. #include <linux/mmzone.h>
  27. #include "edac_core.h"
  28. /*
  29. * Alter this version for the I7300 module when modifications are made
  30. */
  31. #define I7300_REVISION " Ver: 1.0.0"
  32. #define EDAC_MOD_STR "i7300_edac"
  33. #define i7300_printk(level, fmt, arg...) \
  34. edac_printk(level, "i7300", fmt, ##arg)
  35. #define i7300_mc_printk(mci, level, fmt, arg...) \
  36. edac_mc_chipset_printk(mci, level, "i7300", fmt, ##arg)
  37. /***********************************************
  38. * i7300 Limit constants Structs and static vars
  39. ***********************************************/
  40. /*
  41. * Memory topology is organized as:
  42. * Branch 0 - 2 channels: channels 0 and 1 (FDB0 PCI dev 21.0)
  43. * Branch 1 - 2 channels: channels 2 and 3 (FDB1 PCI dev 22.0)
  44. * Each channel can have to 8 DIMM sets (called as SLOTS)
  45. * Slots should generally be filled in pairs
  46. * Except on Single Channel mode of operation
  47. * just slot 0/channel0 filled on this mode
  48. * On normal operation mode, the two channels on a branch should be
  49. * filled together for the same SLOT#
  50. * When in mirrored mode, Branch 1 replicate memory at Branch 0, so, the four
  51. * channels on both branches should be filled
  52. */
  53. /* Limits for i7300 */
  54. #define MAX_SLOTS 8
  55. #define MAX_BRANCHES 2
  56. #define MAX_CH_PER_BRANCH 2
  57. #define MAX_CHANNELS (MAX_CH_PER_BRANCH * MAX_BRANCHES)
  58. #define MAX_MIR 3
  59. #define to_channel(ch, branch) ((((branch)) << 1) | (ch))
  60. #define to_csrow(slot, ch, branch) \
  61. (to_channel(ch, branch) | ((slot) << 2))
  62. /* Device name and register DID (Device ID) */
  63. struct i7300_dev_info {
  64. const char *ctl_name; /* name for this device */
  65. u16 fsb_mapping_errors; /* DID for the branchmap,control */
  66. };
  67. /* Table of devices attributes supported by this driver */
  68. static const struct i7300_dev_info i7300_devs[] = {
  69. {
  70. .ctl_name = "I7300",
  71. .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I7300_MCH_ERR,
  72. },
  73. };
  74. struct i7300_dimm_info {
  75. int megabytes; /* size, 0 means not present */
  76. };
  77. /* driver private data structure */
  78. struct i7300_pvt {
  79. struct pci_dev *pci_dev_16_0_fsb_ctlr; /* 16.0 */
  80. struct pci_dev *pci_dev_16_1_fsb_addr_map; /* 16.1 */
  81. struct pci_dev *pci_dev_16_2_fsb_err_regs; /* 16.2 */
  82. struct pci_dev *pci_dev_2x_0_fbd_branch[MAX_BRANCHES]; /* 21.0 and 22.0 */
  83. u16 tolm; /* top of low memory */
  84. u64 ambase; /* AMB BAR */
  85. u32 mc_settings; /* Report several settings */
  86. u32 mc_settings_a;
  87. u16 mir[MAX_MIR]; /* Memory Interleave Reg*/
  88. u16 mtr[MAX_SLOTS][MAX_BRANCHES]; /* Memory Technlogy Reg */
  89. u16 ambpresent[MAX_CHANNELS]; /* AMB present regs */
  90. /* DIMM information matrix, allocating architecture maximums */
  91. struct i7300_dimm_info dimm_info[MAX_SLOTS][MAX_CHANNELS];
  92. /* Temporary buffer for use when preparing error messages */
  93. char *tmp_prt_buffer;
  94. };
  95. /* FIXME: Why do we need to have this static? */
  96. static struct edac_pci_ctl_info *i7300_pci;
  97. /***************************************************
  98. * i7300 Register definitions for memory enumeration
  99. ***************************************************/
  100. /*
  101. * Device 16,
  102. * Function 0: System Address (not documented)
  103. * Function 1: Memory Branch Map, Control, Errors Register
  104. */
  105. /* OFFSETS for Function 0 */
  106. #define AMBASE 0x48 /* AMB Mem Mapped Reg Region Base */
  107. #define MAXCH 0x56 /* Max Channel Number */
  108. #define MAXDIMMPERCH 0x57 /* Max DIMM PER Channel Number */
  109. /* OFFSETS for Function 1 */
  110. #define MC_SETTINGS 0x40
  111. #define IS_MIRRORED(mc) ((mc) & (1 << 16))
  112. #define IS_ECC_ENABLED(mc) ((mc) & (1 << 5))
  113. #define IS_RETRY_ENABLED(mc) ((mc) & (1 << 31))
  114. #define IS_SCRBALGO_ENHANCED(mc) ((mc) & (1 << 8))
  115. #define MC_SETTINGS_A 0x58
  116. #define IS_SINGLE_MODE(mca) ((mca) & (1 << 14))
  117. #define TOLM 0x6C
  118. #define MIR0 0x80
  119. #define MIR1 0x84
  120. #define MIR2 0x88
  121. /*
  122. * Note: Other Intel EDAC drivers use AMBPRESENT to identify if the available
  123. * memory. From datasheet item 7.3.1 (FB-DIMM technology & organization), it
  124. * seems that we cannot use this information directly for the same usage.
  125. * Each memory slot may have up to 2 AMB interfaces, one for income and another
  126. * for outcome interface to the next slot.
  127. * For now, the driver just stores the AMB present registers, but rely only at
  128. * the MTR info to detect memory.
  129. * Datasheet is also not clear about how to map each AMBPRESENT registers to
  130. * one of the 4 available channels.
  131. */
  132. #define AMBPRESENT_0 0x64
  133. #define AMBPRESENT_1 0x66
  134. static const u16 mtr_regs[MAX_SLOTS] = {
  135. 0x80, 0x84, 0x88, 0x8c,
  136. 0x82, 0x86, 0x8a, 0x8e
  137. };
  138. /*
  139. * Defines to extract the vaious fields from the
  140. * MTRx - Memory Technology Registers
  141. */
  142. #define MTR_DIMMS_PRESENT(mtr) ((mtr) & (1 << 8))
  143. #define MTR_DIMMS_ETHROTTLE(mtr) ((mtr) & (1 << 7))
  144. #define MTR_DRAM_WIDTH(mtr) (((mtr) & (1 << 6)) ? 8 : 4)
  145. #define MTR_DRAM_BANKS(mtr) (((mtr) & (1 << 5)) ? 8 : 4)
  146. #define MTR_DIMM_RANKS(mtr) (((mtr) & (1 << 4)) ? 1 : 0)
  147. #define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
  148. #define MTR_DRAM_BANKS_ADDR_BITS 2
  149. #define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
  150. #define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
  151. #define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
  152. #ifdef CONFIG_EDAC_DEBUG
  153. /* MTR NUMROW */
  154. static const char *numrow_toString[] = {
  155. "8,192 - 13 rows",
  156. "16,384 - 14 rows",
  157. "32,768 - 15 rows",
  158. "65,536 - 16 rows"
  159. };
  160. /* MTR NUMCOL */
  161. static const char *numcol_toString[] = {
  162. "1,024 - 10 columns",
  163. "2,048 - 11 columns",
  164. "4,096 - 12 columns",
  165. "reserved"
  166. };
  167. #endif
  168. /************************************************
  169. * i7300 Register definitions for error detection
  170. ************************************************/
  171. /*
  172. * Device 16.1: FBD Error Registers
  173. */
  174. #define FERR_FAT_FBD 0x98
  175. static const char *ferr_fat_fbd_name[] = {
  176. [22] = "Non-Redundant Fast Reset Timeout",
  177. [2] = ">Tmid Thermal event with intelligent throttling disabled",
  178. [1] = "Memory or FBD configuration CRC read error",
  179. [0] = "Memory Write error on non-redundant retry or "
  180. "FBD configuration Write error on retry",
  181. };
  182. #define GET_FBD_FAT_IDX(fbderr) (fbderr & (3 << 28))
  183. #define FERR_FAT_FBD_ERR_MASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
  184. #define FERR_NF_FBD 0xa0
  185. static const char *ferr_nf_fbd_name[] = {
  186. [24] = "DIMM-Spare Copy Completed",
  187. [23] = "DIMM-Spare Copy Initiated",
  188. [22] = "Redundant Fast Reset Timeout",
  189. [21] = "Memory Write error on redundant retry",
  190. [18] = "SPD protocol Error",
  191. [17] = "FBD Northbound parity error on FBD Sync Status",
  192. [16] = "Correctable Patrol Data ECC",
  193. [15] = "Correctable Resilver- or Spare-Copy Data ECC",
  194. [14] = "Correctable Mirrored Demand Data ECC",
  195. [13] = "Correctable Non-Mirrored Demand Data ECC",
  196. [11] = "Memory or FBD configuration CRC read error",
  197. [10] = "FBD Configuration Write error on first attempt",
  198. [9] = "Memory Write error on first attempt",
  199. [8] = "Non-Aliased Uncorrectable Patrol Data ECC",
  200. [7] = "Non-Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
  201. [6] = "Non-Aliased Uncorrectable Mirrored Demand Data ECC",
  202. [5] = "Non-Aliased Uncorrectable Non-Mirrored Demand Data ECC",
  203. [4] = "Aliased Uncorrectable Patrol Data ECC",
  204. [3] = "Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
  205. [2] = "Aliased Uncorrectable Mirrored Demand Data ECC",
  206. [1] = "Aliased Uncorrectable Non-Mirrored Demand Data ECC",
  207. [0] = "Uncorrectable Data ECC on Replay",
  208. };
  209. #define GET_FBD_NF_IDX(fbderr) (fbderr & (3 << 28))
  210. #define FERR_NF_FBD_ERR_MASK ((1 << 24) | (1 << 23) | (1 << 22) | (1 << 21) |\
  211. (1 << 18) | (1 << 17) | (1 << 16) | (1 << 15) |\
  212. (1 << 14) | (1 << 13) | (1 << 11) | (1 << 10) |\
  213. (1 << 9) | (1 << 8) | (1 << 7) | (1 << 6) |\
  214. (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) |\
  215. (1 << 1) | (1 << 0))
  216. #define EMASK_FBD 0xa8
  217. #define EMASK_FBD_ERR_MASK ((1 << 27) | (1 << 26) | (1 << 25) | (1 << 24) |\
  218. (1 << 22) | (1 << 21) | (1 << 20) | (1 << 19) |\
  219. (1 << 18) | (1 << 17) | (1 << 16) | (1 << 14) |\
  220. (1 << 13) | (1 << 12) | (1 << 11) | (1 << 10) |\
  221. (1 << 9) | (1 << 8) | (1 << 7) | (1 << 6) |\
  222. (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) |\
  223. (1 << 1) | (1 << 0))
  224. /*
  225. * Device 16.2: Global Error Registers
  226. */
  227. #define FERR_GLOBAL_HI 0x48
  228. static const char *ferr_global_hi_name[] = {
  229. [3] = "FSB 3 Fatal Error",
  230. [2] = "FSB 2 Fatal Error",
  231. [1] = "FSB 1 Fatal Error",
  232. [0] = "FSB 0 Fatal Error",
  233. };
  234. #define ferr_global_hi_is_fatal(errno) 1
  235. #define FERR_GLOBAL_LO 0x40
  236. static const char *ferr_global_lo_name[] = {
  237. [31] = "Internal MCH Fatal Error",
  238. [30] = "Intel QuickData Technology Device Fatal Error",
  239. [29] = "FSB1 Fatal Error",
  240. [28] = "FSB0 Fatal Error",
  241. [27] = "FBD Channel 3 Fatal Error",
  242. [26] = "FBD Channel 2 Fatal Error",
  243. [25] = "FBD Channel 1 Fatal Error",
  244. [24] = "FBD Channel 0 Fatal Error",
  245. [23] = "PCI Express Device 7Fatal Error",
  246. [22] = "PCI Express Device 6 Fatal Error",
  247. [21] = "PCI Express Device 5 Fatal Error",
  248. [20] = "PCI Express Device 4 Fatal Error",
  249. [19] = "PCI Express Device 3 Fatal Error",
  250. [18] = "PCI Express Device 2 Fatal Error",
  251. [17] = "PCI Express Device 1 Fatal Error",
  252. [16] = "ESI Fatal Error",
  253. [15] = "Internal MCH Non-Fatal Error",
  254. [14] = "Intel QuickData Technology Device Non Fatal Error",
  255. [13] = "FSB1 Non-Fatal Error",
  256. [12] = "FSB 0 Non-Fatal Error",
  257. [11] = "FBD Channel 3 Non-Fatal Error",
  258. [10] = "FBD Channel 2 Non-Fatal Error",
  259. [9] = "FBD Channel 1 Non-Fatal Error",
  260. [8] = "FBD Channel 0 Non-Fatal Error",
  261. [7] = "PCI Express Device 7 Non-Fatal Error",
  262. [6] = "PCI Express Device 6 Non-Fatal Error",
  263. [5] = "PCI Express Device 5 Non-Fatal Error",
  264. [4] = "PCI Express Device 4 Non-Fatal Error",
  265. [3] = "PCI Express Device 3 Non-Fatal Error",
  266. [2] = "PCI Express Device 2 Non-Fatal Error",
  267. [1] = "PCI Express Device 1 Non-Fatal Error",
  268. [0] = "ESI Non-Fatal Error",
  269. };
  270. #define ferr_global_lo_is_fatal(errno) ((errno < 16) ? 0 : 1)
  271. #define NRECMEMA 0xbe
  272. #define NRECMEMA_BANK(v) (((v) >> 12) & 7)
  273. #define NRECMEMA_RANK(v) (((v) >> 8) & 15)
  274. #define NRECMEMB 0xc0
  275. #define NRECMEMB_IS_WR(v) ((v) & (1 << 31))
  276. #define NRECMEMB_CAS(v) (((v) >> 16) & 0x1fff)
  277. #define NRECMEMB_RAS(v) ((v) & 0xffff)
  278. #define REDMEMA 0xdc
  279. #define REDMEMB 0x7c
  280. #define IS_SECOND_CH(v) ((v) * (1 << 17))
  281. #define RECMEMA 0xe0
  282. #define RECMEMA_BANK(v) (((v) >> 12) & 7)
  283. #define RECMEMA_RANK(v) (((v) >> 8) & 15)
  284. #define RECMEMB 0xe4
  285. #define RECMEMB_IS_WR(v) ((v) & (1 << 31))
  286. #define RECMEMB_CAS(v) (((v) >> 16) & 0x1fff)
  287. #define RECMEMB_RAS(v) ((v) & 0xffff)
  288. /********************************************
  289. * i7300 Functions related to error detection
  290. ********************************************/
  291. /**
  292. * get_err_from_table() - Gets the error message from a table
  293. * @table: table name (array of char *)
  294. * @size: number of elements at the table
  295. * @pos: position of the element to be returned
  296. *
  297. * This is a small routine that gets the pos-th element of a table. If the
  298. * element doesn't exist (or it is empty), it returns "reserved".
  299. * Instead of calling it directly, the better is to call via the macro
  300. * GET_ERR_FROM_TABLE(), that automatically checks the table size via
  301. * ARRAY_SIZE() macro
  302. */
  303. static const char *get_err_from_table(const char *table[], int size, int pos)
  304. {
  305. if (unlikely(pos >= size))
  306. return "Reserved";
  307. if (unlikely(!table[pos]))
  308. return "Reserved";
  309. return table[pos];
  310. }
  311. #define GET_ERR_FROM_TABLE(table, pos) \
  312. get_err_from_table(table, ARRAY_SIZE(table), pos)
  313. /**
  314. * i7300_process_error_global() - Retrieve the hardware error information from
  315. * the hardware global error registers and
  316. * sends it to dmesg
  317. * @mci: struct mem_ctl_info pointer
  318. */
  319. static void i7300_process_error_global(struct mem_ctl_info *mci)
  320. {
  321. struct i7300_pvt *pvt;
  322. u32 errnum, error_reg;
  323. unsigned long errors;
  324. const char *specific;
  325. bool is_fatal;
  326. pvt = mci->pvt_info;
  327. /* read in the 1st FATAL error register */
  328. pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  329. FERR_GLOBAL_HI, &error_reg);
  330. if (unlikely(error_reg)) {
  331. errors = error_reg;
  332. errnum = find_first_bit(&errors,
  333. ARRAY_SIZE(ferr_global_hi_name));
  334. specific = GET_ERR_FROM_TABLE(ferr_global_hi_name, errnum);
  335. is_fatal = ferr_global_hi_is_fatal(errnum);
  336. /* Clear the error bit */
  337. pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  338. FERR_GLOBAL_HI, error_reg);
  339. goto error_global;
  340. }
  341. pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  342. FERR_GLOBAL_LO, &error_reg);
  343. if (unlikely(error_reg)) {
  344. errors = error_reg;
  345. errnum = find_first_bit(&errors,
  346. ARRAY_SIZE(ferr_global_lo_name));
  347. specific = GET_ERR_FROM_TABLE(ferr_global_lo_name, errnum);
  348. is_fatal = ferr_global_lo_is_fatal(errnum);
  349. /* Clear the error bit */
  350. pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  351. FERR_GLOBAL_LO, error_reg);
  352. goto error_global;
  353. }
  354. return;
  355. error_global:
  356. i7300_mc_printk(mci, KERN_EMERG, "%s misc error: %s\n",
  357. is_fatal ? "Fatal" : "NOT fatal", specific);
  358. }
  359. /**
  360. * i7300_process_fbd_error() - Retrieve the hardware error information from
  361. * the FBD error registers and sends it via
  362. * EDAC error API calls
  363. * @mci: struct mem_ctl_info pointer
  364. */
  365. static void i7300_process_fbd_error(struct mem_ctl_info *mci)
  366. {
  367. struct i7300_pvt *pvt;
  368. u32 errnum, value, error_reg;
  369. u16 val16;
  370. unsigned branch, channel, bank, rank, cas, ras;
  371. u32 syndrome;
  372. unsigned long errors;
  373. const char *specific;
  374. bool is_wr;
  375. pvt = mci->pvt_info;
  376. /* read in the 1st FATAL error register */
  377. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  378. FERR_FAT_FBD, &error_reg);
  379. if (unlikely(error_reg & FERR_FAT_FBD_ERR_MASK)) {
  380. errors = error_reg & FERR_FAT_FBD_ERR_MASK ;
  381. errnum = find_first_bit(&errors,
  382. ARRAY_SIZE(ferr_fat_fbd_name));
  383. specific = GET_ERR_FROM_TABLE(ferr_fat_fbd_name, errnum);
  384. branch = (GET_FBD_FAT_IDX(error_reg) == 2) ? 1 : 0;
  385. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
  386. NRECMEMA, &val16);
  387. bank = NRECMEMA_BANK(val16);
  388. rank = NRECMEMA_RANK(val16);
  389. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  390. NRECMEMB, &value);
  391. is_wr = NRECMEMB_IS_WR(value);
  392. cas = NRECMEMB_CAS(value);
  393. ras = NRECMEMB_RAS(value);
  394. /* Clean the error register */
  395. pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  396. FERR_FAT_FBD, error_reg);
  397. snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
  398. "FATAL (Branch=%d DRAM-Bank=%d %s "
  399. "RAS=%d CAS=%d Err=0x%lx (%s))",
  400. branch, bank,
  401. is_wr ? "RDWR" : "RD",
  402. ras, cas,
  403. errors, specific);
  404. /* Call the helper to output message */
  405. edac_mc_handle_fbd_ue(mci, rank, branch << 1,
  406. (branch << 1) + 1,
  407. pvt->tmp_prt_buffer);
  408. }
  409. /* read in the 1st NON-FATAL error register */
  410. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  411. FERR_NF_FBD, &error_reg);
  412. if (unlikely(error_reg & FERR_NF_FBD_ERR_MASK)) {
  413. errors = error_reg & FERR_NF_FBD_ERR_MASK;
  414. errnum = find_first_bit(&errors,
  415. ARRAY_SIZE(ferr_nf_fbd_name));
  416. specific = GET_ERR_FROM_TABLE(ferr_nf_fbd_name, errnum);
  417. branch = (GET_FBD_FAT_IDX(error_reg) == 2) ? 1 : 0;
  418. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  419. REDMEMA, &syndrome);
  420. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
  421. RECMEMA, &val16);
  422. bank = RECMEMA_BANK(val16);
  423. rank = RECMEMA_RANK(val16);
  424. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  425. RECMEMB, &value);
  426. is_wr = RECMEMB_IS_WR(value);
  427. cas = RECMEMB_CAS(value);
  428. ras = RECMEMB_RAS(value);
  429. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  430. REDMEMB, &value);
  431. channel = (branch << 1);
  432. if (IS_SECOND_CH(value))
  433. channel++;
  434. /* Clear the error bit */
  435. pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  436. FERR_NF_FBD, error_reg);
  437. /* Form out message */
  438. snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
  439. "Corrected error (Branch=%d, Channel %d), "
  440. " DRAM-Bank=%d %s "
  441. "RAS=%d CAS=%d, CE Err=0x%lx, Syndrome=0x%08x(%s))",
  442. branch, channel,
  443. bank,
  444. is_wr ? "RDWR" : "RD",
  445. ras, cas,
  446. errors, syndrome, specific);
  447. /*
  448. * Call the helper to output message
  449. * NOTE: Errors are reported per-branch, and not per-channel
  450. * Currently, we don't know how to identify the right
  451. * channel.
  452. */
  453. edac_mc_handle_fbd_ce(mci, rank, channel,
  454. pvt->tmp_prt_buffer);
  455. }
  456. return;
  457. }
  458. /**
  459. * i7300_check_error() - Calls the error checking subroutines
  460. * @mci: struct mem_ctl_info pointer
  461. */
  462. static void i7300_check_error(struct mem_ctl_info *mci)
  463. {
  464. i7300_process_error_global(mci);
  465. i7300_process_fbd_error(mci);
  466. };
  467. /**
  468. * i7300_clear_error() - Clears the error registers
  469. * @mci: struct mem_ctl_info pointer
  470. */
  471. static void i7300_clear_error(struct mem_ctl_info *mci)
  472. {
  473. struct i7300_pvt *pvt = mci->pvt_info;
  474. u32 value;
  475. /*
  476. * All error values are RWC - we need to read and write 1 to the
  477. * bit that we want to cleanup
  478. */
  479. /* Clear global error registers */
  480. pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  481. FERR_GLOBAL_HI, &value);
  482. pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  483. FERR_GLOBAL_HI, value);
  484. pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  485. FERR_GLOBAL_LO, &value);
  486. pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  487. FERR_GLOBAL_LO, value);
  488. /* Clear FBD error registers */
  489. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  490. FERR_FAT_FBD, &value);
  491. pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  492. FERR_FAT_FBD, value);
  493. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  494. FERR_NF_FBD, &value);
  495. pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  496. FERR_NF_FBD, value);
  497. }
  498. /**
  499. * i7300_enable_error_reporting() - Enable the memory reporting logic at the
  500. * hardware
  501. * @mci: struct mem_ctl_info pointer
  502. */
  503. static void i7300_enable_error_reporting(struct mem_ctl_info *mci)
  504. {
  505. struct i7300_pvt *pvt = mci->pvt_info;
  506. u32 fbd_error_mask;
  507. /* Read the FBD Error Mask Register */
  508. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  509. EMASK_FBD, &fbd_error_mask);
  510. /* Enable with a '0' */
  511. fbd_error_mask &= ~(EMASK_FBD_ERR_MASK);
  512. pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  513. EMASK_FBD, fbd_error_mask);
  514. }
  515. /************************************************
  516. * i7300 Functions related to memory enumberation
  517. ************************************************/
  518. /**
  519. * decode_mtr() - Decodes the MTR descriptor, filling the edac structs
  520. * @pvt: pointer to the private data struct used by i7300 driver
  521. * @slot: DIMM slot (0 to 7)
  522. * @ch: Channel number within the branch (0 or 1)
  523. * @branch: Branch number (0 or 1)
  524. * @dinfo: Pointer to DIMM info where dimm size is stored
  525. * @p_csrow: Pointer to the struct csrow_info that corresponds to that element
  526. */
  527. static int decode_mtr(struct i7300_pvt *pvt,
  528. int slot, int ch, int branch,
  529. struct i7300_dimm_info *dinfo,
  530. struct dimm_info *dimm)
  531. {
  532. int mtr, ans, addrBits, channel;
  533. channel = to_channel(ch, branch);
  534. mtr = pvt->mtr[slot][branch];
  535. ans = MTR_DIMMS_PRESENT(mtr) ? 1 : 0;
  536. debugf2("\tMTR%d CH%d: DIMMs are %s (mtr)\n",
  537. slot, channel,
  538. ans ? "Present" : "NOT Present");
  539. /* Determine if there is a DIMM present in this DIMM slot */
  540. if (!ans)
  541. return 0;
  542. /* Start with the number of bits for a Bank
  543. * on the DRAM */
  544. addrBits = MTR_DRAM_BANKS_ADDR_BITS;
  545. /* Add thenumber of ROW bits */
  546. addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
  547. /* add the number of COLUMN bits */
  548. addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
  549. /* add the number of RANK bits */
  550. addrBits += MTR_DIMM_RANKS(mtr);
  551. addrBits += 6; /* add 64 bits per DIMM */
  552. addrBits -= 20; /* divide by 2^^20 */
  553. addrBits -= 3; /* 8 bits per bytes */
  554. dinfo->megabytes = 1 << addrBits;
  555. debugf2("\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
  556. debugf2("\t\tELECTRICAL THROTTLING is %s\n",
  557. MTR_DIMMS_ETHROTTLE(mtr) ? "enabled" : "disabled");
  558. debugf2("\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
  559. debugf2("\t\tNUMRANK: %s\n", MTR_DIMM_RANKS(mtr) ? "double" : "single");
  560. debugf2("\t\tNUMROW: %s\n", numrow_toString[MTR_DIMM_ROWS(mtr)]);
  561. debugf2("\t\tNUMCOL: %s\n", numcol_toString[MTR_DIMM_COLS(mtr)]);
  562. debugf2("\t\tSIZE: %d MB\n", dinfo->megabytes);
  563. /*
  564. * The type of error detection actually depends of the
  565. * mode of operation. When it is just one single memory chip, at
  566. * socket 0, channel 0, it uses 8-byte-over-32-byte SECDED+ code.
  567. * In normal or mirrored mode, it uses Lockstep mode,
  568. * with the possibility of using an extended algorithm for x8 memories
  569. * See datasheet Sections 7.3.6 to 7.3.8
  570. */
  571. dimm->nr_pages = MiB_TO_PAGES(dinfo->megabytes);
  572. dimm->grain = 8;
  573. dimm->mtype = MEM_FB_DDR2;
  574. if (IS_SINGLE_MODE(pvt->mc_settings_a)) {
  575. dimm->edac_mode = EDAC_SECDED;
  576. debugf2("\t\tECC code is 8-byte-over-32-byte SECDED+ code\n");
  577. } else {
  578. debugf2("\t\tECC code is on Lockstep mode\n");
  579. if (MTR_DRAM_WIDTH(mtr) == 8)
  580. dimm->edac_mode = EDAC_S8ECD8ED;
  581. else
  582. dimm->edac_mode = EDAC_S4ECD4ED;
  583. }
  584. /* ask what device type on this row */
  585. if (MTR_DRAM_WIDTH(mtr) == 8) {
  586. debugf2("\t\tScrub algorithm for x8 is on %s mode\n",
  587. IS_SCRBALGO_ENHANCED(pvt->mc_settings) ?
  588. "enhanced" : "normal");
  589. dimm->dtype = DEV_X8;
  590. } else
  591. dimm->dtype = DEV_X4;
  592. return mtr;
  593. }
  594. /**
  595. * print_dimm_size() - Prints dump of the memory organization
  596. * @pvt: pointer to the private data struct used by i7300 driver
  597. *
  598. * Useful for debug. If debug is disabled, this routine do nothing
  599. */
  600. static void print_dimm_size(struct i7300_pvt *pvt)
  601. {
  602. #ifdef CONFIG_EDAC_DEBUG
  603. struct i7300_dimm_info *dinfo;
  604. char *p;
  605. int space, n;
  606. int channel, slot;
  607. space = PAGE_SIZE;
  608. p = pvt->tmp_prt_buffer;
  609. n = snprintf(p, space, " ");
  610. p += n;
  611. space -= n;
  612. for (channel = 0; channel < MAX_CHANNELS; channel++) {
  613. n = snprintf(p, space, "channel %d | ", channel);
  614. p += n;
  615. space -= n;
  616. }
  617. debugf2("%s\n", pvt->tmp_prt_buffer);
  618. p = pvt->tmp_prt_buffer;
  619. space = PAGE_SIZE;
  620. n = snprintf(p, space, "-------------------------------"
  621. "------------------------------");
  622. p += n;
  623. space -= n;
  624. debugf2("%s\n", pvt->tmp_prt_buffer);
  625. p = pvt->tmp_prt_buffer;
  626. space = PAGE_SIZE;
  627. for (slot = 0; slot < MAX_SLOTS; slot++) {
  628. n = snprintf(p, space, "csrow/SLOT %d ", slot);
  629. p += n;
  630. space -= n;
  631. for (channel = 0; channel < MAX_CHANNELS; channel++) {
  632. dinfo = &pvt->dimm_info[slot][channel];
  633. n = snprintf(p, space, "%4d MB | ", dinfo->megabytes);
  634. p += n;
  635. space -= n;
  636. }
  637. debugf2("%s\n", pvt->tmp_prt_buffer);
  638. p = pvt->tmp_prt_buffer;
  639. space = PAGE_SIZE;
  640. }
  641. n = snprintf(p, space, "-------------------------------"
  642. "------------------------------");
  643. p += n;
  644. space -= n;
  645. debugf2("%s\n", pvt->tmp_prt_buffer);
  646. p = pvt->tmp_prt_buffer;
  647. space = PAGE_SIZE;
  648. #endif
  649. }
  650. /**
  651. * i7300_init_csrows() - Initialize the 'csrows' table within
  652. * the mci control structure with the
  653. * addressing of memory.
  654. * @mci: struct mem_ctl_info pointer
  655. */
  656. static int i7300_init_csrows(struct mem_ctl_info *mci)
  657. {
  658. struct i7300_pvt *pvt;
  659. struct i7300_dimm_info *dinfo;
  660. int rc = -ENODEV;
  661. int mtr;
  662. int ch, branch, slot, channel;
  663. struct dimm_info *dimm;
  664. pvt = mci->pvt_info;
  665. debugf2("Memory Technology Registers:\n");
  666. /* Get the AMB present registers for the four channels */
  667. for (branch = 0; branch < MAX_BRANCHES; branch++) {
  668. /* Read and dump branch 0's MTRs */
  669. channel = to_channel(0, branch);
  670. pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
  671. AMBPRESENT_0,
  672. &pvt->ambpresent[channel]);
  673. debugf2("\t\tAMB-present CH%d = 0x%x:\n",
  674. channel, pvt->ambpresent[channel]);
  675. channel = to_channel(1, branch);
  676. pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
  677. AMBPRESENT_1,
  678. &pvt->ambpresent[channel]);
  679. debugf2("\t\tAMB-present CH%d = 0x%x:\n",
  680. channel, pvt->ambpresent[channel]);
  681. }
  682. /* Get the set of MTR[0-7] regs by each branch */
  683. for (slot = 0; slot < MAX_SLOTS; slot++) {
  684. int where = mtr_regs[slot];
  685. for (branch = 0; branch < MAX_BRANCHES; branch++) {
  686. pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
  687. where,
  688. &pvt->mtr[slot][branch]);
  689. for (ch = 0; ch < MAX_CH_PER_BRANCH; ch++) {
  690. int channel = to_channel(ch, branch);
  691. dinfo = &pvt->dimm_info[slot][channel];
  692. dimm = mci->csrows[slot].channels[branch * MAX_CH_PER_BRANCH + ch].dimm;
  693. mtr = decode_mtr(pvt, slot, ch, branch,
  694. dinfo, dimm);
  695. /* if no DIMMS on this row, continue */
  696. if (!MTR_DIMMS_PRESENT(mtr))
  697. continue;
  698. rc = 0;
  699. }
  700. }
  701. }
  702. return rc;
  703. }
  704. /**
  705. * decode_mir() - Decodes Memory Interleave Register (MIR) info
  706. * @int mir_no: number of the MIR register to decode
  707. * @mir: array with the MIR data cached on the driver
  708. */
  709. static void decode_mir(int mir_no, u16 mir[MAX_MIR])
  710. {
  711. if (mir[mir_no] & 3)
  712. debugf2("MIR%d: limit= 0x%x Branch(es) that participate:"
  713. " %s %s\n",
  714. mir_no,
  715. (mir[mir_no] >> 4) & 0xfff,
  716. (mir[mir_no] & 1) ? "B0" : "",
  717. (mir[mir_no] & 2) ? "B1" : "");
  718. }
  719. /**
  720. * i7300_get_mc_regs() - Get the contents of the MC enumeration registers
  721. * @mci: struct mem_ctl_info pointer
  722. *
  723. * Data read is cached internally for its usage when needed
  724. */
  725. static int i7300_get_mc_regs(struct mem_ctl_info *mci)
  726. {
  727. struct i7300_pvt *pvt;
  728. u32 actual_tolm;
  729. int i, rc;
  730. pvt = mci->pvt_info;
  731. pci_read_config_dword(pvt->pci_dev_16_0_fsb_ctlr, AMBASE,
  732. (u32 *) &pvt->ambase);
  733. debugf2("AMBASE= 0x%lx\n", (long unsigned int)pvt->ambase);
  734. /* Get the Branch Map regs */
  735. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, TOLM, &pvt->tolm);
  736. pvt->tolm >>= 12;
  737. debugf2("TOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
  738. pvt->tolm);
  739. actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28));
  740. debugf2("Actual TOLM byte addr=%u.%03u GB (0x%x)\n",
  741. actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28);
  742. /* Get memory controller settings */
  743. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS,
  744. &pvt->mc_settings);
  745. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS_A,
  746. &pvt->mc_settings_a);
  747. if (IS_SINGLE_MODE(pvt->mc_settings_a))
  748. debugf0("Memory controller operating on single mode\n");
  749. else
  750. debugf0("Memory controller operating on %s mode\n",
  751. IS_MIRRORED(pvt->mc_settings) ? "mirrored" : "non-mirrored");
  752. debugf0("Error detection is %s\n",
  753. IS_ECC_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
  754. debugf0("Retry is %s\n",
  755. IS_RETRY_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
  756. /* Get Memory Interleave Range registers */
  757. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR0,
  758. &pvt->mir[0]);
  759. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR1,
  760. &pvt->mir[1]);
  761. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR2,
  762. &pvt->mir[2]);
  763. /* Decode the MIR regs */
  764. for (i = 0; i < MAX_MIR; i++)
  765. decode_mir(i, pvt->mir);
  766. rc = i7300_init_csrows(mci);
  767. if (rc < 0)
  768. return rc;
  769. /* Go and determine the size of each DIMM and place in an
  770. * orderly matrix */
  771. print_dimm_size(pvt);
  772. return 0;
  773. }
  774. /*************************************************
  775. * i7300 Functions related to device probe/release
  776. *************************************************/
  777. /**
  778. * i7300_put_devices() - Release the PCI devices
  779. * @mci: struct mem_ctl_info pointer
  780. */
  781. static void i7300_put_devices(struct mem_ctl_info *mci)
  782. {
  783. struct i7300_pvt *pvt;
  784. int branch;
  785. pvt = mci->pvt_info;
  786. /* Decrement usage count for devices */
  787. for (branch = 0; branch < MAX_CH_PER_BRANCH; branch++)
  788. pci_dev_put(pvt->pci_dev_2x_0_fbd_branch[branch]);
  789. pci_dev_put(pvt->pci_dev_16_2_fsb_err_regs);
  790. pci_dev_put(pvt->pci_dev_16_1_fsb_addr_map);
  791. }
  792. /**
  793. * i7300_get_devices() - Find and perform 'get' operation on the MCH's
  794. * device/functions we want to reference for this driver
  795. * @mci: struct mem_ctl_info pointer
  796. *
  797. * Access and prepare the several devices for usage:
  798. * I7300 devices used by this driver:
  799. * Device 16, functions 0,1 and 2: PCI_DEVICE_ID_INTEL_I7300_MCH_ERR
  800. * Device 21 function 0: PCI_DEVICE_ID_INTEL_I7300_MCH_FB0
  801. * Device 22 function 0: PCI_DEVICE_ID_INTEL_I7300_MCH_FB1
  802. */
  803. static int __devinit i7300_get_devices(struct mem_ctl_info *mci)
  804. {
  805. struct i7300_pvt *pvt;
  806. struct pci_dev *pdev;
  807. pvt = mci->pvt_info;
  808. /* Attempt to 'get' the MCH register we want */
  809. pdev = NULL;
  810. while (!pvt->pci_dev_16_1_fsb_addr_map ||
  811. !pvt->pci_dev_16_2_fsb_err_regs) {
  812. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  813. PCI_DEVICE_ID_INTEL_I7300_MCH_ERR, pdev);
  814. if (!pdev) {
  815. /* End of list, leave */
  816. i7300_printk(KERN_ERR,
  817. "'system address,Process Bus' "
  818. "device not found:"
  819. "vendor 0x%x device 0x%x ERR funcs "
  820. "(broken BIOS?)\n",
  821. PCI_VENDOR_ID_INTEL,
  822. PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
  823. goto error;
  824. }
  825. /* Store device 16 funcs 1 and 2 */
  826. switch (PCI_FUNC(pdev->devfn)) {
  827. case 1:
  828. pvt->pci_dev_16_1_fsb_addr_map = pdev;
  829. break;
  830. case 2:
  831. pvt->pci_dev_16_2_fsb_err_regs = pdev;
  832. break;
  833. }
  834. }
  835. debugf1("System Address, processor bus- PCI Bus ID: %s %x:%x\n",
  836. pci_name(pvt->pci_dev_16_0_fsb_ctlr),
  837. pvt->pci_dev_16_0_fsb_ctlr->vendor,
  838. pvt->pci_dev_16_0_fsb_ctlr->device);
  839. debugf1("Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
  840. pci_name(pvt->pci_dev_16_1_fsb_addr_map),
  841. pvt->pci_dev_16_1_fsb_addr_map->vendor,
  842. pvt->pci_dev_16_1_fsb_addr_map->device);
  843. debugf1("FSB Error Regs - PCI Bus ID: %s %x:%x\n",
  844. pci_name(pvt->pci_dev_16_2_fsb_err_regs),
  845. pvt->pci_dev_16_2_fsb_err_regs->vendor,
  846. pvt->pci_dev_16_2_fsb_err_regs->device);
  847. pvt->pci_dev_2x_0_fbd_branch[0] = pci_get_device(PCI_VENDOR_ID_INTEL,
  848. PCI_DEVICE_ID_INTEL_I7300_MCH_FB0,
  849. NULL);
  850. if (!pvt->pci_dev_2x_0_fbd_branch[0]) {
  851. i7300_printk(KERN_ERR,
  852. "MC: 'BRANCH 0' device not found:"
  853. "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
  854. PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_FB0);
  855. goto error;
  856. }
  857. pvt->pci_dev_2x_0_fbd_branch[1] = pci_get_device(PCI_VENDOR_ID_INTEL,
  858. PCI_DEVICE_ID_INTEL_I7300_MCH_FB1,
  859. NULL);
  860. if (!pvt->pci_dev_2x_0_fbd_branch[1]) {
  861. i7300_printk(KERN_ERR,
  862. "MC: 'BRANCH 1' device not found:"
  863. "vendor 0x%x device 0x%x Func 0 "
  864. "(broken BIOS?)\n",
  865. PCI_VENDOR_ID_INTEL,
  866. PCI_DEVICE_ID_INTEL_I7300_MCH_FB1);
  867. goto error;
  868. }
  869. return 0;
  870. error:
  871. i7300_put_devices(mci);
  872. return -ENODEV;
  873. }
  874. /**
  875. * i7300_init_one() - Probe for one instance of the device
  876. * @pdev: struct pci_dev pointer
  877. * @id: struct pci_device_id pointer - currently unused
  878. */
  879. static int __devinit i7300_init_one(struct pci_dev *pdev,
  880. const struct pci_device_id *id)
  881. {
  882. struct mem_ctl_info *mci;
  883. struct i7300_pvt *pvt;
  884. int num_channels;
  885. int num_dimms_per_channel;
  886. int num_csrows;
  887. int rc;
  888. /* wake up device */
  889. rc = pci_enable_device(pdev);
  890. if (rc == -EIO)
  891. return rc;
  892. debugf0("MC: " __FILE__ ": %s(), pdev bus %u dev=0x%x fn=0x%x\n",
  893. __func__,
  894. pdev->bus->number,
  895. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  896. /* We only are looking for func 0 of the set */
  897. if (PCI_FUNC(pdev->devfn) != 0)
  898. return -ENODEV;
  899. /* As we don't have a motherboard identification routine to determine
  900. * actual number of slots/dimms per channel, we thus utilize the
  901. * resource as specified by the chipset. Thus, we might have
  902. * have more DIMMs per channel than actually on the mobo, but this
  903. * allows the driver to support up to the chipset max, without
  904. * some fancy mobo determination.
  905. */
  906. num_dimms_per_channel = MAX_SLOTS;
  907. num_channels = MAX_CHANNELS;
  908. num_csrows = MAX_SLOTS * MAX_CHANNELS;
  909. debugf0("MC: %s(): Number of - Channels= %d DIMMS= %d CSROWS= %d\n",
  910. __func__, num_channels, num_dimms_per_channel, num_csrows);
  911. /* allocate a new MC control structure */
  912. mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0);
  913. if (mci == NULL)
  914. return -ENOMEM;
  915. debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
  916. mci->dev = &pdev->dev; /* record ptr to the generic device */
  917. pvt = mci->pvt_info;
  918. pvt->pci_dev_16_0_fsb_ctlr = pdev; /* Record this device in our private */
  919. pvt->tmp_prt_buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
  920. if (!pvt->tmp_prt_buffer) {
  921. edac_mc_free(mci);
  922. return -ENOMEM;
  923. }
  924. /* 'get' the pci devices we want to reserve for our use */
  925. if (i7300_get_devices(mci))
  926. goto fail0;
  927. mci->mc_idx = 0;
  928. mci->mtype_cap = MEM_FLAG_FB_DDR2;
  929. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  930. mci->edac_cap = EDAC_FLAG_NONE;
  931. mci->mod_name = "i7300_edac.c";
  932. mci->mod_ver = I7300_REVISION;
  933. mci->ctl_name = i7300_devs[0].ctl_name;
  934. mci->dev_name = pci_name(pdev);
  935. mci->ctl_page_to_phys = NULL;
  936. /* Set the function pointer to an actual operation function */
  937. mci->edac_check = i7300_check_error;
  938. /* initialize the MC control structure 'csrows' table
  939. * with the mapping and control information */
  940. if (i7300_get_mc_regs(mci)) {
  941. debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
  942. " because i7300_init_csrows() returned nonzero "
  943. "value\n");
  944. mci->edac_cap = EDAC_FLAG_NONE; /* no csrows found */
  945. } else {
  946. debugf1("MC: Enable error reporting now\n");
  947. i7300_enable_error_reporting(mci);
  948. }
  949. /* add this new MC control structure to EDAC's list of MCs */
  950. if (edac_mc_add_mc(mci)) {
  951. debugf0("MC: " __FILE__
  952. ": %s(): failed edac_mc_add_mc()\n", __func__);
  953. /* FIXME: perhaps some code should go here that disables error
  954. * reporting if we just enabled it
  955. */
  956. goto fail1;
  957. }
  958. i7300_clear_error(mci);
  959. /* allocating generic PCI control info */
  960. i7300_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  961. if (!i7300_pci) {
  962. printk(KERN_WARNING
  963. "%s(): Unable to create PCI control\n",
  964. __func__);
  965. printk(KERN_WARNING
  966. "%s(): PCI error report via EDAC not setup\n",
  967. __func__);
  968. }
  969. return 0;
  970. /* Error exit unwinding stack */
  971. fail1:
  972. i7300_put_devices(mci);
  973. fail0:
  974. kfree(pvt->tmp_prt_buffer);
  975. edac_mc_free(mci);
  976. return -ENODEV;
  977. }
  978. /**
  979. * i7300_remove_one() - Remove the driver
  980. * @pdev: struct pci_dev pointer
  981. */
  982. static void __devexit i7300_remove_one(struct pci_dev *pdev)
  983. {
  984. struct mem_ctl_info *mci;
  985. char *tmp;
  986. debugf0(__FILE__ ": %s()\n", __func__);
  987. if (i7300_pci)
  988. edac_pci_release_generic_ctl(i7300_pci);
  989. mci = edac_mc_del_mc(&pdev->dev);
  990. if (!mci)
  991. return;
  992. tmp = ((struct i7300_pvt *)mci->pvt_info)->tmp_prt_buffer;
  993. /* retrieve references to resources, and free those resources */
  994. i7300_put_devices(mci);
  995. kfree(tmp);
  996. edac_mc_free(mci);
  997. }
  998. /*
  999. * pci_device_id: table for which devices we are looking for
  1000. *
  1001. * Has only 8086:360c PCI ID
  1002. */
  1003. static DEFINE_PCI_DEVICE_TABLE(i7300_pci_tbl) = {
  1004. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
  1005. {0,} /* 0 terminated list. */
  1006. };
  1007. MODULE_DEVICE_TABLE(pci, i7300_pci_tbl);
  1008. /*
  1009. * i7300_driver: pci_driver structure for this module
  1010. */
  1011. static struct pci_driver i7300_driver = {
  1012. .name = "i7300_edac",
  1013. .probe = i7300_init_one,
  1014. .remove = __devexit_p(i7300_remove_one),
  1015. .id_table = i7300_pci_tbl,
  1016. };
  1017. /**
  1018. * i7300_init() - Registers the driver
  1019. */
  1020. static int __init i7300_init(void)
  1021. {
  1022. int pci_rc;
  1023. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  1024. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1025. opstate_init();
  1026. pci_rc = pci_register_driver(&i7300_driver);
  1027. return (pci_rc < 0) ? pci_rc : 0;
  1028. }
  1029. /**
  1030. * i7300_init() - Unregisters the driver
  1031. */
  1032. static void __exit i7300_exit(void)
  1033. {
  1034. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  1035. pci_unregister_driver(&i7300_driver);
  1036. }
  1037. module_init(i7300_init);
  1038. module_exit(i7300_exit);
  1039. MODULE_LICENSE("GPL");
  1040. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
  1041. MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
  1042. MODULE_DESCRIPTION("MC Driver for Intel I7300 memory controllers - "
  1043. I7300_REVISION);
  1044. module_param(edac_op_state, int, 0444);
  1045. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");