i7core_edac.c 34 KB

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