i7core_edac.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  1. /* Intel 7 core Memory Controller kernel module (Nehalem)
  2. *
  3. * This file may be distributed under the terms of the
  4. * GNU General Public License version 2 only.
  5. *
  6. * Copyright (c) 2009 by:
  7. * Mauro Carvalho Chehab <mchehab@redhat.com>
  8. *
  9. * Red Hat Inc. http://www.redhat.com
  10. *
  11. * Forked and adapted from the i5400_edac driver
  12. *
  13. * Based on the following public Intel datasheets:
  14. * Intel Core i7 Processor Extreme Edition and Intel Core i7 Processor
  15. * Datasheet, Volume 2:
  16. * http://download.intel.com/design/processor/datashts/320835.pdf
  17. * Intel Xeon Processor 5500 Series Datasheet Volume 2
  18. * http://www.intel.com/Assets/PDF/datasheet/321322.pdf
  19. * also available at:
  20. * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
  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. /* To use the new pci_[read/write]_config_qword instead of two dword */
  31. #define USE_QWORD 1
  32. /*
  33. * Alter this version for the module when modifications are made
  34. */
  35. #define I7CORE_REVISION " Ver: 1.0.0 " __DATE__
  36. #define EDAC_MOD_STR "i7core_edac"
  37. /* HACK: temporary, just to enable all logs, for now */
  38. #undef debugf0
  39. #define debugf0(fmt, arg...) edac_printk(KERN_INFO, "i7core", fmt, ##arg)
  40. /*
  41. * Debug macros
  42. */
  43. #define i7core_printk(level, fmt, arg...) \
  44. edac_printk(level, "i7core", fmt, ##arg)
  45. #define i7core_mc_printk(mci, level, fmt, arg...) \
  46. edac_mc_chipset_printk(mci, level, "i7core", fmt, ##arg)
  47. /*
  48. * i7core Memory Controller Registers
  49. */
  50. /* OFFSETS for Device 3 Function 0 */
  51. #define MC_CONTROL 0x48
  52. #define MC_STATUS 0x4c
  53. #define MC_MAX_DOD 0x64
  54. /*
  55. * OFFSETS for Device 3 Function 4, as inicated on Xeon 5500 datasheet:
  56. * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
  57. */
  58. #define MC_TEST_ERR_RCV1 0x60
  59. #define DIMM2_COR_ERR(r) ((r) & 0x7fff)
  60. #define MC_TEST_ERR_RCV0 0x64
  61. #define DIMM1_COR_ERR(r) (((r) >> 16) & 0x7fff)
  62. #define DIMM0_COR_ERR(r) ((r) & 0x7fff)
  63. /* OFFSETS for Devices 4,5 and 6 Function 0 */
  64. #define MC_CHANNEL_DIMM_INIT_PARAMS 0x58
  65. #define THREE_DIMMS_PRESENT (1 << 24)
  66. #define SINGLE_QUAD_RANK_PRESENT (1 << 23)
  67. #define QUAD_RANK_PRESENT (1 << 22)
  68. #define REGISTERED_DIMM (1 << 15)
  69. #define MC_CHANNEL_MAPPER 0x60
  70. #define RDLCH(r, ch) ((((r) >> (3 + (ch * 6))) & 0x07) - 1)
  71. #define WRLCH(r, ch) ((((r) >> (ch * 6)) & 0x07) - 1)
  72. #define MC_CHANNEL_RANK_PRESENT 0x7c
  73. #define RANK_PRESENT_MASK 0xffff
  74. #define MC_CHANNEL_ADDR_MATCH 0xf0
  75. #define MC_CHANNEL_ERROR_MASK 0xf8
  76. #define MC_CHANNEL_ERROR_INJECT 0xfc
  77. #define INJECT_ADDR_PARITY 0x10
  78. #define INJECT_ECC 0x08
  79. #define MASK_CACHELINE 0x06
  80. #define MASK_FULL_CACHELINE 0x06
  81. #define MASK_MSB32_CACHELINE 0x04
  82. #define MASK_LSB32_CACHELINE 0x02
  83. #define NO_MASK_CACHELINE 0x00
  84. #define REPEAT_EN 0x01
  85. /* OFFSETS for Devices 4,5 and 6 Function 1 */
  86. #define MC_DOD_CH_DIMM0 0x48
  87. #define MC_DOD_CH_DIMM1 0x4c
  88. #define MC_DOD_CH_DIMM2 0x50
  89. #define RANKOFFSET_MASK ((1 << 12) | (1 << 11) | (1 << 10))
  90. #define RANKOFFSET(x) ((x & RANKOFFSET_MASK) >> 10)
  91. #define DIMM_PRESENT_MASK (1 << 9)
  92. #define DIMM_PRESENT(x) (((x) & DIMM_PRESENT_MASK) >> 9)
  93. #define MC_DOD_NUMBANK_MASK ((1 << 8) | (1 << 7))
  94. #define MC_DOD_NUMBANK(x) (((x) & MC_DOD_NUMBANK_MASK) >> 7)
  95. #define MC_DOD_NUMRANK_MASK ((1 << 6) | (1 << 5))
  96. #define MC_DOD_NUMRANK(x) (((x) & MC_DOD_NUMRANK_MASK) >> 5)
  97. #define MC_DOD_NUMROW_MASK ((1 << 4) | (1 << 3)| (1 << 2))
  98. #define MC_DOD_NUMROW(x) (((x) & MC_DOD_NUMROW_MASK) >> 2)
  99. #define MC_DOD_NUMCOL_MASK 3
  100. #define MC_DOD_NUMCOL(x) ((x) & MC_DOD_NUMCOL_MASK)
  101. #define MC_RANK_PRESENT 0x7c
  102. #define MC_SAG_CH_0 0x80
  103. #define MC_SAG_CH_1 0x84
  104. #define MC_SAG_CH_2 0x88
  105. #define MC_SAG_CH_3 0x8c
  106. #define MC_SAG_CH_4 0x90
  107. #define MC_SAG_CH_5 0x94
  108. #define MC_SAG_CH_6 0x98
  109. #define MC_SAG_CH_7 0x9c
  110. #define MC_RIR_LIMIT_CH_0 0x40
  111. #define MC_RIR_LIMIT_CH_1 0x44
  112. #define MC_RIR_LIMIT_CH_2 0x48
  113. #define MC_RIR_LIMIT_CH_3 0x4C
  114. #define MC_RIR_LIMIT_CH_4 0x50
  115. #define MC_RIR_LIMIT_CH_5 0x54
  116. #define MC_RIR_LIMIT_CH_6 0x58
  117. #define MC_RIR_LIMIT_CH_7 0x5C
  118. #define MC_RIR_LIMIT_MASK ((1 << 10) - 1)
  119. #define MC_RIR_WAY_CH 0x80
  120. #define MC_RIR_WAY_OFFSET_MASK (((1 << 14) - 1) & ~0x7)
  121. #define MC_RIR_WAY_RANK_MASK 0x7
  122. /*
  123. * i7core structs
  124. */
  125. #define NUM_CHANS 3
  126. #define MAX_DIMMS 3 /* Max DIMMS per channel */
  127. #define MAX_MCR_FUNC 4
  128. #define MAX_CHAN_FUNC 3
  129. struct i7core_info {
  130. u32 mc_control;
  131. u32 mc_status;
  132. u32 max_dod;
  133. u32 ch_map;
  134. };
  135. struct i7core_inject {
  136. int enable;
  137. u32 section;
  138. u32 type;
  139. u32 eccmask;
  140. /* Error address mask */
  141. int channel, dimm, rank, bank, page, col;
  142. };
  143. struct i7core_channel {
  144. u32 ranks;
  145. u32 dimms;
  146. };
  147. struct pci_id_descr {
  148. int dev;
  149. int func;
  150. int dev_id;
  151. struct pci_dev *pdev;
  152. };
  153. struct i7core_pvt {
  154. struct pci_dev *pci_mcr[MAX_MCR_FUNC + 1];
  155. struct pci_dev *pci_ch[NUM_CHANS][MAX_CHAN_FUNC + 1];
  156. struct i7core_info info;
  157. struct i7core_inject inject;
  158. struct i7core_channel channel[NUM_CHANS];
  159. int channels; /* Number of active channels */
  160. int ce_count_available;
  161. unsigned long ce_count[MAX_DIMMS]; /* ECC corrected errors counts per dimm */
  162. int last_ce_count[MAX_DIMMS];
  163. };
  164. /* Device name and register DID (Device ID) */
  165. struct i7core_dev_info {
  166. const char *ctl_name; /* name for this device */
  167. u16 fsb_mapping_errors; /* DID for the branchmap,control */
  168. };
  169. #define PCI_DESCR(device, function, device_id) \
  170. .dev = (device), \
  171. .func = (function), \
  172. .dev_id = (device_id)
  173. struct pci_id_descr pci_devs[] = {
  174. /* Memory controller */
  175. { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_I7_MCR) },
  176. { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_I7_MC_TAD) },
  177. { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_I7_MC_RAS) }, /* if RDIMM is supported */
  178. { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_I7_MC_TEST) },
  179. /* Channel 0 */
  180. { PCI_DESCR(4, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH0_CTRL) },
  181. { PCI_DESCR(4, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH0_ADDR) },
  182. { PCI_DESCR(4, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH0_RANK) },
  183. { PCI_DESCR(4, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH0_TC) },
  184. /* Channel 1 */
  185. { PCI_DESCR(5, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH1_CTRL) },
  186. { PCI_DESCR(5, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH1_ADDR) },
  187. { PCI_DESCR(5, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH1_RANK) },
  188. { PCI_DESCR(5, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH1_TC) },
  189. /* Channel 2 */
  190. { PCI_DESCR(6, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH2_CTRL) },
  191. { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH2_ADDR) },
  192. { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH2_RANK) },
  193. { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH2_TC) },
  194. };
  195. #define N_DEVS ARRAY_SIZE(pci_devs)
  196. /*
  197. * pci_device_id table for which devices we are looking for
  198. * This should match the first device at pci_devs table
  199. */
  200. static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
  201. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7_MCR)},
  202. {0,} /* 0 terminated list. */
  203. };
  204. /* Table of devices attributes supported by this driver */
  205. static const struct i7core_dev_info i7core_devs[] = {
  206. {
  207. .ctl_name = "i7 Core",
  208. .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I7_MCR,
  209. },
  210. };
  211. static struct edac_pci_ctl_info *i7core_pci;
  212. /****************************************************************************
  213. Anciliary status routines
  214. ****************************************************************************/
  215. /* MC_CONTROL bits */
  216. #define CH_ACTIVE(pvt, ch) ((pvt)->info.mc_control & (1 << (8 + ch)))
  217. #define ECCx8(pvt) ((pvt)->info.mc_control & (1 << 1))
  218. /* MC_STATUS bits */
  219. #define ECC_ENABLED(pvt) ((pvt)->info.mc_status & (1 << 3))
  220. #define CH_DISABLED(pvt, ch) ((pvt)->info.mc_status & (1 << ch))
  221. /* MC_MAX_DOD read functions */
  222. static inline int numdimms(u32 dimms)
  223. {
  224. return (dimms & 0x3) + 1;
  225. }
  226. static inline int numrank(u32 rank)
  227. {
  228. static int ranks[4] = { 1, 2, 4, -EINVAL };
  229. return ranks[rank & 0x3];
  230. }
  231. static inline int numbank(u32 bank)
  232. {
  233. static int banks[4] = { 4, 8, 16, -EINVAL };
  234. return banks[bank & 0x3];
  235. }
  236. static inline int numrow(u32 row)
  237. {
  238. static int rows[8] = {
  239. 1 << 12, 1 << 13, 1 << 14, 1 << 15,
  240. 1 << 16, -EINVAL, -EINVAL, -EINVAL,
  241. };
  242. return rows[row & 0x7];
  243. }
  244. static inline int numcol(u32 col)
  245. {
  246. static int cols[8] = {
  247. 1 << 10, 1 << 11, 1 << 12, -EINVAL,
  248. };
  249. return cols[col & 0x3];
  250. }
  251. /****************************************************************************
  252. Memory check routines
  253. ****************************************************************************/
  254. static struct pci_dev *get_pdev_slot_func(int slot, int func)
  255. {
  256. int i;
  257. for (i = 0; i < N_DEVS; i++) {
  258. if (!pci_devs[i].pdev)
  259. continue;
  260. if (PCI_SLOT(pci_devs[i].pdev->devfn) == slot &&
  261. PCI_FUNC(pci_devs[i].pdev->devfn) == func) {
  262. return pci_devs[i].pdev;
  263. }
  264. }
  265. return NULL;
  266. }
  267. static int i7core_get_active_channels(int *channels, int *csrows)
  268. {
  269. struct pci_dev *pdev = NULL;
  270. int i, j;
  271. u32 status, control;
  272. *channels = 0;
  273. *csrows = 0;
  274. pdev = get_pdev_slot_func(3, 0);
  275. if (!pdev) {
  276. i7core_printk(KERN_ERR, "Couldn't find fn 3.0!!!\n");
  277. return -ENODEV;
  278. }
  279. /* Device 3 function 0 reads */
  280. pci_read_config_dword(pdev, MC_STATUS, &status);
  281. pci_read_config_dword(pdev, MC_CONTROL, &control);
  282. for (i = 0; i < NUM_CHANS; i++) {
  283. u32 dimm_dod[3];
  284. /* Check if the channel is active */
  285. if (!(control & (1 << (8 + i))))
  286. continue;
  287. /* Check if the channel is disabled */
  288. if (status & (1 << i)) {
  289. continue;
  290. }
  291. pdev = get_pdev_slot_func(i + 4, 1);
  292. if (!pdev) {
  293. i7core_printk(KERN_ERR, "Couldn't find fn %d.%d!!!\n",
  294. i + 4, 1);
  295. return -ENODEV;
  296. }
  297. /* Devices 4-6 function 1 */
  298. pci_read_config_dword(pdev,
  299. MC_DOD_CH_DIMM0, &dimm_dod[0]);
  300. pci_read_config_dword(pdev,
  301. MC_DOD_CH_DIMM1, &dimm_dod[1]);
  302. pci_read_config_dword(pdev,
  303. MC_DOD_CH_DIMM2, &dimm_dod[2]);
  304. (*channels)++;
  305. for (j = 0; j < 3; j++) {
  306. if (!DIMM_PRESENT(dimm_dod[j]))
  307. continue;
  308. (*csrows)++;
  309. }
  310. }
  311. debugf0("Number of active channels: %d\n", *channels);
  312. return 0;
  313. }
  314. static int get_dimm_config(struct mem_ctl_info *mci)
  315. {
  316. struct i7core_pvt *pvt = mci->pvt_info;
  317. struct csrow_info *csr;
  318. struct pci_dev *pdev;
  319. int i, j, csrow = 0;
  320. unsigned long last_page = 0;
  321. enum edac_type mode;
  322. enum mem_type mtype;
  323. /* Get data from the MC register, function 0 */
  324. pdev = pvt->pci_mcr[0];
  325. if (!pdev)
  326. return -ENODEV;
  327. /* Device 3 function 0 reads */
  328. pci_read_config_dword(pdev, MC_CONTROL, &pvt->info.mc_control);
  329. pci_read_config_dword(pdev, MC_STATUS, &pvt->info.mc_status);
  330. pci_read_config_dword(pdev, MC_MAX_DOD, &pvt->info.max_dod);
  331. pci_read_config_dword(pdev, MC_CHANNEL_MAPPER, &pvt->info.ch_map);
  332. debugf0("MC control=0x%08x status=0x%08x dod=0x%08x map=0x%08x\n",
  333. pvt->info.mc_control, pvt->info.mc_status,
  334. pvt->info.max_dod, pvt->info.ch_map);
  335. if (ECC_ENABLED(pvt)) {
  336. debugf0("ECC enabled with x%d SDCC\n", ECCx8(pvt) ?8:4);
  337. if (ECCx8(pvt))
  338. mode = EDAC_S8ECD8ED;
  339. else
  340. mode = EDAC_S4ECD4ED;
  341. } else {
  342. debugf0("ECC disabled\n");
  343. mode = EDAC_NONE;
  344. }
  345. /* FIXME: need to handle the error codes */
  346. debugf0("DOD Max limits: DIMMS: %d, %d-ranked, %d-banked\n",
  347. numdimms(pvt->info.max_dod),
  348. numrank(pvt->info.max_dod >> 2),
  349. numbank(pvt->info.max_dod >> 4));
  350. debugf0("DOD Max rows x colums = 0x%x x 0x%x\n",
  351. numrow(pvt->info.max_dod >> 6),
  352. numcol(pvt->info.max_dod >> 9));
  353. debugf0("Memory channel configuration:\n");
  354. for (i = 0; i < NUM_CHANS; i++) {
  355. u32 data, dimm_dod[3], value[8];
  356. if (!CH_ACTIVE(pvt, i)) {
  357. debugf0("Channel %i is not active\n", i);
  358. continue;
  359. }
  360. if (CH_DISABLED(pvt, i)) {
  361. debugf0("Channel %i is disabled\n", i);
  362. continue;
  363. }
  364. /* Devices 4-6 function 0 */
  365. pci_read_config_dword(pvt->pci_ch[i][0],
  366. MC_CHANNEL_DIMM_INIT_PARAMS, &data);
  367. pvt->channel[i].ranks = (data & QUAD_RANK_PRESENT)? 4 : 2;
  368. if (data & REGISTERED_DIMM)
  369. mtype = MEM_RDDR3;
  370. else
  371. mtype = MEM_DDR3;
  372. #if 0
  373. if (data & THREE_DIMMS_PRESENT)
  374. pvt->channel[i].dimms = 3;
  375. else if (data & SINGLE_QUAD_RANK_PRESENT)
  376. pvt->channel[i].dimms = 1;
  377. else
  378. pvt->channel[i].dimms = 2;
  379. #endif
  380. /* Devices 4-6 function 1 */
  381. pci_read_config_dword(pvt->pci_ch[i][1],
  382. MC_DOD_CH_DIMM0, &dimm_dod[0]);
  383. pci_read_config_dword(pvt->pci_ch[i][1],
  384. MC_DOD_CH_DIMM1, &dimm_dod[1]);
  385. pci_read_config_dword(pvt->pci_ch[i][1],
  386. MC_DOD_CH_DIMM2, &dimm_dod[2]);
  387. debugf0("Ch%d phy rd%d, wr%d (0x%08x): "
  388. "%d ranks, %cDIMMs\n",
  389. i,
  390. RDLCH(pvt->info.ch_map, i), WRLCH(pvt->info.ch_map, i),
  391. data,
  392. pvt->channel[i].ranks,
  393. (data & REGISTERED_DIMM)? 'R' : 'U');
  394. for (j = 0; j < 3; j++) {
  395. u32 banks, ranks, rows, cols;
  396. u32 size, npages;
  397. if (!DIMM_PRESENT(dimm_dod[j]))
  398. continue;
  399. banks = numbank(MC_DOD_NUMBANK(dimm_dod[j]));
  400. ranks = numrank(MC_DOD_NUMRANK(dimm_dod[j]));
  401. rows = numrow(MC_DOD_NUMROW(dimm_dod[j]));
  402. cols = numcol(MC_DOD_NUMCOL(dimm_dod[j]));
  403. /* DDR3 has 8 I/O banks */
  404. size = (rows * cols * banks * ranks) >> (20 - 3);
  405. pvt->channel[i].dimms++;
  406. debugf0("\tdimm %d (0x%08x) %d Mb offset: %x, "
  407. "numbank: %d,\n\t\t"
  408. "numrank: %d, numrow: %#x, numcol: %#x\n",
  409. j, dimm_dod[j], size,
  410. RANKOFFSET(dimm_dod[j]),
  411. banks, ranks, rows, cols);
  412. #if PAGE_SHIFT > 20
  413. npages = size >> (PAGE_SHIFT - 20);
  414. #else
  415. npages = size << (20 - PAGE_SHIFT);
  416. #endif
  417. csr = &mci->csrows[csrow];
  418. csr->first_page = last_page + 1;
  419. last_page += npages;
  420. csr->last_page = last_page;
  421. csr->nr_pages = npages;
  422. csr->page_mask = 0;
  423. csr->grain = 8;
  424. csr->csrow_idx = csrow;
  425. csr->nr_channels = 1;
  426. csr->channels[0].chan_idx = i;
  427. csr->channels[0].ce_count = 0;
  428. switch (banks) {
  429. case 4:
  430. csr->dtype = DEV_X4;
  431. break;
  432. case 8:
  433. csr->dtype = DEV_X8;
  434. break;
  435. case 16:
  436. csr->dtype = DEV_X16;
  437. break;
  438. default:
  439. csr->dtype = DEV_UNKNOWN;
  440. }
  441. csr->edac_mode = mode;
  442. csr->mtype = mtype;
  443. csrow++;
  444. }
  445. pci_read_config_dword(pdev, MC_SAG_CH_0, &value[0]);
  446. pci_read_config_dword(pdev, MC_SAG_CH_1, &value[1]);
  447. pci_read_config_dword(pdev, MC_SAG_CH_2, &value[2]);
  448. pci_read_config_dword(pdev, MC_SAG_CH_3, &value[3]);
  449. pci_read_config_dword(pdev, MC_SAG_CH_4, &value[4]);
  450. pci_read_config_dword(pdev, MC_SAG_CH_5, &value[5]);
  451. pci_read_config_dword(pdev, MC_SAG_CH_6, &value[6]);
  452. pci_read_config_dword(pdev, MC_SAG_CH_7, &value[7]);
  453. printk("\t[%i] DIVBY3\tREMOVED\tOFFSET\n", i);
  454. for (j = 0; j < 8; j++)
  455. printk("\t\t%#x\t%#x\t%#x\n",
  456. (value[j] >> 27) & 0x1,
  457. (value[j] >> 24) & 0x7,
  458. (value[j] && ((1 << 24) - 1)));
  459. }
  460. return 0;
  461. }
  462. /****************************************************************************
  463. Error insertion routines
  464. ****************************************************************************/
  465. /* The i7core has independent error injection features per channel.
  466. However, to have a simpler code, we don't allow enabling error injection
  467. on more than one channel.
  468. Also, since a change at an inject parameter will be applied only at enable,
  469. we're disabling error injection on all write calls to the sysfs nodes that
  470. controls the error code injection.
  471. */
  472. static int disable_inject(struct mem_ctl_info *mci)
  473. {
  474. struct i7core_pvt *pvt = mci->pvt_info;
  475. pvt->inject.enable = 0;
  476. if (!pvt->pci_ch[pvt->inject.channel][0])
  477. return -ENODEV;
  478. pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  479. MC_CHANNEL_ERROR_MASK, 0);
  480. return 0;
  481. }
  482. /*
  483. * i7core inject inject.section
  484. *
  485. * accept and store error injection inject.section value
  486. * bit 0 - refers to the lower 32-byte half cacheline
  487. * bit 1 - refers to the upper 32-byte half cacheline
  488. */
  489. static ssize_t i7core_inject_section_store(struct mem_ctl_info *mci,
  490. const char *data, size_t count)
  491. {
  492. struct i7core_pvt *pvt = mci->pvt_info;
  493. unsigned long value;
  494. int rc;
  495. if (pvt->inject.enable)
  496. disable_inject(mci);
  497. rc = strict_strtoul(data, 10, &value);
  498. if ((rc < 0) || (value > 3))
  499. return 0;
  500. pvt->inject.section = (u32) value;
  501. return count;
  502. }
  503. static ssize_t i7core_inject_section_show(struct mem_ctl_info *mci,
  504. char *data)
  505. {
  506. struct i7core_pvt *pvt = mci->pvt_info;
  507. return sprintf(data, "0x%08x\n", pvt->inject.section);
  508. }
  509. /*
  510. * i7core inject.type
  511. *
  512. * accept and store error injection inject.section value
  513. * bit 0 - repeat enable - Enable error repetition
  514. * bit 1 - inject ECC error
  515. * bit 2 - inject parity error
  516. */
  517. static ssize_t i7core_inject_type_store(struct mem_ctl_info *mci,
  518. const char *data, size_t count)
  519. {
  520. struct i7core_pvt *pvt = mci->pvt_info;
  521. unsigned long value;
  522. int rc;
  523. if (pvt->inject.enable)
  524. disable_inject(mci);
  525. rc = strict_strtoul(data, 10, &value);
  526. if ((rc < 0) || (value > 7))
  527. return 0;
  528. pvt->inject.type = (u32) value;
  529. return count;
  530. }
  531. static ssize_t i7core_inject_type_show(struct mem_ctl_info *mci,
  532. char *data)
  533. {
  534. struct i7core_pvt *pvt = mci->pvt_info;
  535. return sprintf(data, "0x%08x\n", pvt->inject.type);
  536. }
  537. /*
  538. * i7core_inject_inject.eccmask_store
  539. *
  540. * The type of error (UE/CE) will depend on the inject.eccmask value:
  541. * Any bits set to a 1 will flip the corresponding ECC bit
  542. * Correctable errors can be injected by flipping 1 bit or the bits within
  543. * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or
  544. * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an
  545. * uncorrectable error to be injected.
  546. */
  547. static ssize_t i7core_inject_eccmask_store(struct mem_ctl_info *mci,
  548. const char *data, size_t count)
  549. {
  550. struct i7core_pvt *pvt = mci->pvt_info;
  551. unsigned long value;
  552. int rc;
  553. if (pvt->inject.enable)
  554. disable_inject(mci);
  555. rc = strict_strtoul(data, 10, &value);
  556. if (rc < 0)
  557. return 0;
  558. pvt->inject.eccmask = (u32) value;
  559. return count;
  560. }
  561. static ssize_t i7core_inject_eccmask_show(struct mem_ctl_info *mci,
  562. char *data)
  563. {
  564. struct i7core_pvt *pvt = mci->pvt_info;
  565. return sprintf(data, "0x%08x\n", pvt->inject.eccmask);
  566. }
  567. /*
  568. * i7core_addrmatch
  569. *
  570. * The type of error (UE/CE) will depend on the inject.eccmask value:
  571. * Any bits set to a 1 will flip the corresponding ECC bit
  572. * Correctable errors can be injected by flipping 1 bit or the bits within
  573. * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or
  574. * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an
  575. * uncorrectable error to be injected.
  576. */
  577. static ssize_t i7core_inject_addrmatch_store(struct mem_ctl_info *mci,
  578. const char *data, size_t count)
  579. {
  580. struct i7core_pvt *pvt = mci->pvt_info;
  581. char *cmd, *val;
  582. long value;
  583. int rc;
  584. if (pvt->inject.enable)
  585. disable_inject(mci);
  586. do {
  587. cmd = strsep((char **) &data, ":");
  588. if (!cmd)
  589. break;
  590. val = strsep((char **) &data, " \n\t");
  591. if (!val)
  592. return cmd - data;
  593. if (!strcasecmp(val,"any"))
  594. value = -1;
  595. else {
  596. rc = strict_strtol(val, 10, &value);
  597. if ((rc < 0) || (value < 0))
  598. return cmd - data;
  599. }
  600. if (!strcasecmp(cmd,"channel")) {
  601. if (value < 3)
  602. pvt->inject.channel = value;
  603. else
  604. return cmd - data;
  605. } else if (!strcasecmp(cmd,"dimm")) {
  606. if (value < 4)
  607. pvt->inject.dimm = value;
  608. else
  609. return cmd - data;
  610. } else if (!strcasecmp(cmd,"rank")) {
  611. if (value < 4)
  612. pvt->inject.rank = value;
  613. else
  614. return cmd - data;
  615. } else if (!strcasecmp(cmd,"bank")) {
  616. if (value < 4)
  617. pvt->inject.bank = value;
  618. else
  619. return cmd - data;
  620. } else if (!strcasecmp(cmd,"page")) {
  621. if (value <= 0xffff)
  622. pvt->inject.page = value;
  623. else
  624. return cmd - data;
  625. } else if (!strcasecmp(cmd,"col") ||
  626. !strcasecmp(cmd,"column")) {
  627. if (value <= 0x3fff)
  628. pvt->inject.col = value;
  629. else
  630. return cmd - data;
  631. }
  632. } while (1);
  633. return count;
  634. }
  635. static ssize_t i7core_inject_addrmatch_show(struct mem_ctl_info *mci,
  636. char *data)
  637. {
  638. struct i7core_pvt *pvt = mci->pvt_info;
  639. char channel[4], dimm[4], bank[4], rank[4], page[7], col[7];
  640. if (pvt->inject.channel < 0)
  641. sprintf(channel, "any");
  642. else
  643. sprintf(channel, "%d", pvt->inject.channel);
  644. if (pvt->inject.dimm < 0)
  645. sprintf(dimm, "any");
  646. else
  647. sprintf(dimm, "%d", pvt->inject.dimm);
  648. if (pvt->inject.bank < 0)
  649. sprintf(bank, "any");
  650. else
  651. sprintf(bank, "%d", pvt->inject.bank);
  652. if (pvt->inject.rank < 0)
  653. sprintf(rank, "any");
  654. else
  655. sprintf(rank, "%d", pvt->inject.rank);
  656. if (pvt->inject.page < 0)
  657. sprintf(page, "any");
  658. else
  659. sprintf(page, "0x%04x", pvt->inject.page);
  660. if (pvt->inject.col < 0)
  661. sprintf(col, "any");
  662. else
  663. sprintf(col, "0x%04x", pvt->inject.col);
  664. return sprintf(data, "channel: %s\ndimm: %s\nbank: %s\n"
  665. "rank: %s\npage: %s\ncolumn: %s\n",
  666. channel, dimm, bank, rank, page, col);
  667. }
  668. /*
  669. * This routine prepares the Memory Controller for error injection.
  670. * The error will be injected when some process tries to write to the
  671. * memory that matches the given criteria.
  672. * The criteria can be set in terms of a mask where dimm, rank, bank, page
  673. * and col can be specified.
  674. * A -1 value for any of the mask items will make the MCU to ignore
  675. * that matching criteria for error injection.
  676. *
  677. * It should be noticed that the error will only happen after a write operation
  678. * on a memory that matches the condition. if REPEAT_EN is not enabled at
  679. * inject mask, then it will produce just one error. Otherwise, it will repeat
  680. * until the injectmask would be cleaned.
  681. *
  682. * FIXME: This routine assumes that MAXNUMDIMMS value of MC_MAX_DOD
  683. * is reliable enough to check if the MC is using the
  684. * three channels. However, this is not clear at the datasheet.
  685. */
  686. static ssize_t i7core_inject_enable_store(struct mem_ctl_info *mci,
  687. const char *data, size_t count)
  688. {
  689. struct i7core_pvt *pvt = mci->pvt_info;
  690. u32 injectmask;
  691. u64 mask = 0;
  692. int rc;
  693. long enable;
  694. if (!pvt->pci_ch[pvt->inject.channel][0])
  695. return 0;
  696. rc = strict_strtoul(data, 10, &enable);
  697. if ((rc < 0))
  698. return 0;
  699. if (enable) {
  700. pvt->inject.enable = 1;
  701. } else {
  702. disable_inject(mci);
  703. return count;
  704. }
  705. /* Sets pvt->inject.dimm mask */
  706. if (pvt->inject.dimm < 0)
  707. mask |= 1L << 41;
  708. else {
  709. if (pvt->channel[pvt->inject.channel].dimms > 2)
  710. mask |= (pvt->inject.dimm & 0x3L) << 35;
  711. else
  712. mask |= (pvt->inject.dimm & 0x1L) << 36;
  713. }
  714. /* Sets pvt->inject.rank mask */
  715. if (pvt->inject.rank < 0)
  716. mask |= 1L << 40;
  717. else {
  718. if (pvt->channel[pvt->inject.channel].dimms > 2)
  719. mask |= (pvt->inject.rank & 0x1L) << 34;
  720. else
  721. mask |= (pvt->inject.rank & 0x3L) << 34;
  722. }
  723. /* Sets pvt->inject.bank mask */
  724. if (pvt->inject.bank < 0)
  725. mask |= 1L << 39;
  726. else
  727. mask |= (pvt->inject.bank & 0x15L) << 30;
  728. /* Sets pvt->inject.page mask */
  729. if (pvt->inject.page < 0)
  730. mask |= 1L << 38;
  731. else
  732. mask |= (pvt->inject.page & 0xffffL) << 14;
  733. /* Sets pvt->inject.column mask */
  734. if (pvt->inject.col < 0)
  735. mask |= 1L << 37;
  736. else
  737. mask |= (pvt->inject.col & 0x3fffL);
  738. #if USE_QWORD
  739. pci_write_config_qword(pvt->pci_ch[pvt->inject.channel][0],
  740. MC_CHANNEL_ADDR_MATCH, mask);
  741. #else
  742. pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  743. MC_CHANNEL_ADDR_MATCH, mask);
  744. pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  745. MC_CHANNEL_ADDR_MATCH + 4, mask >> 32L);
  746. #endif
  747. #if 1
  748. #if USE_QWORD
  749. u64 rdmask;
  750. pci_read_config_qword(pvt->pci_ch[pvt->inject.channel][0],
  751. MC_CHANNEL_ADDR_MATCH, &rdmask);
  752. debugf0("Inject addr match write 0x%016llx, read: 0x%016llx\n",
  753. mask, rdmask);
  754. #else
  755. u32 rdmask1, rdmask2;
  756. pci_read_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  757. MC_CHANNEL_ADDR_MATCH, &rdmask1);
  758. pci_read_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  759. MC_CHANNEL_ADDR_MATCH + 4, &rdmask2);
  760. debugf0("Inject addr match write 0x%016llx, read: 0x%08x%08x\n",
  761. mask, rdmask1, rdmask2);
  762. #endif
  763. #endif
  764. pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  765. MC_CHANNEL_ERROR_MASK, pvt->inject.eccmask);
  766. /*
  767. * bit 0: REPEAT_EN
  768. * bits 1-2: MASK_HALF_CACHELINE
  769. * bit 3: INJECT_ECC
  770. * bit 4: INJECT_ADDR_PARITY
  771. */
  772. injectmask = (pvt->inject.type & 1) |
  773. (pvt->inject.section & 0x3) << 1 |
  774. (pvt->inject.type & 0x6) << (3 - 1);
  775. pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  776. MC_CHANNEL_ERROR_MASK, injectmask);
  777. debugf0("Error inject addr match 0x%016llx, ecc 0x%08x, inject 0x%08x\n",
  778. mask, pvt->inject.eccmask, injectmask);
  779. return count;
  780. }
  781. static ssize_t i7core_inject_enable_show(struct mem_ctl_info *mci,
  782. char *data)
  783. {
  784. struct i7core_pvt *pvt = mci->pvt_info;
  785. u32 injectmask;
  786. pci_read_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  787. MC_CHANNEL_ERROR_MASK, &injectmask);
  788. debugf0("Inject error read: 0x%018x\n", injectmask);
  789. if (injectmask & 0x0c)
  790. pvt->inject.enable = 1;
  791. return sprintf(data, "%d\n", pvt->inject.enable);
  792. }
  793. static ssize_t i7core_ce_regs_show(struct mem_ctl_info *mci, char *data)
  794. {
  795. struct i7core_pvt *pvt = mci->pvt_info;
  796. if (!pvt->ce_count_available)
  797. return sprintf(data, "unavailable\n");
  798. return sprintf(data, "dimm0: %lu\ndimm1: %lu\ndimm2: %lu\n",
  799. pvt->ce_count[0],
  800. pvt->ce_count[1],
  801. pvt->ce_count[2]);
  802. }
  803. /*
  804. * Sysfs struct
  805. */
  806. static struct mcidev_sysfs_attribute i7core_inj_attrs[] = {
  807. {
  808. .attr = {
  809. .name = "inject_section",
  810. .mode = (S_IRUGO | S_IWUSR)
  811. },
  812. .show = i7core_inject_section_show,
  813. .store = i7core_inject_section_store,
  814. }, {
  815. .attr = {
  816. .name = "inject_type",
  817. .mode = (S_IRUGO | S_IWUSR)
  818. },
  819. .show = i7core_inject_type_show,
  820. .store = i7core_inject_type_store,
  821. }, {
  822. .attr = {
  823. .name = "inject_eccmask",
  824. .mode = (S_IRUGO | S_IWUSR)
  825. },
  826. .show = i7core_inject_eccmask_show,
  827. .store = i7core_inject_eccmask_store,
  828. }, {
  829. .attr = {
  830. .name = "inject_addrmatch",
  831. .mode = (S_IRUGO | S_IWUSR)
  832. },
  833. .show = i7core_inject_addrmatch_show,
  834. .store = i7core_inject_addrmatch_store,
  835. }, {
  836. .attr = {
  837. .name = "inject_enable",
  838. .mode = (S_IRUGO | S_IWUSR)
  839. },
  840. .show = i7core_inject_enable_show,
  841. .store = i7core_inject_enable_store,
  842. }, {
  843. .attr = {
  844. .name = "corrected_error_counts",
  845. .mode = (S_IRUGO | S_IWUSR)
  846. },
  847. .show = i7core_ce_regs_show,
  848. .store = NULL,
  849. },
  850. };
  851. /****************************************************************************
  852. Device initialization routines: put/get, init/exit
  853. ****************************************************************************/
  854. /*
  855. * i7core_put_devices 'put' all the devices that we have
  856. * reserved via 'get'
  857. */
  858. static void i7core_put_devices(void)
  859. {
  860. int i;
  861. for (i = 0; i < N_DEVS; i++)
  862. pci_dev_put(pci_devs[i].pdev);
  863. }
  864. /*
  865. * i7core_get_devices Find and perform 'get' operation on the MCH's
  866. * device/functions we want to reference for this driver
  867. *
  868. * Need to 'get' device 16 func 1 and func 2
  869. */
  870. static int i7core_get_devices(void)
  871. {
  872. int rc, i;
  873. struct pci_dev *pdev = NULL;
  874. for (i = 0; i < N_DEVS; i++) {
  875. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  876. pci_devs[i].dev_id, NULL);
  877. if (likely(pdev))
  878. pci_devs[i].pdev = pdev;
  879. else {
  880. i7core_printk(KERN_ERR,
  881. "Device not found: PCI ID %04x:%04x "
  882. "(dev %d, func %d)\n",
  883. PCI_VENDOR_ID_INTEL, pci_devs[i].dev_id,
  884. pci_devs[i].dev,pci_devs[i].func);
  885. /* Dev 3 function 2 only exists on chips with RDIMMs */
  886. if ((pci_devs[i].dev == 3) && (pci_devs[i].func == 2))
  887. continue;
  888. /* End of list, leave */
  889. rc = -ENODEV;
  890. goto error;
  891. }
  892. /* Sanity check */
  893. if (unlikely(PCI_SLOT(pdev->devfn) != pci_devs[i].dev ||
  894. PCI_FUNC(pdev->devfn) != pci_devs[i].func)) {
  895. i7core_printk(KERN_ERR,
  896. "Device PCI ID %04x:%04x "
  897. "has fn %d.%d instead of fn %d.%d\n",
  898. PCI_VENDOR_ID_INTEL, pci_devs[i].dev_id,
  899. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
  900. pci_devs[i].dev, pci_devs[i].func);
  901. rc = -EINVAL;
  902. goto error;
  903. }
  904. /* Be sure that the device is enabled */
  905. rc = pci_enable_device(pdev);
  906. if (unlikely(rc < 0)) {
  907. i7core_printk(KERN_ERR,
  908. "Couldn't enable PCI ID %04x:%04x "
  909. "fn %d.%d\n",
  910. PCI_VENDOR_ID_INTEL, pci_devs[i].dev_id,
  911. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  912. goto error;
  913. }
  914. i7core_printk(KERN_INFO,
  915. "Registered device %0x:%0x fn %d.%d\n",
  916. PCI_VENDOR_ID_INTEL, pci_devs[i].dev_id,
  917. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  918. }
  919. return 0;
  920. error:
  921. i7core_put_devices();
  922. return -EINVAL;
  923. }
  924. static int mci_bind_devs(struct mem_ctl_info *mci)
  925. {
  926. struct i7core_pvt *pvt = mci->pvt_info;
  927. struct pci_dev *pdev;
  928. int i, func, slot;
  929. for (i = 0; i < N_DEVS; i++) {
  930. pdev = pci_devs[i].pdev;
  931. if (!pdev)
  932. continue;
  933. func = PCI_FUNC(pdev->devfn);
  934. slot = PCI_SLOT(pdev->devfn);
  935. if (slot == 3) {
  936. if (unlikely(func > MAX_MCR_FUNC))
  937. goto error;
  938. pvt->pci_mcr[func] = pdev;
  939. } else if (likely(slot >= 4 && slot < 4 + NUM_CHANS)) {
  940. if (unlikely(func > MAX_CHAN_FUNC))
  941. goto error;
  942. pvt->pci_ch[slot - 4][func] = pdev;
  943. } else
  944. goto error;
  945. debugf0("Associated fn %d.%d, dev = %p\n",
  946. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), pdev);
  947. }
  948. return 0;
  949. error:
  950. i7core_printk(KERN_ERR, "Device %d, function %d "
  951. "is out of the expected range\n",
  952. slot, func);
  953. return -EINVAL;
  954. }
  955. /****************************************************************************
  956. Error check routines
  957. ****************************************************************************/
  958. /* This function is based on the device 3 function 4 registers as described on:
  959. * Intel Xeon Processor 5500 Series Datasheet Volume 2
  960. * http://www.intel.com/Assets/PDF/datasheet/321322.pdf
  961. * also available at:
  962. * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
  963. */
  964. static void check_mc_test_err(struct mem_ctl_info *mci)
  965. {
  966. struct i7core_pvt *pvt = mci->pvt_info;
  967. u32 rcv1, rcv0;
  968. int new0, new1, new2;
  969. if (!pvt->pci_mcr[4]) {
  970. debugf0("%s MCR registers not found\n",__func__);
  971. return;
  972. }
  973. /* Corrected error reads */
  974. pci_read_config_dword(pvt->pci_mcr[4], MC_TEST_ERR_RCV1, &rcv1);
  975. pci_read_config_dword(pvt->pci_mcr[4], MC_TEST_ERR_RCV0, &rcv0);
  976. /* Store the new values */
  977. new2 = DIMM2_COR_ERR(rcv1);
  978. new1 = DIMM1_COR_ERR(rcv0);
  979. new0 = DIMM0_COR_ERR(rcv0);
  980. debugf2("%s CE rcv1=0x%08x rcv0=0x%08x, %d %d %d\n",
  981. (pvt->ce_count_available ? "UPDATE" : "READ"),
  982. rcv1, rcv0, new0, new1, new2);
  983. /* Updates CE counters if it is not the first time here */
  984. if (pvt->ce_count_available) {
  985. /* Updates CE counters */
  986. int add0, add1, add2;
  987. add2 = new2 - pvt->last_ce_count[2];
  988. add1 = new1 - pvt->last_ce_count[1];
  989. add0 = new0 - pvt->last_ce_count[0];
  990. if (add2 < 0)
  991. add2 += 0x7fff;
  992. pvt->ce_count[2] += add2;
  993. if (add1 < 0)
  994. add1 += 0x7fff;
  995. pvt->ce_count[1] += add1;
  996. if (add0 < 0)
  997. add0 += 0x7fff;
  998. pvt->ce_count[0] += add0;
  999. } else
  1000. pvt->ce_count_available = 1;
  1001. /* Store the new values */
  1002. pvt->last_ce_count[2] = new2;
  1003. pvt->last_ce_count[1] = new1;
  1004. pvt->last_ce_count[0] = new0;
  1005. }
  1006. /*
  1007. * i7core_check_error Retrieve and process errors reported by the
  1008. * hardware. Called by the Core module.
  1009. */
  1010. static void i7core_check_error(struct mem_ctl_info *mci)
  1011. {
  1012. check_mc_test_err(mci);
  1013. }
  1014. /*
  1015. * i7core_probe Probe for ONE instance of device to see if it is
  1016. * present.
  1017. * return:
  1018. * 0 for FOUND a device
  1019. * < 0 for error code
  1020. */
  1021. static int __devinit i7core_probe(struct pci_dev *pdev,
  1022. const struct pci_device_id *id)
  1023. {
  1024. struct mem_ctl_info *mci;
  1025. struct i7core_pvt *pvt;
  1026. int num_channels;
  1027. int num_csrows;
  1028. int dev_idx = id->driver_data;
  1029. int rc;
  1030. if (unlikely(dev_idx >= ARRAY_SIZE(i7core_devs)))
  1031. return -EINVAL;
  1032. /* get the pci devices we want to reserve for our use */
  1033. rc = i7core_get_devices();
  1034. if (unlikely(rc < 0))
  1035. return rc;
  1036. /* Check the number of active and not disabled channels */
  1037. rc = i7core_get_active_channels(&num_channels, &num_csrows);
  1038. if (unlikely (rc < 0))
  1039. goto fail0;
  1040. /* allocate a new MC control structure */
  1041. mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0);
  1042. if (unlikely (!mci)) {
  1043. rc = -ENOMEM;
  1044. goto fail0;
  1045. }
  1046. debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
  1047. mci->dev = &pdev->dev; /* record ptr to the generic device */
  1048. pvt = mci->pvt_info;
  1049. memset(pvt, 0, sizeof(*pvt));
  1050. mci->mc_idx = 0;
  1051. mci->mtype_cap = MEM_FLAG_DDR3; /* FIXME: how to handle RDDR3? */
  1052. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  1053. mci->edac_cap = EDAC_FLAG_NONE;
  1054. mci->mod_name = "i7core_edac.c";
  1055. mci->mod_ver = I7CORE_REVISION;
  1056. mci->ctl_name = i7core_devs[dev_idx].ctl_name;
  1057. mci->dev_name = pci_name(pdev);
  1058. mci->ctl_page_to_phys = NULL;
  1059. mci->mc_driver_sysfs_attributes = i7core_inj_attrs;
  1060. /* Set the function pointer to an actual operation function */
  1061. mci->edac_check = i7core_check_error;
  1062. /* Store pci devices at mci for faster access */
  1063. rc = mci_bind_devs(mci);
  1064. if (unlikely (rc < 0))
  1065. goto fail1;
  1066. /* Get dimm basic config */
  1067. get_dimm_config(mci);
  1068. /* add this new MC control structure to EDAC's list of MCs */
  1069. if (unlikely(edac_mc_add_mc(mci))) {
  1070. debugf0("MC: " __FILE__
  1071. ": %s(): failed edac_mc_add_mc()\n", __func__);
  1072. /* FIXME: perhaps some code should go here that disables error
  1073. * reporting if we just enabled it
  1074. */
  1075. rc = -EINVAL;
  1076. goto fail1;
  1077. }
  1078. /* allocating generic PCI control info */
  1079. i7core_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  1080. if (unlikely (!i7core_pci)) {
  1081. printk(KERN_WARNING
  1082. "%s(): Unable to create PCI control\n",
  1083. __func__);
  1084. printk(KERN_WARNING
  1085. "%s(): PCI error report via EDAC not setup\n",
  1086. __func__);
  1087. }
  1088. /* Default error mask is any memory */
  1089. pvt->inject.channel = 0;
  1090. pvt->inject.dimm = -1;
  1091. pvt->inject.rank = -1;
  1092. pvt->inject.bank = -1;
  1093. pvt->inject.page = -1;
  1094. pvt->inject.col = -1;
  1095. i7core_printk(KERN_INFO, "Driver loaded.\n");
  1096. return 0;
  1097. fail1:
  1098. edac_mc_free(mci);
  1099. fail0:
  1100. i7core_put_devices();
  1101. return rc;
  1102. }
  1103. /*
  1104. * i7core_remove destructor for one instance of device
  1105. *
  1106. */
  1107. static void __devexit i7core_remove(struct pci_dev *pdev)
  1108. {
  1109. struct mem_ctl_info *mci;
  1110. debugf0(__FILE__ ": %s()\n", __func__);
  1111. if (i7core_pci)
  1112. edac_pci_release_generic_ctl(i7core_pci);
  1113. mci = edac_mc_del_mc(&pdev->dev);
  1114. if (!mci)
  1115. return;
  1116. /* retrieve references to resources, and free those resources */
  1117. i7core_put_devices();
  1118. edac_mc_free(mci);
  1119. }
  1120. MODULE_DEVICE_TABLE(pci, i7core_pci_tbl);
  1121. /*
  1122. * i7core_driver pci_driver structure for this module
  1123. *
  1124. */
  1125. static struct pci_driver i7core_driver = {
  1126. .name = "i7core_edac",
  1127. .probe = i7core_probe,
  1128. .remove = __devexit_p(i7core_remove),
  1129. .id_table = i7core_pci_tbl,
  1130. };
  1131. /*
  1132. * i7core_init Module entry function
  1133. * Try to initialize this module for its devices
  1134. */
  1135. static int __init i7core_init(void)
  1136. {
  1137. int pci_rc;
  1138. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  1139. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1140. opstate_init();
  1141. pci_rc = pci_register_driver(&i7core_driver);
  1142. return (pci_rc < 0) ? pci_rc : 0;
  1143. }
  1144. /*
  1145. * i7core_exit() Module exit function
  1146. * Unregister the driver
  1147. */
  1148. static void __exit i7core_exit(void)
  1149. {
  1150. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  1151. pci_unregister_driver(&i7core_driver);
  1152. }
  1153. module_init(i7core_init);
  1154. module_exit(i7core_exit);
  1155. MODULE_LICENSE("GPL");
  1156. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
  1157. MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
  1158. MODULE_DESCRIPTION("MC Driver for Intel i7 Core memory controllers - "
  1159. I7CORE_REVISION);
  1160. module_param(edac_op_state, int, 0444);
  1161. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");