i7core_edac.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  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 NUMBANK_MASK ((1 << 8) | (1 << 7))
  94. #define NUMBANK(x) (((x) & NUMBANK_MASK) >> 7)
  95. #define NUMRANK_MASK ((1 << 6) | (1 << 5))
  96. #define NUMRANK(x) (((x) & NUMRANK_MASK) >> 5)
  97. #define NUMROW_MASK ((1 << 4) | (1 << 3))
  98. #define NUMROW(x) (((x) & NUMROW_MASK) >> 3)
  99. #define NUMCOL_MASK 3
  100. #define NUMCOL(x) ((x) & 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 maxnumdimms(struct i7core_pvt *pvt)
  223. {
  224. return (pvt->info.max_dod & 0x3) + 1;
  225. }
  226. static inline int maxnumrank(struct i7core_pvt *pvt)
  227. {
  228. static int ranks[4] = { 1, 2, 4, -EINVAL };
  229. return ranks[(pvt->info.max_dod >> 2) & 0x3];
  230. }
  231. static inline int maxnumbank(struct i7core_pvt *pvt)
  232. {
  233. static int banks[4] = { 4, 8, 16, -EINVAL };
  234. return banks[(pvt->info.max_dod >> 4) & 0x3];
  235. }
  236. static inline int maxnumrow(struct i7core_pvt *pvt)
  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[((pvt->info.max_dod >> 6) & 0x7)];
  243. }
  244. static inline int maxnumcol(struct i7core_pvt *pvt)
  245. {
  246. static int cols[8] = {
  247. 1 << 10, 1 << 11, 1 << 12, -EINVAL,
  248. };
  249. return cols[((pvt->info.max_dod >> 9) & 0x3) << 12];
  250. }
  251. /****************************************************************************
  252. Memory check routines
  253. ****************************************************************************/
  254. static int i7core_get_active_channels(int *channels)
  255. {
  256. struct pci_dev *pdev = NULL;
  257. int i;
  258. u32 status, control;
  259. *channels = 0;
  260. for (i = 0; i < N_DEVS; i++) {
  261. if (!pci_devs[i].pdev)
  262. continue;
  263. if (PCI_SLOT(pci_devs[i].pdev->devfn) == 3 &&
  264. PCI_FUNC(pci_devs[i].pdev->devfn) == 0) {
  265. pdev = pci_devs[i].pdev;
  266. break;
  267. }
  268. }
  269. if (!pdev) {
  270. i7core_printk(KERN_ERR, "Couldn't find fn 3.0!!!\n");
  271. return -ENODEV;
  272. }
  273. /* Device 3 function 0 reads */
  274. pci_read_config_dword(pdev, MC_STATUS, &status);
  275. pci_read_config_dword(pdev, MC_CONTROL, &control);
  276. for (i = 0; i < NUM_CHANS; i++) {
  277. /* Check if the channel is active */
  278. if (!(control & (1 << (8 + i))))
  279. continue;
  280. /* Check if the channel is disabled */
  281. if (status & (1 << i)) {
  282. continue;
  283. }
  284. (*channels)++;
  285. }
  286. debugf0("Number of active channels: %d\n", *channels);
  287. return 0;
  288. }
  289. static int get_dimm_config(struct mem_ctl_info *mci)
  290. {
  291. struct i7core_pvt *pvt = mci->pvt_info;
  292. struct csrow_info *csr;
  293. struct pci_dev *pdev = pvt->pci_mcr[0];
  294. int i, j, csrow = 0;
  295. enum edac_type mode;
  296. if (!pdev)
  297. return -ENODEV;
  298. /* Device 3 function 0 reads */
  299. pci_read_config_dword(pdev, MC_CONTROL, &pvt->info.mc_control);
  300. pci_read_config_dword(pdev, MC_STATUS, &pvt->info.mc_status);
  301. pci_read_config_dword(pdev, MC_MAX_DOD, &pvt->info.max_dod);
  302. pci_read_config_dword(pdev, MC_CHANNEL_MAPPER, &pvt->info.ch_map);
  303. debugf0("MC control=0x%08x status=0x%08x dod=0x%08x map=0x%08x\n",
  304. pvt->info.mc_control, pvt->info.mc_status,
  305. pvt->info.max_dod, pvt->info.ch_map);
  306. if (ECC_ENABLED(pvt)) {
  307. debugf0("ECC enabled with x%d SDCC\n", ECCx8(pvt)?8:4);
  308. if (ECCx8(pvt))
  309. mode = EDAC_S8ECD8ED;
  310. else
  311. mode = EDAC_S4ECD4ED;
  312. } else {
  313. debugf0("ECC disabled\n");
  314. mode = EDAC_NONE;
  315. }
  316. /* FIXME: need to handle the error codes */
  317. debugf0("DOD Maximum limits: DIMMS: %d, %d-ranked, %d-banked\n",
  318. maxnumdimms(pvt), maxnumrank(pvt), maxnumbank(pvt));
  319. debugf0("DOD Maximum rows x colums = 0x%x x 0x%x\n",
  320. maxnumrow(pvt), maxnumcol(pvt));
  321. debugf0("Memory channel configuration:\n");
  322. for (i = 0; i < NUM_CHANS; i++) {
  323. u32 data, value[8];
  324. if (!CH_ACTIVE(pvt, i)) {
  325. debugf0("Channel %i is not active\n", i);
  326. continue;
  327. }
  328. if (CH_DISABLED(pvt, i)) {
  329. debugf0("Channel %i is disabled\n", i);
  330. continue;
  331. }
  332. /* Devices 4-6 function 0 */
  333. pci_read_config_dword(pvt->pci_ch[i][0],
  334. MC_CHANNEL_DIMM_INIT_PARAMS, &data);
  335. pvt->channel[i].ranks = (data & QUAD_RANK_PRESENT)? 4 : 2;
  336. if (data & THREE_DIMMS_PRESENT)
  337. pvt->channel[i].dimms = 3;
  338. else if (data & SINGLE_QUAD_RANK_PRESENT)
  339. pvt->channel[i].dimms = 1;
  340. else
  341. pvt->channel[i].dimms = 2;
  342. debugf0("Ch%d phy rd%d, wr%d (0x%08x): "
  343. "%d ranks, %d %cDIMMs, offset = %d\n\t"
  344. "present: %i, numbank: %#x, numrank: %#x, "
  345. "numrow: %#x, numcol: %#x\n",
  346. i,
  347. RDLCH(pvt->info.ch_map, i), WRLCH(pvt->info.ch_map, i),
  348. data,
  349. pvt->channel[i].ranks, pvt->channel[i].dimms,
  350. (data & REGISTERED_DIMM)? 'R' : 'U',
  351. RANKOFFSET(data),
  352. DIMM_PRESENT(data),
  353. NUMBANK(data), NUMRANK(data),
  354. NUMROW(data), NUMCOL(data));
  355. pci_read_config_dword(pdev, MC_SAG_CH_0, &value[0]);
  356. pci_read_config_dword(pdev, MC_SAG_CH_1, &value[1]);
  357. pci_read_config_dword(pdev, MC_SAG_CH_2, &value[2]);
  358. pci_read_config_dword(pdev, MC_SAG_CH_3, &value[3]);
  359. pci_read_config_dword(pdev, MC_SAG_CH_4, &value[4]);
  360. pci_read_config_dword(pdev, MC_SAG_CH_5, &value[5]);
  361. pci_read_config_dword(pdev, MC_SAG_CH_6, &value[6]);
  362. pci_read_config_dword(pdev, MC_SAG_CH_7, &value[7]);
  363. printk("\t[%i] DIVBY3\tREMOVED\tOFFSET\n", i);
  364. for (j = 0; j < 8; j++)
  365. printk("\t\t%#x\t%#x\t%#x\n",
  366. (value[j] >> 27) & 0x1,
  367. (value[j] >> 24) & 0x7,
  368. (value[j] && ((1 << 24) - 1)));
  369. csr = &mci->csrows[csrow];
  370. csr->first_page = 0;
  371. csr->last_page = 0;
  372. csr->page_mask = 0;
  373. csr->nr_pages = 0;
  374. csr->grain = 0;
  375. csr->csrow_idx = csrow;
  376. csr->dtype = DEV_X8; /* FIXME: check this */
  377. if (data & REGISTERED_DIMM)
  378. csr->mtype = MEM_RDDR3;
  379. else
  380. csr->mtype = MEM_DDR3;
  381. csr->edac_mode = mode;
  382. csrow++;
  383. }
  384. return 0;
  385. }
  386. /****************************************************************************
  387. Error insertion routines
  388. ****************************************************************************/
  389. /* The i7core has independent error injection features per channel.
  390. However, to have a simpler code, we don't allow enabling error injection
  391. on more than one channel.
  392. Also, since a change at an inject parameter will be applied only at enable,
  393. we're disabling error injection on all write calls to the sysfs nodes that
  394. controls the error code injection.
  395. */
  396. static int disable_inject(struct mem_ctl_info *mci)
  397. {
  398. struct i7core_pvt *pvt = mci->pvt_info;
  399. pvt->inject.enable = 0;
  400. if (!pvt->pci_ch[pvt->inject.channel][0])
  401. return -ENODEV;
  402. pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  403. MC_CHANNEL_ERROR_MASK, 0);
  404. return 0;
  405. }
  406. /*
  407. * i7core inject inject.section
  408. *
  409. * accept and store error injection inject.section value
  410. * bit 0 - refers to the lower 32-byte half cacheline
  411. * bit 1 - refers to the upper 32-byte half cacheline
  412. */
  413. static ssize_t i7core_inject_section_store(struct mem_ctl_info *mci,
  414. const char *data, size_t count)
  415. {
  416. struct i7core_pvt *pvt = mci->pvt_info;
  417. unsigned long value;
  418. int rc;
  419. if (pvt->inject.enable)
  420. disable_inject(mci);
  421. rc = strict_strtoul(data, 10, &value);
  422. if ((rc < 0) || (value > 3))
  423. return 0;
  424. pvt->inject.section = (u32) value;
  425. return count;
  426. }
  427. static ssize_t i7core_inject_section_show(struct mem_ctl_info *mci,
  428. char *data)
  429. {
  430. struct i7core_pvt *pvt = mci->pvt_info;
  431. return sprintf(data, "0x%08x\n", pvt->inject.section);
  432. }
  433. /*
  434. * i7core inject.type
  435. *
  436. * accept and store error injection inject.section value
  437. * bit 0 - repeat enable - Enable error repetition
  438. * bit 1 - inject ECC error
  439. * bit 2 - inject parity error
  440. */
  441. static ssize_t i7core_inject_type_store(struct mem_ctl_info *mci,
  442. const char *data, size_t count)
  443. {
  444. struct i7core_pvt *pvt = mci->pvt_info;
  445. unsigned long value;
  446. int rc;
  447. if (pvt->inject.enable)
  448. disable_inject(mci);
  449. rc = strict_strtoul(data, 10, &value);
  450. if ((rc < 0) || (value > 7))
  451. return 0;
  452. pvt->inject.type = (u32) value;
  453. return count;
  454. }
  455. static ssize_t i7core_inject_type_show(struct mem_ctl_info *mci,
  456. char *data)
  457. {
  458. struct i7core_pvt *pvt = mci->pvt_info;
  459. return sprintf(data, "0x%08x\n", pvt->inject.type);
  460. }
  461. /*
  462. * i7core_inject_inject.eccmask_store
  463. *
  464. * The type of error (UE/CE) will depend on the inject.eccmask value:
  465. * Any bits set to a 1 will flip the corresponding ECC bit
  466. * Correctable errors can be injected by flipping 1 bit or the bits within
  467. * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or
  468. * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an
  469. * uncorrectable error to be injected.
  470. */
  471. static ssize_t i7core_inject_eccmask_store(struct mem_ctl_info *mci,
  472. const char *data, size_t count)
  473. {
  474. struct i7core_pvt *pvt = mci->pvt_info;
  475. unsigned long value;
  476. int rc;
  477. if (pvt->inject.enable)
  478. disable_inject(mci);
  479. rc = strict_strtoul(data, 10, &value);
  480. if (rc < 0)
  481. return 0;
  482. pvt->inject.eccmask = (u32) value;
  483. return count;
  484. }
  485. static ssize_t i7core_inject_eccmask_show(struct mem_ctl_info *mci,
  486. char *data)
  487. {
  488. struct i7core_pvt *pvt = mci->pvt_info;
  489. return sprintf(data, "0x%08x\n", pvt->inject.eccmask);
  490. }
  491. /*
  492. * i7core_addrmatch
  493. *
  494. * The type of error (UE/CE) will depend on the inject.eccmask value:
  495. * Any bits set to a 1 will flip the corresponding ECC bit
  496. * Correctable errors can be injected by flipping 1 bit or the bits within
  497. * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or
  498. * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an
  499. * uncorrectable error to be injected.
  500. */
  501. static ssize_t i7core_inject_addrmatch_store(struct mem_ctl_info *mci,
  502. const char *data, size_t count)
  503. {
  504. struct i7core_pvt *pvt = mci->pvt_info;
  505. char *cmd, *val;
  506. long value;
  507. int rc;
  508. if (pvt->inject.enable)
  509. disable_inject(mci);
  510. do {
  511. cmd = strsep((char **) &data, ":");
  512. if (!cmd)
  513. break;
  514. val = strsep((char **) &data, " \n\t");
  515. if (!val)
  516. return cmd - data;
  517. if (!strcasecmp(val,"any"))
  518. value = -1;
  519. else {
  520. rc = strict_strtol(val, 10, &value);
  521. if ((rc < 0) || (value < 0))
  522. return cmd - data;
  523. }
  524. if (!strcasecmp(cmd,"channel")) {
  525. if (value < 3)
  526. pvt->inject.channel = value;
  527. else
  528. return cmd - data;
  529. } else if (!strcasecmp(cmd,"dimm")) {
  530. if (value < 4)
  531. pvt->inject.dimm = value;
  532. else
  533. return cmd - data;
  534. } else if (!strcasecmp(cmd,"rank")) {
  535. if (value < 4)
  536. pvt->inject.rank = value;
  537. else
  538. return cmd - data;
  539. } else if (!strcasecmp(cmd,"bank")) {
  540. if (value < 4)
  541. pvt->inject.bank = value;
  542. else
  543. return cmd - data;
  544. } else if (!strcasecmp(cmd,"page")) {
  545. if (value <= 0xffff)
  546. pvt->inject.page = value;
  547. else
  548. return cmd - data;
  549. } else if (!strcasecmp(cmd,"col") ||
  550. !strcasecmp(cmd,"column")) {
  551. if (value <= 0x3fff)
  552. pvt->inject.col = value;
  553. else
  554. return cmd - data;
  555. }
  556. } while (1);
  557. return count;
  558. }
  559. static ssize_t i7core_inject_addrmatch_show(struct mem_ctl_info *mci,
  560. char *data)
  561. {
  562. struct i7core_pvt *pvt = mci->pvt_info;
  563. char channel[4], dimm[4], bank[4], rank[4], page[7], col[7];
  564. if (pvt->inject.channel < 0)
  565. sprintf(channel, "any");
  566. else
  567. sprintf(channel, "%d", pvt->inject.channel);
  568. if (pvt->inject.dimm < 0)
  569. sprintf(dimm, "any");
  570. else
  571. sprintf(dimm, "%d", pvt->inject.dimm);
  572. if (pvt->inject.bank < 0)
  573. sprintf(bank, "any");
  574. else
  575. sprintf(bank, "%d", pvt->inject.bank);
  576. if (pvt->inject.rank < 0)
  577. sprintf(rank, "any");
  578. else
  579. sprintf(rank, "%d", pvt->inject.rank);
  580. if (pvt->inject.page < 0)
  581. sprintf(page, "any");
  582. else
  583. sprintf(page, "0x%04x", pvt->inject.page);
  584. if (pvt->inject.col < 0)
  585. sprintf(col, "any");
  586. else
  587. sprintf(col, "0x%04x", pvt->inject.col);
  588. return sprintf(data, "channel: %s\ndimm: %s\nbank: %s\n"
  589. "rank: %s\npage: %s\ncolumn: %s\n",
  590. channel, dimm, bank, rank, page, col);
  591. }
  592. /*
  593. * This routine prepares the Memory Controller for error injection.
  594. * The error will be injected when some process tries to write to the
  595. * memory that matches the given criteria.
  596. * The criteria can be set in terms of a mask where dimm, rank, bank, page
  597. * and col can be specified.
  598. * A -1 value for any of the mask items will make the MCU to ignore
  599. * that matching criteria for error injection.
  600. *
  601. * It should be noticed that the error will only happen after a write operation
  602. * on a memory that matches the condition. if REPEAT_EN is not enabled at
  603. * inject mask, then it will produce just one error. Otherwise, it will repeat
  604. * until the injectmask would be cleaned.
  605. *
  606. * FIXME: This routine assumes that MAXNUMDIMMS value of MC_MAX_DOD
  607. * is reliable enough to check if the MC is using the
  608. * three channels. However, this is not clear at the datasheet.
  609. */
  610. static ssize_t i7core_inject_enable_store(struct mem_ctl_info *mci,
  611. const char *data, size_t count)
  612. {
  613. struct i7core_pvt *pvt = mci->pvt_info;
  614. u32 injectmask;
  615. u64 mask = 0;
  616. int rc;
  617. long enable;
  618. if (!pvt->pci_ch[pvt->inject.channel][0])
  619. return 0;
  620. rc = strict_strtoul(data, 10, &enable);
  621. if ((rc < 0))
  622. return 0;
  623. if (enable) {
  624. pvt->inject.enable = 1;
  625. } else {
  626. disable_inject(mci);
  627. return count;
  628. }
  629. /* Sets pvt->inject.dimm mask */
  630. if (pvt->inject.dimm < 0)
  631. mask |= 1L << 41;
  632. else {
  633. if (pvt->channel[pvt->inject.channel].dimms > 2)
  634. mask |= (pvt->inject.dimm & 0x3L) << 35;
  635. else
  636. mask |= (pvt->inject.dimm & 0x1L) << 36;
  637. }
  638. /* Sets pvt->inject.rank mask */
  639. if (pvt->inject.rank < 0)
  640. mask |= 1L << 40;
  641. else {
  642. if (pvt->channel[pvt->inject.channel].dimms > 2)
  643. mask |= (pvt->inject.rank & 0x1L) << 34;
  644. else
  645. mask |= (pvt->inject.rank & 0x3L) << 34;
  646. }
  647. /* Sets pvt->inject.bank mask */
  648. if (pvt->inject.bank < 0)
  649. mask |= 1L << 39;
  650. else
  651. mask |= (pvt->inject.bank & 0x15L) << 30;
  652. /* Sets pvt->inject.page mask */
  653. if (pvt->inject.page < 0)
  654. mask |= 1L << 38;
  655. else
  656. mask |= (pvt->inject.page & 0xffffL) << 14;
  657. /* Sets pvt->inject.column mask */
  658. if (pvt->inject.col < 0)
  659. mask |= 1L << 37;
  660. else
  661. mask |= (pvt->inject.col & 0x3fffL);
  662. #if USE_QWORD
  663. pci_write_config_qword(pvt->pci_ch[pvt->inject.channel][0],
  664. MC_CHANNEL_ADDR_MATCH, mask);
  665. #else
  666. pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  667. MC_CHANNEL_ADDR_MATCH, mask);
  668. pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  669. MC_CHANNEL_ADDR_MATCH + 4, mask >> 32L);
  670. #endif
  671. #if 1
  672. #if USE_QWORD
  673. u64 rdmask;
  674. pci_read_config_qword(pvt->pci_ch[pvt->inject.channel][0],
  675. MC_CHANNEL_ADDR_MATCH, &rdmask);
  676. debugf0("Inject addr match write 0x%016llx, read: 0x%016llx\n",
  677. mask, rdmask);
  678. #else
  679. u32 rdmask1, rdmask2;
  680. pci_read_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  681. MC_CHANNEL_ADDR_MATCH, &rdmask1);
  682. pci_read_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  683. MC_CHANNEL_ADDR_MATCH + 4, &rdmask2);
  684. debugf0("Inject addr match write 0x%016llx, read: 0x%08x%08x\n",
  685. mask, rdmask1, rdmask2);
  686. #endif
  687. #endif
  688. pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  689. MC_CHANNEL_ERROR_MASK, pvt->inject.eccmask);
  690. /*
  691. * bit 0: REPEAT_EN
  692. * bits 1-2: MASK_HALF_CACHELINE
  693. * bit 3: INJECT_ECC
  694. * bit 4: INJECT_ADDR_PARITY
  695. */
  696. injectmask = (pvt->inject.type & 1) |
  697. (pvt->inject.section & 0x3) << 1 |
  698. (pvt->inject.type & 0x6) << (3 - 1);
  699. pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  700. MC_CHANNEL_ERROR_MASK, injectmask);
  701. debugf0("Error inject addr match 0x%016llx, ecc 0x%08x, inject 0x%08x\n",
  702. mask, pvt->inject.eccmask, injectmask);
  703. return count;
  704. }
  705. static ssize_t i7core_inject_enable_show(struct mem_ctl_info *mci,
  706. char *data)
  707. {
  708. struct i7core_pvt *pvt = mci->pvt_info;
  709. u32 injectmask;
  710. pci_read_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  711. MC_CHANNEL_ERROR_MASK, &injectmask);
  712. debugf0("Inject error read: 0x%018x\n", injectmask);
  713. if (injectmask & 0x0c)
  714. pvt->inject.enable = 1;
  715. return sprintf(data, "%d\n", pvt->inject.enable);
  716. }
  717. static ssize_t i7core_ce_regs_show(struct mem_ctl_info *mci, char *data)
  718. {
  719. struct i7core_pvt *pvt = mci->pvt_info;
  720. if (!pvt->ce_count_available)
  721. return sprintf(data, "unavailable\n");
  722. return sprintf(data, "dimm0: %lu\ndimm1: %lu\ndimm2: %lu\n",
  723. pvt->ce_count[0],
  724. pvt->ce_count[1],
  725. pvt->ce_count[2]);
  726. }
  727. /*
  728. * Sysfs struct
  729. */
  730. static struct mcidev_sysfs_attribute i7core_inj_attrs[] = {
  731. {
  732. .attr = {
  733. .name = "inject_section",
  734. .mode = (S_IRUGO | S_IWUSR)
  735. },
  736. .show = i7core_inject_section_show,
  737. .store = i7core_inject_section_store,
  738. }, {
  739. .attr = {
  740. .name = "inject_type",
  741. .mode = (S_IRUGO | S_IWUSR)
  742. },
  743. .show = i7core_inject_type_show,
  744. .store = i7core_inject_type_store,
  745. }, {
  746. .attr = {
  747. .name = "inject_eccmask",
  748. .mode = (S_IRUGO | S_IWUSR)
  749. },
  750. .show = i7core_inject_eccmask_show,
  751. .store = i7core_inject_eccmask_store,
  752. }, {
  753. .attr = {
  754. .name = "inject_addrmatch",
  755. .mode = (S_IRUGO | S_IWUSR)
  756. },
  757. .show = i7core_inject_addrmatch_show,
  758. .store = i7core_inject_addrmatch_store,
  759. }, {
  760. .attr = {
  761. .name = "inject_enable",
  762. .mode = (S_IRUGO | S_IWUSR)
  763. },
  764. .show = i7core_inject_enable_show,
  765. .store = i7core_inject_enable_store,
  766. }, {
  767. .attr = {
  768. .name = "corrected_error_counts",
  769. .mode = (S_IRUGO | S_IWUSR)
  770. },
  771. .show = i7core_ce_regs_show,
  772. .store = NULL,
  773. },
  774. };
  775. /****************************************************************************
  776. Device initialization routines: put/get, init/exit
  777. ****************************************************************************/
  778. /*
  779. * i7core_put_devices 'put' all the devices that we have
  780. * reserved via 'get'
  781. */
  782. static void i7core_put_devices(void)
  783. {
  784. int i;
  785. for (i = 0; i < N_DEVS; i++)
  786. pci_dev_put(pci_devs[i].pdev);
  787. }
  788. /*
  789. * i7core_get_devices Find and perform 'get' operation on the MCH's
  790. * device/functions we want to reference for this driver
  791. *
  792. * Need to 'get' device 16 func 1 and func 2
  793. */
  794. static int i7core_get_devices(void)
  795. {
  796. int rc, i;
  797. struct pci_dev *pdev = NULL;
  798. for (i = 0; i < N_DEVS; i++) {
  799. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  800. pci_devs[i].dev_id, NULL);
  801. if (likely(pdev))
  802. pci_devs[i].pdev = pdev;
  803. else {
  804. i7core_printk(KERN_ERR,
  805. "Device not found: PCI ID %04x:%04x "
  806. "(dev %d, func %d)\n",
  807. PCI_VENDOR_ID_INTEL, pci_devs[i].dev_id,
  808. pci_devs[i].dev,pci_devs[i].func);
  809. /* Dev 3 function 2 only exists on chips with RDIMMs */
  810. if ((pci_devs[i].dev == 3) && (pci_devs[i].func == 2))
  811. continue;
  812. /* End of list, leave */
  813. rc = -ENODEV;
  814. goto error;
  815. }
  816. /* Sanity check */
  817. if (unlikely(PCI_SLOT(pdev->devfn) != pci_devs[i].dev ||
  818. PCI_FUNC(pdev->devfn) != pci_devs[i].func)) {
  819. i7core_printk(KERN_ERR,
  820. "Device PCI ID %04x:%04x "
  821. "has fn %d.%d instead of fn %d.%d\n",
  822. PCI_VENDOR_ID_INTEL, pci_devs[i].dev_id,
  823. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
  824. pci_devs[i].dev, pci_devs[i].func);
  825. rc = -EINVAL;
  826. goto error;
  827. }
  828. /* Be sure that the device is enabled */
  829. rc = pci_enable_device(pdev);
  830. if (unlikely(rc < 0)) {
  831. i7core_printk(KERN_ERR,
  832. "Couldn't enable PCI ID %04x:%04x "
  833. "fn %d.%d\n",
  834. PCI_VENDOR_ID_INTEL, pci_devs[i].dev_id,
  835. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  836. goto error;
  837. }
  838. i7core_printk(KERN_INFO,
  839. "Registered device %0x:%0x fn %d.%d\n",
  840. PCI_VENDOR_ID_INTEL, pci_devs[i].dev_id,
  841. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  842. }
  843. return 0;
  844. error:
  845. i7core_put_devices();
  846. return -EINVAL;
  847. }
  848. static int mci_bind_devs(struct mem_ctl_info *mci)
  849. {
  850. struct i7core_pvt *pvt = mci->pvt_info;
  851. struct pci_dev *pdev;
  852. int i, func, slot;
  853. for (i = 0; i < N_DEVS; i++) {
  854. pdev = pci_devs[i].pdev;
  855. if (!pdev)
  856. continue;
  857. func = PCI_FUNC(pdev->devfn);
  858. slot = PCI_SLOT(pdev->devfn);
  859. if (slot == 3) {
  860. if (unlikely(func > MAX_MCR_FUNC))
  861. goto error;
  862. pvt->pci_mcr[func] = pdev;
  863. } else if (likely(slot >= 4 && slot < 4 + NUM_CHANS)) {
  864. if (unlikely(func > MAX_CHAN_FUNC))
  865. goto error;
  866. pvt->pci_ch[slot - 4][func] = pdev;
  867. } else
  868. goto error;
  869. debugf0("Associated fn %d.%d, dev = %p\n",
  870. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), pdev);
  871. }
  872. return 0;
  873. error:
  874. i7core_printk(KERN_ERR, "Device %d, function %d "
  875. "is out of the expected range\n",
  876. slot, func);
  877. return -EINVAL;
  878. }
  879. /****************************************************************************
  880. Error check routines
  881. ****************************************************************************/
  882. /* This function is based on the device 3 function 4 registers as described on:
  883. * Intel Xeon Processor 5500 Series Datasheet Volume 2
  884. * http://www.intel.com/Assets/PDF/datasheet/321322.pdf
  885. * also available at:
  886. * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
  887. */
  888. static void check_mc_test_err(struct mem_ctl_info *mci)
  889. {
  890. struct i7core_pvt *pvt = mci->pvt_info;
  891. u32 rcv1, rcv0;
  892. int new0, new1, new2;
  893. if (!pvt->pci_mcr[4]) {
  894. debugf0("%s MCR registers not found\n",__func__);
  895. return;
  896. }
  897. /* Corrected error reads */
  898. pci_read_config_dword(pvt->pci_mcr[4], MC_TEST_ERR_RCV1, &rcv1);
  899. pci_read_config_dword(pvt->pci_mcr[4], MC_TEST_ERR_RCV0, &rcv0);
  900. /* Store the new values */
  901. new2 = DIMM2_COR_ERR(rcv1);
  902. new1 = DIMM1_COR_ERR(rcv0);
  903. new0 = DIMM0_COR_ERR(rcv0);
  904. debugf2("%s CE rcv1=0x%08x rcv0=0x%08x, %d %d %d\n",
  905. (pvt->ce_count_available ? "UPDATE" : "READ"),
  906. rcv1, rcv0, new0, new1, new2);
  907. /* Updates CE counters if it is not the first time here */
  908. if (pvt->ce_count_available) {
  909. /* Updates CE counters */
  910. int add0, add1, add2;
  911. add2 = new2 - pvt->last_ce_count[2];
  912. add1 = new1 - pvt->last_ce_count[1];
  913. add0 = new0 - pvt->last_ce_count[0];
  914. if (add2 < 0)
  915. add2 += 0x7fff;
  916. pvt->ce_count[2] += add2;
  917. if (add1 < 0)
  918. add1 += 0x7fff;
  919. pvt->ce_count[1] += add1;
  920. if (add0 < 0)
  921. add0 += 0x7fff;
  922. pvt->ce_count[0] += add0;
  923. } else
  924. pvt->ce_count_available = 1;
  925. /* Store the new values */
  926. pvt->last_ce_count[2] = new2;
  927. pvt->last_ce_count[1] = new1;
  928. pvt->last_ce_count[0] = new0;
  929. }
  930. /*
  931. * i7core_check_error Retrieve and process errors reported by the
  932. * hardware. Called by the Core module.
  933. */
  934. static void i7core_check_error(struct mem_ctl_info *mci)
  935. {
  936. check_mc_test_err(mci);
  937. }
  938. /*
  939. * i7core_probe Probe for ONE instance of device to see if it is
  940. * present.
  941. * return:
  942. * 0 for FOUND a device
  943. * < 0 for error code
  944. */
  945. static int __devinit i7core_probe(struct pci_dev *pdev,
  946. const struct pci_device_id *id)
  947. {
  948. struct mem_ctl_info *mci;
  949. struct i7core_pvt *pvt;
  950. int num_channels = 0;
  951. int num_csrows;
  952. int dev_idx = id->driver_data;
  953. int rc;
  954. if (unlikely(dev_idx >= ARRAY_SIZE(i7core_devs)))
  955. return -EINVAL;
  956. /* get the pci devices we want to reserve for our use */
  957. rc = i7core_get_devices();
  958. if (unlikely(rc < 0))
  959. return rc;
  960. /* Check the number of active and not disabled channels */
  961. rc = i7core_get_active_channels(&num_channels);
  962. if (unlikely (rc < 0))
  963. goto fail0;
  964. /* FIXME: we currently don't know the number of csrows */
  965. num_csrows = num_channels;
  966. /* allocate a new MC control structure */
  967. mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0);
  968. if (unlikely (!mci)) {
  969. rc = -ENOMEM;
  970. goto fail0;
  971. }
  972. debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
  973. mci->dev = &pdev->dev; /* record ptr to the generic device */
  974. pvt = mci->pvt_info;
  975. memset(pvt, 0, sizeof(*pvt));
  976. mci->mc_idx = 0;
  977. mci->mtype_cap = MEM_FLAG_DDR3; /* FIXME: how to handle RDDR3? */
  978. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  979. mci->edac_cap = EDAC_FLAG_NONE;
  980. mci->mod_name = "i7core_edac.c";
  981. mci->mod_ver = I7CORE_REVISION;
  982. mci->ctl_name = i7core_devs[dev_idx].ctl_name;
  983. mci->dev_name = pci_name(pdev);
  984. mci->ctl_page_to_phys = NULL;
  985. mci->mc_driver_sysfs_attributes = i7core_inj_attrs;
  986. /* Set the function pointer to an actual operation function */
  987. mci->edac_check = i7core_check_error;
  988. /* Store pci devices at mci for faster access */
  989. rc = mci_bind_devs(mci);
  990. if (unlikely (rc < 0))
  991. goto fail1;
  992. /* Get dimm basic config */
  993. get_dimm_config(mci);
  994. /* add this new MC control structure to EDAC's list of MCs */
  995. if (unlikely(edac_mc_add_mc(mci))) {
  996. debugf0("MC: " __FILE__
  997. ": %s(): failed edac_mc_add_mc()\n", __func__);
  998. /* FIXME: perhaps some code should go here that disables error
  999. * reporting if we just enabled it
  1000. */
  1001. rc = -EINVAL;
  1002. goto fail1;
  1003. }
  1004. /* allocating generic PCI control info */
  1005. i7core_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  1006. if (unlikely (!i7core_pci)) {
  1007. printk(KERN_WARNING
  1008. "%s(): Unable to create PCI control\n",
  1009. __func__);
  1010. printk(KERN_WARNING
  1011. "%s(): PCI error report via EDAC not setup\n",
  1012. __func__);
  1013. }
  1014. /* Default error mask is any memory */
  1015. pvt->inject.channel = 0;
  1016. pvt->inject.dimm = -1;
  1017. pvt->inject.rank = -1;
  1018. pvt->inject.bank = -1;
  1019. pvt->inject.page = -1;
  1020. pvt->inject.col = -1;
  1021. i7core_printk(KERN_INFO, "Driver loaded.\n");
  1022. return 0;
  1023. fail1:
  1024. edac_mc_free(mci);
  1025. fail0:
  1026. i7core_put_devices();
  1027. return rc;
  1028. }
  1029. /*
  1030. * i7core_remove destructor for one instance of device
  1031. *
  1032. */
  1033. static void __devexit i7core_remove(struct pci_dev *pdev)
  1034. {
  1035. struct mem_ctl_info *mci;
  1036. debugf0(__FILE__ ": %s()\n", __func__);
  1037. if (i7core_pci)
  1038. edac_pci_release_generic_ctl(i7core_pci);
  1039. mci = edac_mc_del_mc(&pdev->dev);
  1040. if (!mci)
  1041. return;
  1042. /* retrieve references to resources, and free those resources */
  1043. i7core_put_devices();
  1044. edac_mc_free(mci);
  1045. }
  1046. MODULE_DEVICE_TABLE(pci, i7core_pci_tbl);
  1047. /*
  1048. * i7core_driver pci_driver structure for this module
  1049. *
  1050. */
  1051. static struct pci_driver i7core_driver = {
  1052. .name = "i7core_edac",
  1053. .probe = i7core_probe,
  1054. .remove = __devexit_p(i7core_remove),
  1055. .id_table = i7core_pci_tbl,
  1056. };
  1057. /*
  1058. * i7core_init Module entry function
  1059. * Try to initialize this module for its devices
  1060. */
  1061. static int __init i7core_init(void)
  1062. {
  1063. int pci_rc;
  1064. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  1065. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1066. opstate_init();
  1067. pci_rc = pci_register_driver(&i7core_driver);
  1068. return (pci_rc < 0) ? pci_rc : 0;
  1069. }
  1070. /*
  1071. * i7core_exit() Module exit function
  1072. * Unregister the driver
  1073. */
  1074. static void __exit i7core_exit(void)
  1075. {
  1076. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  1077. pci_unregister_driver(&i7core_driver);
  1078. }
  1079. module_init(i7core_init);
  1080. module_exit(i7core_exit);
  1081. MODULE_LICENSE("GPL");
  1082. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
  1083. MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
  1084. MODULE_DESCRIPTION("MC Driver for Intel i7 Core memory controllers - "
  1085. I7CORE_REVISION);
  1086. module_param(edac_op_state, int, 0444);
  1087. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");