i7core_edac.c 34 KB

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