i7core_edac.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923
  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 <linux/edac_mce.h>
  30. #include <linux/spinlock.h>
  31. #include "edac_core.h"
  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. /*
  38. * Debug macros
  39. */
  40. #define i7core_printk(level, fmt, arg...) \
  41. edac_printk(level, "i7core", fmt, ##arg)
  42. #define i7core_mc_printk(mci, level, fmt, arg...) \
  43. edac_mc_chipset_printk(mci, level, "i7core", fmt, ##arg)
  44. /*
  45. * i7core Memory Controller Registers
  46. */
  47. /* OFFSETS for Device 0 Function 0 */
  48. #define MC_CFG_CONTROL 0x90
  49. /* OFFSETS for Device 3 Function 0 */
  50. #define MC_CONTROL 0x48
  51. #define MC_STATUS 0x4c
  52. #define MC_MAX_DOD 0x64
  53. /*
  54. * OFFSETS for Device 3 Function 4, as inicated on Xeon 5500 datasheet:
  55. * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
  56. */
  57. #define MC_TEST_ERR_RCV1 0x60
  58. #define DIMM2_COR_ERR(r) ((r) & 0x7fff)
  59. #define MC_TEST_ERR_RCV0 0x64
  60. #define DIMM1_COR_ERR(r) (((r) >> 16) & 0x7fff)
  61. #define DIMM0_COR_ERR(r) ((r) & 0x7fff)
  62. /* OFFSETS for Device 3 Function 2, as inicated on Xeon 5500 datasheet */
  63. #define MC_COR_ECC_CNT_0 0x80
  64. #define MC_COR_ECC_CNT_1 0x84
  65. #define MC_COR_ECC_CNT_2 0x88
  66. #define MC_COR_ECC_CNT_3 0x8c
  67. #define MC_COR_ECC_CNT_4 0x90
  68. #define MC_COR_ECC_CNT_5 0x94
  69. #define DIMM_TOP_COR_ERR(r) (((r) >> 16) & 0x7fff)
  70. #define DIMM_BOT_COR_ERR(r) ((r) & 0x7fff)
  71. /* OFFSETS for Devices 4,5 and 6 Function 0 */
  72. #define MC_CHANNEL_DIMM_INIT_PARAMS 0x58
  73. #define THREE_DIMMS_PRESENT (1 << 24)
  74. #define SINGLE_QUAD_RANK_PRESENT (1 << 23)
  75. #define QUAD_RANK_PRESENT (1 << 22)
  76. #define REGISTERED_DIMM (1 << 15)
  77. #define MC_CHANNEL_MAPPER 0x60
  78. #define RDLCH(r, ch) ((((r) >> (3 + (ch * 6))) & 0x07) - 1)
  79. #define WRLCH(r, ch) ((((r) >> (ch * 6)) & 0x07) - 1)
  80. #define MC_CHANNEL_RANK_PRESENT 0x7c
  81. #define RANK_PRESENT_MASK 0xffff
  82. #define MC_CHANNEL_ADDR_MATCH 0xf0
  83. #define MC_CHANNEL_ERROR_MASK 0xf8
  84. #define MC_CHANNEL_ERROR_INJECT 0xfc
  85. #define INJECT_ADDR_PARITY 0x10
  86. #define INJECT_ECC 0x08
  87. #define MASK_CACHELINE 0x06
  88. #define MASK_FULL_CACHELINE 0x06
  89. #define MASK_MSB32_CACHELINE 0x04
  90. #define MASK_LSB32_CACHELINE 0x02
  91. #define NO_MASK_CACHELINE 0x00
  92. #define REPEAT_EN 0x01
  93. /* OFFSETS for Devices 4,5 and 6 Function 1 */
  94. #define MC_DOD_CH_DIMM0 0x48
  95. #define MC_DOD_CH_DIMM1 0x4c
  96. #define MC_DOD_CH_DIMM2 0x50
  97. #define RANKOFFSET_MASK ((1 << 12) | (1 << 11) | (1 << 10))
  98. #define RANKOFFSET(x) ((x & RANKOFFSET_MASK) >> 10)
  99. #define DIMM_PRESENT_MASK (1 << 9)
  100. #define DIMM_PRESENT(x) (((x) & DIMM_PRESENT_MASK) >> 9)
  101. #define MC_DOD_NUMBANK_MASK ((1 << 8) | (1 << 7))
  102. #define MC_DOD_NUMBANK(x) (((x) & MC_DOD_NUMBANK_MASK) >> 7)
  103. #define MC_DOD_NUMRANK_MASK ((1 << 6) | (1 << 5))
  104. #define MC_DOD_NUMRANK(x) (((x) & MC_DOD_NUMRANK_MASK) >> 5)
  105. #define MC_DOD_NUMROW_MASK ((1 << 4) | (1 << 3) | (1 << 2))
  106. #define MC_DOD_NUMROW(x) (((x) & MC_DOD_NUMROW_MASK) >> 2)
  107. #define MC_DOD_NUMCOL_MASK 3
  108. #define MC_DOD_NUMCOL(x) ((x) & MC_DOD_NUMCOL_MASK)
  109. #define MC_RANK_PRESENT 0x7c
  110. #define MC_SAG_CH_0 0x80
  111. #define MC_SAG_CH_1 0x84
  112. #define MC_SAG_CH_2 0x88
  113. #define MC_SAG_CH_3 0x8c
  114. #define MC_SAG_CH_4 0x90
  115. #define MC_SAG_CH_5 0x94
  116. #define MC_SAG_CH_6 0x98
  117. #define MC_SAG_CH_7 0x9c
  118. #define MC_RIR_LIMIT_CH_0 0x40
  119. #define MC_RIR_LIMIT_CH_1 0x44
  120. #define MC_RIR_LIMIT_CH_2 0x48
  121. #define MC_RIR_LIMIT_CH_3 0x4C
  122. #define MC_RIR_LIMIT_CH_4 0x50
  123. #define MC_RIR_LIMIT_CH_5 0x54
  124. #define MC_RIR_LIMIT_CH_6 0x58
  125. #define MC_RIR_LIMIT_CH_7 0x5C
  126. #define MC_RIR_LIMIT_MASK ((1 << 10) - 1)
  127. #define MC_RIR_WAY_CH 0x80
  128. #define MC_RIR_WAY_OFFSET_MASK (((1 << 14) - 1) & ~0x7)
  129. #define MC_RIR_WAY_RANK_MASK 0x7
  130. /*
  131. * i7core structs
  132. */
  133. #define NUM_CHANS 3
  134. #define MAX_DIMMS 3 /* Max DIMMS per channel */
  135. #define NUM_SOCKETS 2 /* Max number of MC sockets */
  136. #define MAX_MCR_FUNC 4
  137. #define MAX_CHAN_FUNC 3
  138. struct i7core_info {
  139. u32 mc_control;
  140. u32 mc_status;
  141. u32 max_dod;
  142. u32 ch_map;
  143. };
  144. struct i7core_inject {
  145. int enable;
  146. u8 socket;
  147. u32 section;
  148. u32 type;
  149. u32 eccmask;
  150. /* Error address mask */
  151. int channel, dimm, rank, bank, page, col;
  152. };
  153. struct i7core_channel {
  154. u32 ranks;
  155. u32 dimms;
  156. };
  157. struct pci_id_descr {
  158. int dev;
  159. int func;
  160. int dev_id;
  161. struct pci_dev *pdev[NUM_SOCKETS];
  162. };
  163. struct i7core_pvt {
  164. struct pci_dev *pci_noncore[NUM_SOCKETS];
  165. struct pci_dev *pci_mcr[NUM_SOCKETS][MAX_MCR_FUNC + 1];
  166. struct pci_dev *pci_ch[NUM_SOCKETS][NUM_CHANS][MAX_CHAN_FUNC + 1];
  167. struct i7core_info info;
  168. struct i7core_inject inject;
  169. struct i7core_channel channel[NUM_SOCKETS][NUM_CHANS];
  170. unsigned int is_registered:1; /* true if all memories are RDIMMs */
  171. int sockets; /* Number of sockets */
  172. int channels; /* Number of active channels */
  173. int ce_count_available[NUM_SOCKETS];
  174. int csrow_map[NUM_SOCKETS][NUM_CHANS][MAX_DIMMS];
  175. /* ECC corrected errors counts per udimm */
  176. unsigned long udimm_ce_count[NUM_SOCKETS][MAX_DIMMS];
  177. int udimm_last_ce_count[NUM_SOCKETS][MAX_DIMMS];
  178. /* ECC corrected errors counts per rdimm */
  179. unsigned long rdimm_ce_count[NUM_SOCKETS][NUM_CHANS][MAX_DIMMS];
  180. int rdimm_last_ce_count[NUM_SOCKETS][NUM_CHANS][MAX_DIMMS];
  181. /* mcelog glue */
  182. struct edac_mce edac_mce;
  183. struct mce mce_entry[MCE_LOG_LEN];
  184. unsigned mce_count;
  185. spinlock_t mce_lock;
  186. };
  187. /* Device name and register DID (Device ID) */
  188. struct i7core_dev_info {
  189. const char *ctl_name; /* name for this device */
  190. u16 fsb_mapping_errors; /* DID for the branchmap,control */
  191. };
  192. #define PCI_DESCR(device, function, device_id) \
  193. .dev = (device), \
  194. .func = (function), \
  195. .dev_id = (device_id)
  196. struct pci_id_descr pci_devs[] = {
  197. /* Memory controller */
  198. { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_I7_MCR) },
  199. { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_I7_MC_TAD) },
  200. { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_I7_MC_RAS) }, /* if RDIMM */
  201. { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_I7_MC_TEST) },
  202. /* Channel 0 */
  203. { PCI_DESCR(4, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH0_CTRL) },
  204. { PCI_DESCR(4, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH0_ADDR) },
  205. { PCI_DESCR(4, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH0_RANK) },
  206. { PCI_DESCR(4, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH0_TC) },
  207. /* Channel 1 */
  208. { PCI_DESCR(5, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH1_CTRL) },
  209. { PCI_DESCR(5, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH1_ADDR) },
  210. { PCI_DESCR(5, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH1_RANK) },
  211. { PCI_DESCR(5, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH1_TC) },
  212. /* Channel 2 */
  213. { PCI_DESCR(6, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH2_CTRL) },
  214. { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH2_ADDR) },
  215. { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH2_RANK) },
  216. { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH2_TC) },
  217. /* Generic Non-core registers */
  218. /*
  219. * This is the PCI device on i7core and on Xeon 35xx (8086:2c41)
  220. * On Xeon 55xx, however, it has a different id (8086:2c40). So,
  221. * the probing code needs to test for the other address in case of
  222. * failure of this one
  223. */
  224. { PCI_DESCR(0, 0, PCI_DEVICE_ID_INTEL_I7_NOCORE) },
  225. };
  226. #define N_DEVS ARRAY_SIZE(pci_devs)
  227. /*
  228. * pci_device_id table for which devices we are looking for
  229. * This should match the first device at pci_devs table
  230. */
  231. static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
  232. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
  233. {0,} /* 0 terminated list. */
  234. };
  235. /* Table of devices attributes supported by this driver */
  236. static const struct i7core_dev_info i7core_devs[] = {
  237. {
  238. .ctl_name = "i7 Core",
  239. .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I7_MCR,
  240. },
  241. };
  242. static struct edac_pci_ctl_info *i7core_pci;
  243. /****************************************************************************
  244. Anciliary status routines
  245. ****************************************************************************/
  246. /* MC_CONTROL bits */
  247. #define CH_ACTIVE(pvt, ch) ((pvt)->info.mc_control & (1 << (8 + ch)))
  248. #define ECCx8(pvt) ((pvt)->info.mc_control & (1 << 1))
  249. /* MC_STATUS bits */
  250. #define ECC_ENABLED(pvt) ((pvt)->info.mc_status & (1 << 4))
  251. #define CH_DISABLED(pvt, ch) ((pvt)->info.mc_status & (1 << ch))
  252. /* MC_MAX_DOD read functions */
  253. static inline int numdimms(u32 dimms)
  254. {
  255. return (dimms & 0x3) + 1;
  256. }
  257. static inline int numrank(u32 rank)
  258. {
  259. static int ranks[4] = { 1, 2, 4, -EINVAL };
  260. return ranks[rank & 0x3];
  261. }
  262. static inline int numbank(u32 bank)
  263. {
  264. static int banks[4] = { 4, 8, 16, -EINVAL };
  265. return banks[bank & 0x3];
  266. }
  267. static inline int numrow(u32 row)
  268. {
  269. static int rows[8] = {
  270. 1 << 12, 1 << 13, 1 << 14, 1 << 15,
  271. 1 << 16, -EINVAL, -EINVAL, -EINVAL,
  272. };
  273. return rows[row & 0x7];
  274. }
  275. static inline int numcol(u32 col)
  276. {
  277. static int cols[8] = {
  278. 1 << 10, 1 << 11, 1 << 12, -EINVAL,
  279. };
  280. return cols[col & 0x3];
  281. }
  282. /****************************************************************************
  283. Memory check routines
  284. ****************************************************************************/
  285. static struct pci_dev *get_pdev_slot_func(u8 socket, unsigned slot,
  286. unsigned func)
  287. {
  288. int i;
  289. for (i = 0; i < N_DEVS; i++) {
  290. if (!pci_devs[i].pdev[socket])
  291. continue;
  292. if (PCI_SLOT(pci_devs[i].pdev[socket]->devfn) == slot &&
  293. PCI_FUNC(pci_devs[i].pdev[socket]->devfn) == func) {
  294. return pci_devs[i].pdev[socket];
  295. }
  296. }
  297. return NULL;
  298. }
  299. /**
  300. * i7core_get_active_channels() - gets the number of channels and csrows
  301. * @socket: Quick Path Interconnect socket
  302. * @channels: Number of channels that will be returned
  303. * @csrows: Number of csrows found
  304. *
  305. * Since EDAC core needs to know in advance the number of available channels
  306. * and csrows, in order to allocate memory for csrows/channels, it is needed
  307. * to run two similar steps. At the first step, implemented on this function,
  308. * it checks the number of csrows/channels present at one socket.
  309. * this is used in order to properly allocate the size of mci components.
  310. *
  311. * It should be noticed that none of the current available datasheets explain
  312. * or even mention how csrows are seen by the memory controller. So, we need
  313. * to add a fake description for csrows.
  314. * So, this driver is attributing one DIMM memory for one csrow.
  315. */
  316. static int i7core_get_active_channels(u8 socket, unsigned *channels,
  317. unsigned *csrows)
  318. {
  319. struct pci_dev *pdev = NULL;
  320. int i, j;
  321. u32 status, control;
  322. *channels = 0;
  323. *csrows = 0;
  324. pdev = get_pdev_slot_func(socket, 3, 0);
  325. if (!pdev) {
  326. i7core_printk(KERN_ERR, "Couldn't find socket %d fn 3.0!!!\n",
  327. socket);
  328. return -ENODEV;
  329. }
  330. /* Device 3 function 0 reads */
  331. pci_read_config_dword(pdev, MC_STATUS, &status);
  332. pci_read_config_dword(pdev, MC_CONTROL, &control);
  333. for (i = 0; i < NUM_CHANS; i++) {
  334. u32 dimm_dod[3];
  335. /* Check if the channel is active */
  336. if (!(control & (1 << (8 + i))))
  337. continue;
  338. /* Check if the channel is disabled */
  339. if (status & (1 << i))
  340. continue;
  341. pdev = get_pdev_slot_func(socket, i + 4, 1);
  342. if (!pdev) {
  343. i7core_printk(KERN_ERR, "Couldn't find socket %d "
  344. "fn %d.%d!!!\n",
  345. socket, i + 4, 1);
  346. return -ENODEV;
  347. }
  348. /* Devices 4-6 function 1 */
  349. pci_read_config_dword(pdev,
  350. MC_DOD_CH_DIMM0, &dimm_dod[0]);
  351. pci_read_config_dword(pdev,
  352. MC_DOD_CH_DIMM1, &dimm_dod[1]);
  353. pci_read_config_dword(pdev,
  354. MC_DOD_CH_DIMM2, &dimm_dod[2]);
  355. (*channels)++;
  356. for (j = 0; j < 3; j++) {
  357. if (!DIMM_PRESENT(dimm_dod[j]))
  358. continue;
  359. (*csrows)++;
  360. }
  361. }
  362. debugf0("Number of active channels on socket %d: %d\n",
  363. socket, *channels);
  364. return 0;
  365. }
  366. static int get_dimm_config(struct mem_ctl_info *mci, int *csrow, u8 socket)
  367. {
  368. struct i7core_pvt *pvt = mci->pvt_info;
  369. struct csrow_info *csr;
  370. struct pci_dev *pdev;
  371. int i, j;
  372. unsigned long last_page = 0;
  373. enum edac_type mode;
  374. enum mem_type mtype;
  375. /* Get data from the MC register, function 0 */
  376. pdev = pvt->pci_mcr[socket][0];
  377. if (!pdev)
  378. return -ENODEV;
  379. /* Device 3 function 0 reads */
  380. pci_read_config_dword(pdev, MC_CONTROL, &pvt->info.mc_control);
  381. pci_read_config_dword(pdev, MC_STATUS, &pvt->info.mc_status);
  382. pci_read_config_dword(pdev, MC_MAX_DOD, &pvt->info.max_dod);
  383. pci_read_config_dword(pdev, MC_CHANNEL_MAPPER, &pvt->info.ch_map);
  384. debugf0("QPI %d control=0x%08x status=0x%08x dod=0x%08x map=0x%08x\n",
  385. socket, pvt->info.mc_control, pvt->info.mc_status,
  386. pvt->info.max_dod, pvt->info.ch_map);
  387. if (ECC_ENABLED(pvt)) {
  388. debugf0("ECC enabled with x%d SDCC\n", ECCx8(pvt) ? 8 : 4);
  389. if (ECCx8(pvt))
  390. mode = EDAC_S8ECD8ED;
  391. else
  392. mode = EDAC_S4ECD4ED;
  393. } else {
  394. debugf0("ECC disabled\n");
  395. mode = EDAC_NONE;
  396. }
  397. /* FIXME: need to handle the error codes */
  398. debugf0("DOD Max limits: DIMMS: %d, %d-ranked, %d-banked "
  399. "x%x x 0x%x\n",
  400. numdimms(pvt->info.max_dod),
  401. numrank(pvt->info.max_dod >> 2),
  402. numbank(pvt->info.max_dod >> 4),
  403. numrow(pvt->info.max_dod >> 6),
  404. numcol(pvt->info.max_dod >> 9));
  405. pvt->is_registered = 1;
  406. for (i = 0; i < NUM_CHANS; i++) {
  407. u32 data, dimm_dod[3], value[8];
  408. if (!CH_ACTIVE(pvt, i)) {
  409. debugf0("Channel %i is not active\n", i);
  410. continue;
  411. }
  412. if (CH_DISABLED(pvt, i)) {
  413. debugf0("Channel %i is disabled\n", i);
  414. continue;
  415. }
  416. /* Devices 4-6 function 0 */
  417. pci_read_config_dword(pvt->pci_ch[socket][i][0],
  418. MC_CHANNEL_DIMM_INIT_PARAMS, &data);
  419. pvt->channel[socket][i].ranks = (data & QUAD_RANK_PRESENT) ?
  420. 4 : 2;
  421. if (data & REGISTERED_DIMM)
  422. mtype = MEM_RDDR3;
  423. else {
  424. mtype = MEM_DDR3;
  425. /*
  426. * FIXME: Currently, the driver will use dev 3:2
  427. * counter registers only if all memories are registered
  428. */
  429. pvt->is_registered = 0;
  430. }
  431. #if 0
  432. if (data & THREE_DIMMS_PRESENT)
  433. pvt->channel[i].dimms = 3;
  434. else if (data & SINGLE_QUAD_RANK_PRESENT)
  435. pvt->channel[i].dimms = 1;
  436. else
  437. pvt->channel[i].dimms = 2;
  438. #endif
  439. /* Devices 4-6 function 1 */
  440. pci_read_config_dword(pvt->pci_ch[socket][i][1],
  441. MC_DOD_CH_DIMM0, &dimm_dod[0]);
  442. pci_read_config_dword(pvt->pci_ch[socket][i][1],
  443. MC_DOD_CH_DIMM1, &dimm_dod[1]);
  444. pci_read_config_dword(pvt->pci_ch[socket][i][1],
  445. MC_DOD_CH_DIMM2, &dimm_dod[2]);
  446. debugf0("Ch%d phy rd%d, wr%d (0x%08x): "
  447. "%d ranks, %cDIMMs\n",
  448. i,
  449. RDLCH(pvt->info.ch_map, i), WRLCH(pvt->info.ch_map, i),
  450. data,
  451. pvt->channel[socket][i].ranks,
  452. (data & REGISTERED_DIMM) ? 'R' : 'U');
  453. for (j = 0; j < 3; j++) {
  454. u32 banks, ranks, rows, cols;
  455. u32 size, npages;
  456. if (!DIMM_PRESENT(dimm_dod[j]))
  457. continue;
  458. banks = numbank(MC_DOD_NUMBANK(dimm_dod[j]));
  459. ranks = numrank(MC_DOD_NUMRANK(dimm_dod[j]));
  460. rows = numrow(MC_DOD_NUMROW(dimm_dod[j]));
  461. cols = numcol(MC_DOD_NUMCOL(dimm_dod[j]));
  462. /* DDR3 has 8 I/O banks */
  463. size = (rows * cols * banks * ranks) >> (20 - 3);
  464. pvt->channel[socket][i].dimms++;
  465. debugf0("\tdimm %d %d Mb offset: %x, "
  466. "bank: %d, rank: %d, row: %#x, col: %#x\n",
  467. j, size,
  468. RANKOFFSET(dimm_dod[j]),
  469. banks, ranks, rows, cols);
  470. #if PAGE_SHIFT > 20
  471. npages = size >> (PAGE_SHIFT - 20);
  472. #else
  473. npages = size << (20 - PAGE_SHIFT);
  474. #endif
  475. csr = &mci->csrows[*csrow];
  476. csr->first_page = last_page + 1;
  477. last_page += npages;
  478. csr->last_page = last_page;
  479. csr->nr_pages = npages;
  480. csr->page_mask = 0;
  481. csr->grain = 8;
  482. csr->csrow_idx = *csrow;
  483. csr->nr_channels = 1;
  484. csr->channels[0].chan_idx = i;
  485. csr->channels[0].ce_count = 0;
  486. pvt->csrow_map[socket][i][j] = *csrow;
  487. switch (banks) {
  488. case 4:
  489. csr->dtype = DEV_X4;
  490. break;
  491. case 8:
  492. csr->dtype = DEV_X8;
  493. break;
  494. case 16:
  495. csr->dtype = DEV_X16;
  496. break;
  497. default:
  498. csr->dtype = DEV_UNKNOWN;
  499. }
  500. csr->edac_mode = mode;
  501. csr->mtype = mtype;
  502. (*csrow)++;
  503. }
  504. pci_read_config_dword(pdev, MC_SAG_CH_0, &value[0]);
  505. pci_read_config_dword(pdev, MC_SAG_CH_1, &value[1]);
  506. pci_read_config_dword(pdev, MC_SAG_CH_2, &value[2]);
  507. pci_read_config_dword(pdev, MC_SAG_CH_3, &value[3]);
  508. pci_read_config_dword(pdev, MC_SAG_CH_4, &value[4]);
  509. pci_read_config_dword(pdev, MC_SAG_CH_5, &value[5]);
  510. pci_read_config_dword(pdev, MC_SAG_CH_6, &value[6]);
  511. pci_read_config_dword(pdev, MC_SAG_CH_7, &value[7]);
  512. debugf1("\t[%i] DIVBY3\tREMOVED\tOFFSET\n", i);
  513. for (j = 0; j < 8; j++)
  514. debugf1("\t\t%#x\t%#x\t%#x\n",
  515. (value[j] >> 27) & 0x1,
  516. (value[j] >> 24) & 0x7,
  517. (value[j] && ((1 << 24) - 1)));
  518. }
  519. return 0;
  520. }
  521. /****************************************************************************
  522. Error insertion routines
  523. ****************************************************************************/
  524. /* The i7core has independent error injection features per channel.
  525. However, to have a simpler code, we don't allow enabling error injection
  526. on more than one channel.
  527. Also, since a change at an inject parameter will be applied only at enable,
  528. we're disabling error injection on all write calls to the sysfs nodes that
  529. controls the error code injection.
  530. */
  531. static int disable_inject(struct mem_ctl_info *mci)
  532. {
  533. struct i7core_pvt *pvt = mci->pvt_info;
  534. pvt->inject.enable = 0;
  535. if (!pvt->pci_ch[pvt->inject.socket][pvt->inject.channel][0])
  536. return -ENODEV;
  537. pci_write_config_dword(pvt->pci_ch[pvt->inject.socket][pvt->inject.channel][0],
  538. MC_CHANNEL_ERROR_INJECT, 0);
  539. return 0;
  540. }
  541. /*
  542. * i7core inject inject.socket
  543. *
  544. * accept and store error injection inject.socket value
  545. */
  546. static ssize_t i7core_inject_socket_store(struct mem_ctl_info *mci,
  547. const char *data, size_t count)
  548. {
  549. struct i7core_pvt *pvt = mci->pvt_info;
  550. unsigned long value;
  551. int rc;
  552. rc = strict_strtoul(data, 10, &value);
  553. if ((rc < 0) || (value >= pvt->sockets))
  554. return -EIO;
  555. pvt->inject.socket = (u32) value;
  556. return count;
  557. }
  558. static ssize_t i7core_inject_socket_show(struct mem_ctl_info *mci,
  559. char *data)
  560. {
  561. struct i7core_pvt *pvt = mci->pvt_info;
  562. return sprintf(data, "%d\n", pvt->inject.socket);
  563. }
  564. /*
  565. * i7core inject inject.section
  566. *
  567. * accept and store error injection inject.section value
  568. * bit 0 - refers to the lower 32-byte half cacheline
  569. * bit 1 - refers to the upper 32-byte half cacheline
  570. */
  571. static ssize_t i7core_inject_section_store(struct mem_ctl_info *mci,
  572. const char *data, size_t count)
  573. {
  574. struct i7core_pvt *pvt = mci->pvt_info;
  575. unsigned long value;
  576. int rc;
  577. if (pvt->inject.enable)
  578. disable_inject(mci);
  579. rc = strict_strtoul(data, 10, &value);
  580. if ((rc < 0) || (value > 3))
  581. return -EIO;
  582. pvt->inject.section = (u32) value;
  583. return count;
  584. }
  585. static ssize_t i7core_inject_section_show(struct mem_ctl_info *mci,
  586. char *data)
  587. {
  588. struct i7core_pvt *pvt = mci->pvt_info;
  589. return sprintf(data, "0x%08x\n", pvt->inject.section);
  590. }
  591. /*
  592. * i7core inject.type
  593. *
  594. * accept and store error injection inject.section value
  595. * bit 0 - repeat enable - Enable error repetition
  596. * bit 1 - inject ECC error
  597. * bit 2 - inject parity error
  598. */
  599. static ssize_t i7core_inject_type_store(struct mem_ctl_info *mci,
  600. const char *data, size_t count)
  601. {
  602. struct i7core_pvt *pvt = mci->pvt_info;
  603. unsigned long value;
  604. int rc;
  605. if (pvt->inject.enable)
  606. disable_inject(mci);
  607. rc = strict_strtoul(data, 10, &value);
  608. if ((rc < 0) || (value > 7))
  609. return -EIO;
  610. pvt->inject.type = (u32) value;
  611. return count;
  612. }
  613. static ssize_t i7core_inject_type_show(struct mem_ctl_info *mci,
  614. char *data)
  615. {
  616. struct i7core_pvt *pvt = mci->pvt_info;
  617. return sprintf(data, "0x%08x\n", pvt->inject.type);
  618. }
  619. /*
  620. * i7core_inject_inject.eccmask_store
  621. *
  622. * The type of error (UE/CE) will depend on the inject.eccmask value:
  623. * Any bits set to a 1 will flip the corresponding ECC bit
  624. * Correctable errors can be injected by flipping 1 bit or the bits within
  625. * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or
  626. * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an
  627. * uncorrectable error to be injected.
  628. */
  629. static ssize_t i7core_inject_eccmask_store(struct mem_ctl_info *mci,
  630. const char *data, size_t count)
  631. {
  632. struct i7core_pvt *pvt = mci->pvt_info;
  633. unsigned long value;
  634. int rc;
  635. if (pvt->inject.enable)
  636. disable_inject(mci);
  637. rc = strict_strtoul(data, 10, &value);
  638. if (rc < 0)
  639. return -EIO;
  640. pvt->inject.eccmask = (u32) value;
  641. return count;
  642. }
  643. static ssize_t i7core_inject_eccmask_show(struct mem_ctl_info *mci,
  644. char *data)
  645. {
  646. struct i7core_pvt *pvt = mci->pvt_info;
  647. return sprintf(data, "0x%08x\n", pvt->inject.eccmask);
  648. }
  649. /*
  650. * i7core_addrmatch
  651. *
  652. * The type of error (UE/CE) will depend on the inject.eccmask value:
  653. * Any bits set to a 1 will flip the corresponding ECC bit
  654. * Correctable errors can be injected by flipping 1 bit or the bits within
  655. * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or
  656. * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an
  657. * uncorrectable error to be injected.
  658. */
  659. static ssize_t i7core_inject_addrmatch_store(struct mem_ctl_info *mci,
  660. const char *data, size_t count)
  661. {
  662. struct i7core_pvt *pvt = mci->pvt_info;
  663. char *cmd, *val;
  664. long value;
  665. int rc;
  666. if (pvt->inject.enable)
  667. disable_inject(mci);
  668. do {
  669. cmd = strsep((char **) &data, ":");
  670. if (!cmd)
  671. break;
  672. val = strsep((char **) &data, " \n\t");
  673. if (!val)
  674. return cmd - data;
  675. if (!strcasecmp(val, "any"))
  676. value = -1;
  677. else {
  678. rc = strict_strtol(val, 10, &value);
  679. if ((rc < 0) || (value < 0))
  680. return cmd - data;
  681. }
  682. if (!strcasecmp(cmd, "channel")) {
  683. if (value < 3)
  684. pvt->inject.channel = value;
  685. else
  686. return cmd - data;
  687. } else if (!strcasecmp(cmd, "dimm")) {
  688. if (value < 3)
  689. pvt->inject.dimm = value;
  690. else
  691. return cmd - data;
  692. } else if (!strcasecmp(cmd, "rank")) {
  693. if (value < 4)
  694. pvt->inject.rank = value;
  695. else
  696. return cmd - data;
  697. } else if (!strcasecmp(cmd, "bank")) {
  698. if (value < 32)
  699. pvt->inject.bank = value;
  700. else
  701. return cmd - data;
  702. } else if (!strcasecmp(cmd, "page")) {
  703. if (value <= 0xffff)
  704. pvt->inject.page = value;
  705. else
  706. return cmd - data;
  707. } else if (!strcasecmp(cmd, "col") ||
  708. !strcasecmp(cmd, "column")) {
  709. if (value <= 0x3fff)
  710. pvt->inject.col = value;
  711. else
  712. return cmd - data;
  713. }
  714. } while (1);
  715. return count;
  716. }
  717. static ssize_t i7core_inject_addrmatch_show(struct mem_ctl_info *mci,
  718. char *data)
  719. {
  720. struct i7core_pvt *pvt = mci->pvt_info;
  721. char channel[4], dimm[4], bank[4], rank[4], page[7], col[7];
  722. if (pvt->inject.channel < 0)
  723. sprintf(channel, "any");
  724. else
  725. sprintf(channel, "%d", pvt->inject.channel);
  726. if (pvt->inject.dimm < 0)
  727. sprintf(dimm, "any");
  728. else
  729. sprintf(dimm, "%d", pvt->inject.dimm);
  730. if (pvt->inject.bank < 0)
  731. sprintf(bank, "any");
  732. else
  733. sprintf(bank, "%d", pvt->inject.bank);
  734. if (pvt->inject.rank < 0)
  735. sprintf(rank, "any");
  736. else
  737. sprintf(rank, "%d", pvt->inject.rank);
  738. if (pvt->inject.page < 0)
  739. sprintf(page, "any");
  740. else
  741. sprintf(page, "0x%04x", pvt->inject.page);
  742. if (pvt->inject.col < 0)
  743. sprintf(col, "any");
  744. else
  745. sprintf(col, "0x%04x", pvt->inject.col);
  746. return sprintf(data, "channel: %s\ndimm: %s\nbank: %s\n"
  747. "rank: %s\npage: %s\ncolumn: %s\n",
  748. channel, dimm, bank, rank, page, col);
  749. }
  750. static int write_and_test(struct pci_dev *dev, int where, u32 val)
  751. {
  752. u32 read;
  753. int count;
  754. debugf0("setting pci %02x:%02x.%x reg=%02x value=%08x\n",
  755. dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn),
  756. where, val);
  757. for (count = 0; count < 10; count++) {
  758. if (count)
  759. msleep(100);
  760. pci_write_config_dword(dev, where, val);
  761. pci_read_config_dword(dev, where, &read);
  762. if (read == val)
  763. return 0;
  764. }
  765. i7core_printk(KERN_ERR, "Error during set pci %02x:%02x.%x reg=%02x "
  766. "write=%08x. Read=%08x\n",
  767. dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn),
  768. where, val, read);
  769. return -EINVAL;
  770. }
  771. /*
  772. * This routine prepares the Memory Controller for error injection.
  773. * The error will be injected when some process tries to write to the
  774. * memory that matches the given criteria.
  775. * The criteria can be set in terms of a mask where dimm, rank, bank, page
  776. * and col can be specified.
  777. * A -1 value for any of the mask items will make the MCU to ignore
  778. * that matching criteria for error injection.
  779. *
  780. * It should be noticed that the error will only happen after a write operation
  781. * on a memory that matches the condition. if REPEAT_EN is not enabled at
  782. * inject mask, then it will produce just one error. Otherwise, it will repeat
  783. * until the injectmask would be cleaned.
  784. *
  785. * FIXME: This routine assumes that MAXNUMDIMMS value of MC_MAX_DOD
  786. * is reliable enough to check if the MC is using the
  787. * three channels. However, this is not clear at the datasheet.
  788. */
  789. static ssize_t i7core_inject_enable_store(struct mem_ctl_info *mci,
  790. const char *data, size_t count)
  791. {
  792. struct i7core_pvt *pvt = mci->pvt_info;
  793. u32 injectmask;
  794. u64 mask = 0;
  795. int rc;
  796. long enable;
  797. if (!pvt->pci_ch[pvt->inject.socket][pvt->inject.channel][0])
  798. return 0;
  799. rc = strict_strtoul(data, 10, &enable);
  800. if ((rc < 0))
  801. return 0;
  802. if (enable) {
  803. pvt->inject.enable = 1;
  804. } else {
  805. disable_inject(mci);
  806. return count;
  807. }
  808. /* Sets pvt->inject.dimm mask */
  809. if (pvt->inject.dimm < 0)
  810. mask |= 1L << 41;
  811. else {
  812. if (pvt->channel[pvt->inject.socket][pvt->inject.channel].dimms > 2)
  813. mask |= (pvt->inject.dimm & 0x3L) << 35;
  814. else
  815. mask |= (pvt->inject.dimm & 0x1L) << 36;
  816. }
  817. /* Sets pvt->inject.rank mask */
  818. if (pvt->inject.rank < 0)
  819. mask |= 1L << 40;
  820. else {
  821. if (pvt->channel[pvt->inject.socket][pvt->inject.channel].dimms > 2)
  822. mask |= (pvt->inject.rank & 0x1L) << 34;
  823. else
  824. mask |= (pvt->inject.rank & 0x3L) << 34;
  825. }
  826. /* Sets pvt->inject.bank mask */
  827. if (pvt->inject.bank < 0)
  828. mask |= 1L << 39;
  829. else
  830. mask |= (pvt->inject.bank & 0x15L) << 30;
  831. /* Sets pvt->inject.page mask */
  832. if (pvt->inject.page < 0)
  833. mask |= 1L << 38;
  834. else
  835. mask |= (pvt->inject.page & 0xffffL) << 14;
  836. /* Sets pvt->inject.column mask */
  837. if (pvt->inject.col < 0)
  838. mask |= 1L << 37;
  839. else
  840. mask |= (pvt->inject.col & 0x3fffL);
  841. /*
  842. * bit 0: REPEAT_EN
  843. * bits 1-2: MASK_HALF_CACHELINE
  844. * bit 3: INJECT_ECC
  845. * bit 4: INJECT_ADDR_PARITY
  846. */
  847. injectmask = (pvt->inject.type & 1) |
  848. (pvt->inject.section & 0x3) << 1 |
  849. (pvt->inject.type & 0x6) << (3 - 1);
  850. /* Unlock writes to registers - this register is write only */
  851. pci_write_config_dword(pvt->pci_noncore[pvt->inject.socket],
  852. MC_CFG_CONTROL, 0x2);
  853. write_and_test(pvt->pci_ch[pvt->inject.socket][pvt->inject.channel][0],
  854. MC_CHANNEL_ADDR_MATCH, mask);
  855. write_and_test(pvt->pci_ch[pvt->inject.socket][pvt->inject.channel][0],
  856. MC_CHANNEL_ADDR_MATCH + 4, mask >> 32L);
  857. write_and_test(pvt->pci_ch[pvt->inject.socket][pvt->inject.channel][0],
  858. MC_CHANNEL_ERROR_MASK, pvt->inject.eccmask);
  859. write_and_test(pvt->pci_ch[pvt->inject.socket][pvt->inject.channel][0],
  860. MC_CHANNEL_ERROR_INJECT, injectmask);
  861. /*
  862. * This is something undocumented, based on my tests
  863. * Without writing 8 to this register, errors aren't injected. Not sure
  864. * why.
  865. */
  866. pci_write_config_dword(pvt->pci_noncore[pvt->inject.socket],
  867. MC_CFG_CONTROL, 8);
  868. debugf0("Error inject addr match 0x%016llx, ecc 0x%08x,"
  869. " inject 0x%08x\n",
  870. mask, pvt->inject.eccmask, injectmask);
  871. return count;
  872. }
  873. static ssize_t i7core_inject_enable_show(struct mem_ctl_info *mci,
  874. char *data)
  875. {
  876. struct i7core_pvt *pvt = mci->pvt_info;
  877. u32 injectmask;
  878. pci_read_config_dword(pvt->pci_ch[pvt->inject.socket][pvt->inject.channel][0],
  879. MC_CHANNEL_ERROR_INJECT, &injectmask);
  880. debugf0("Inject error read: 0x%018x\n", injectmask);
  881. if (injectmask & 0x0c)
  882. pvt->inject.enable = 1;
  883. return sprintf(data, "%d\n", pvt->inject.enable);
  884. }
  885. static ssize_t i7core_ce_regs_show(struct mem_ctl_info *mci, char *data)
  886. {
  887. unsigned i, j, count, total = 0;
  888. struct i7core_pvt *pvt = mci->pvt_info;
  889. for (i = 0; i < pvt->sockets; i++) {
  890. if (!pvt->ce_count_available[i]) {
  891. count = sprintf(data, "socket 0 data unavailable\n");
  892. continue;
  893. }
  894. if (!pvt->is_registered)
  895. count = sprintf(data, "socket %d, dimm0: %lu\n"
  896. "dimm1: %lu\ndimm2: %lu\n",
  897. i,
  898. pvt->udimm_ce_count[i][0],
  899. pvt->udimm_ce_count[i][1],
  900. pvt->udimm_ce_count[i][2]);
  901. else
  902. for (j = 0; j < NUM_CHANS; j++) {
  903. count = sprintf(data, "socket %d, channel %d"
  904. "dimm0: %lu\n"
  905. "dimm1: %lu\ndimm2: %lu\n",
  906. i, j,
  907. pvt->rdimm_ce_count[i][j][0],
  908. pvt->rdimm_ce_count[i][j][1],
  909. pvt->rdimm_ce_count[i][j][2]);
  910. }
  911. data += count;
  912. total += count;
  913. }
  914. return total;
  915. }
  916. /*
  917. * Sysfs struct
  918. */
  919. static struct mcidev_sysfs_attribute i7core_inj_attrs[] = {
  920. {
  921. .attr = {
  922. .name = "inject_socket",
  923. .mode = (S_IRUGO | S_IWUSR)
  924. },
  925. .show = i7core_inject_socket_show,
  926. .store = i7core_inject_socket_store,
  927. }, {
  928. .attr = {
  929. .name = "inject_section",
  930. .mode = (S_IRUGO | S_IWUSR)
  931. },
  932. .show = i7core_inject_section_show,
  933. .store = i7core_inject_section_store,
  934. }, {
  935. .attr = {
  936. .name = "inject_type",
  937. .mode = (S_IRUGO | S_IWUSR)
  938. },
  939. .show = i7core_inject_type_show,
  940. .store = i7core_inject_type_store,
  941. }, {
  942. .attr = {
  943. .name = "inject_eccmask",
  944. .mode = (S_IRUGO | S_IWUSR)
  945. },
  946. .show = i7core_inject_eccmask_show,
  947. .store = i7core_inject_eccmask_store,
  948. }, {
  949. .attr = {
  950. .name = "inject_addrmatch",
  951. .mode = (S_IRUGO | S_IWUSR)
  952. },
  953. .show = i7core_inject_addrmatch_show,
  954. .store = i7core_inject_addrmatch_store,
  955. }, {
  956. .attr = {
  957. .name = "inject_enable",
  958. .mode = (S_IRUGO | S_IWUSR)
  959. },
  960. .show = i7core_inject_enable_show,
  961. .store = i7core_inject_enable_store,
  962. }, {
  963. .attr = {
  964. .name = "corrected_error_counts",
  965. .mode = (S_IRUGO | S_IWUSR)
  966. },
  967. .show = i7core_ce_regs_show,
  968. .store = NULL,
  969. },
  970. };
  971. /****************************************************************************
  972. Device initialization routines: put/get, init/exit
  973. ****************************************************************************/
  974. /*
  975. * i7core_put_devices 'put' all the devices that we have
  976. * reserved via 'get'
  977. */
  978. static void i7core_put_devices(void)
  979. {
  980. int i, j;
  981. for (i = 0; i < NUM_SOCKETS; i++)
  982. for (j = 0; j < N_DEVS; j++)
  983. pci_dev_put(pci_devs[j].pdev[i]);
  984. }
  985. /*
  986. * i7core_get_devices Find and perform 'get' operation on the MCH's
  987. * device/functions we want to reference for this driver
  988. *
  989. * Need to 'get' device 16 func 1 and func 2
  990. */
  991. int i7core_get_onedevice(struct pci_dev **prev, int devno)
  992. {
  993. struct pci_dev *pdev = NULL;
  994. u8 bus = 0;
  995. u8 socket = 0;
  996. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  997. pci_devs[devno].dev_id, *prev);
  998. /*
  999. * On Xeon 55xx, the Intel Quckpath Arch Generic Non-core pci buses
  1000. * aren't announced by acpi. So, we need to use a legacy scan probing
  1001. * to detect them
  1002. */
  1003. if (unlikely(!pdev && !devno && !prev)) {
  1004. pcibios_scan_specific_bus(254);
  1005. pcibios_scan_specific_bus(255);
  1006. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  1007. pci_devs[devno].dev_id, *prev);
  1008. }
  1009. /*
  1010. * On Xeon 55xx, the Intel Quckpath Arch Generic Non-core regs
  1011. * is at addr 8086:2c40, instead of 8086:2c41. So, we need
  1012. * to probe for the alternate address in case of failure
  1013. */
  1014. if (pci_devs[devno].dev_id == PCI_DEVICE_ID_INTEL_I7_NOCORE && !pdev)
  1015. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  1016. PCI_DEVICE_ID_INTEL_I7_NOCORE_ALT, *prev);
  1017. if (!pdev) {
  1018. if (*prev) {
  1019. *prev = pdev;
  1020. return 0;
  1021. }
  1022. /*
  1023. * Dev 3 function 2 only exists on chips with RDIMMs
  1024. * so, it is ok to not found it
  1025. */
  1026. if ((pci_devs[devno].dev == 3) && (pci_devs[devno].func == 2)) {
  1027. *prev = pdev;
  1028. return 0;
  1029. }
  1030. i7core_printk(KERN_ERR,
  1031. "Device not found: dev %02x.%d PCI ID %04x:%04x\n",
  1032. pci_devs[devno].dev, pci_devs[devno].func,
  1033. PCI_VENDOR_ID_INTEL, pci_devs[devno].dev_id);
  1034. /* End of list, leave */
  1035. return -ENODEV;
  1036. }
  1037. bus = pdev->bus->number;
  1038. if (bus == 0x3f)
  1039. socket = 0;
  1040. else
  1041. socket = 255 - bus;
  1042. if (socket >= NUM_SOCKETS) {
  1043. i7core_printk(KERN_ERR,
  1044. "Unexpected socket for "
  1045. "dev %02x:%02x.%d PCI ID %04x:%04x\n",
  1046. bus, pci_devs[devno].dev, pci_devs[devno].func,
  1047. PCI_VENDOR_ID_INTEL, pci_devs[devno].dev_id);
  1048. pci_dev_put(pdev);
  1049. return -ENODEV;
  1050. }
  1051. if (pci_devs[devno].pdev[socket]) {
  1052. i7core_printk(KERN_ERR,
  1053. "Duplicated device for "
  1054. "dev %02x:%02x.%d PCI ID %04x:%04x\n",
  1055. bus, pci_devs[devno].dev, pci_devs[devno].func,
  1056. PCI_VENDOR_ID_INTEL, pci_devs[devno].dev_id);
  1057. pci_dev_put(pdev);
  1058. return -ENODEV;
  1059. }
  1060. pci_devs[devno].pdev[socket] = pdev;
  1061. /* Sanity check */
  1062. if (unlikely(PCI_SLOT(pdev->devfn) != pci_devs[devno].dev ||
  1063. PCI_FUNC(pdev->devfn) != pci_devs[devno].func)) {
  1064. i7core_printk(KERN_ERR,
  1065. "Device PCI ID %04x:%04x "
  1066. "has dev %02x:%02x.%d instead of dev %02x:%02x.%d\n",
  1067. PCI_VENDOR_ID_INTEL, pci_devs[devno].dev_id,
  1068. bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
  1069. bus, pci_devs[devno].dev, pci_devs[devno].func);
  1070. return -ENODEV;
  1071. }
  1072. /* Be sure that the device is enabled */
  1073. if (unlikely(pci_enable_device(pdev) < 0)) {
  1074. i7core_printk(KERN_ERR,
  1075. "Couldn't enable "
  1076. "dev %02x:%02x.%d PCI ID %04x:%04x\n",
  1077. bus, pci_devs[devno].dev, pci_devs[devno].func,
  1078. PCI_VENDOR_ID_INTEL, pci_devs[devno].dev_id);
  1079. return -ENODEV;
  1080. }
  1081. i7core_printk(KERN_INFO,
  1082. "Registered socket %d "
  1083. "dev %02x:%02x.%d PCI ID %04x:%04x\n",
  1084. socket, bus, pci_devs[devno].dev, pci_devs[devno].func,
  1085. PCI_VENDOR_ID_INTEL, pci_devs[devno].dev_id);
  1086. *prev = pdev;
  1087. return 0;
  1088. }
  1089. static int i7core_get_devices(void)
  1090. {
  1091. int i;
  1092. struct pci_dev *pdev = NULL;
  1093. for (i = 0; i < N_DEVS; i++) {
  1094. pdev = NULL;
  1095. do {
  1096. if (i7core_get_onedevice(&pdev, i) < 0) {
  1097. i7core_put_devices();
  1098. return -ENODEV;
  1099. }
  1100. } while (pdev);
  1101. }
  1102. return 0;
  1103. }
  1104. static int mci_bind_devs(struct mem_ctl_info *mci)
  1105. {
  1106. struct i7core_pvt *pvt = mci->pvt_info;
  1107. struct pci_dev *pdev;
  1108. int i, j, func, slot;
  1109. for (i = 0; i < pvt->sockets; i++) {
  1110. for (j = 0; j < N_DEVS; j++) {
  1111. pdev = pci_devs[j].pdev[i];
  1112. if (!pdev)
  1113. continue;
  1114. func = PCI_FUNC(pdev->devfn);
  1115. slot = PCI_SLOT(pdev->devfn);
  1116. if (slot == 3) {
  1117. if (unlikely(func > MAX_MCR_FUNC))
  1118. goto error;
  1119. pvt->pci_mcr[i][func] = pdev;
  1120. } else if (likely(slot >= 4 && slot < 4 + NUM_CHANS)) {
  1121. if (unlikely(func > MAX_CHAN_FUNC))
  1122. goto error;
  1123. pvt->pci_ch[i][slot - 4][func] = pdev;
  1124. } else if (!slot && !func)
  1125. pvt->pci_noncore[i] = pdev;
  1126. else
  1127. goto error;
  1128. debugf0("Associated fn %d.%d, dev = %p, socket %d\n",
  1129. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
  1130. pdev, i);
  1131. }
  1132. }
  1133. return 0;
  1134. error:
  1135. i7core_printk(KERN_ERR, "Device %d, function %d "
  1136. "is out of the expected range\n",
  1137. slot, func);
  1138. return -EINVAL;
  1139. }
  1140. /****************************************************************************
  1141. Error check routines
  1142. ****************************************************************************/
  1143. static void i7core_rdimm_update_csrow(struct mem_ctl_info *mci, int socket,
  1144. int chan, int dimm, int add)
  1145. {
  1146. char *msg;
  1147. struct i7core_pvt *pvt = mci->pvt_info;
  1148. int row = pvt->csrow_map[socket][chan][dimm], i;
  1149. for (i = 0; i < add; i++) {
  1150. msg = kasprintf(GFP_KERNEL, "Corrected error "
  1151. "(Socket=%d channel=%d dimm=%d",
  1152. socket, chan, dimm);
  1153. edac_mc_handle_fbd_ce(mci, row, 0, msg);
  1154. kfree (msg);
  1155. }
  1156. }
  1157. static void i7core_rdimm_update_ce_count(struct mem_ctl_info *mci,
  1158. int socket, int chan, int new0, int new1, int new2)
  1159. {
  1160. struct i7core_pvt *pvt = mci->pvt_info;
  1161. int add0 = 0, add1 = 0, add2 = 0;
  1162. /* Updates CE counters if it is not the first time here */
  1163. if (pvt->ce_count_available[socket]) {
  1164. /* Updates CE counters */
  1165. add2 = new2 - pvt->rdimm_last_ce_count[socket][chan][2];
  1166. add1 = new1 - pvt->rdimm_last_ce_count[socket][chan][1];
  1167. add0 = new0 - pvt->rdimm_last_ce_count[socket][chan][0];
  1168. if (add2 < 0)
  1169. add2 += 0x7fff;
  1170. pvt->rdimm_ce_count[socket][chan][2] += add2;
  1171. if (add1 < 0)
  1172. add1 += 0x7fff;
  1173. pvt->rdimm_ce_count[socket][chan][1] += add1;
  1174. if (add0 < 0)
  1175. add0 += 0x7fff;
  1176. pvt->rdimm_ce_count[socket][chan][0] += add0;
  1177. } else
  1178. pvt->ce_count_available[socket] = 1;
  1179. /* Store the new values */
  1180. pvt->rdimm_last_ce_count[socket][chan][2] = new2;
  1181. pvt->rdimm_last_ce_count[socket][chan][1] = new1;
  1182. pvt->rdimm_last_ce_count[socket][chan][0] = new0;
  1183. /*updated the edac core */
  1184. if (add0 != 0)
  1185. i7core_rdimm_update_csrow(mci, socket, chan, 0, add0);
  1186. if (add1 != 0)
  1187. i7core_rdimm_update_csrow(mci, socket, chan, 1, add1);
  1188. if (add2 != 0)
  1189. i7core_rdimm_update_csrow(mci, socket, chan, 2, add2);
  1190. }
  1191. static void i7core_rdimm_check_mc_ecc_err(struct mem_ctl_info *mci, u8 socket)
  1192. {
  1193. struct i7core_pvt *pvt = mci->pvt_info;
  1194. u32 rcv[3][2];
  1195. int i, new0, new1, new2;
  1196. /*Read DEV 3: FUN 2: MC_COR_ECC_CNT regs directly*/
  1197. pci_read_config_dword(pvt->pci_mcr[socket][2], MC_COR_ECC_CNT_0,
  1198. &rcv[0][0]);
  1199. pci_read_config_dword(pvt->pci_mcr[socket][2], MC_COR_ECC_CNT_1,
  1200. &rcv[0][1]);
  1201. pci_read_config_dword(pvt->pci_mcr[socket][2], MC_COR_ECC_CNT_2,
  1202. &rcv[1][0]);
  1203. pci_read_config_dword(pvt->pci_mcr[socket][2], MC_COR_ECC_CNT_3,
  1204. &rcv[1][1]);
  1205. pci_read_config_dword(pvt->pci_mcr[socket][2], MC_COR_ECC_CNT_4,
  1206. &rcv[2][0]);
  1207. pci_read_config_dword(pvt->pci_mcr[socket][2], MC_COR_ECC_CNT_5,
  1208. &rcv[2][1]);
  1209. for (i = 0 ; i < 3; i++) {
  1210. debugf3("MC_COR_ECC_CNT%d = 0x%x; MC_COR_ECC_CNT%d = 0x%x\n",
  1211. (i * 2), rcv[i][0], (i * 2) + 1, rcv[i][1]);
  1212. /*if the channel has 3 dimms*/
  1213. if (pvt->channel[socket][i].dimms > 2) {
  1214. new0 = DIMM_BOT_COR_ERR(rcv[i][0]);
  1215. new1 = DIMM_TOP_COR_ERR(rcv[i][0]);
  1216. new2 = DIMM_BOT_COR_ERR(rcv[i][1]);
  1217. } else {
  1218. new0 = DIMM_TOP_COR_ERR(rcv[i][0]) +
  1219. DIMM_BOT_COR_ERR(rcv[i][0]);
  1220. new1 = DIMM_TOP_COR_ERR(rcv[i][1]) +
  1221. DIMM_BOT_COR_ERR(rcv[i][1]);
  1222. new2 = 0;
  1223. }
  1224. i7core_rdimm_update_ce_count(mci, socket, i, new0, new1, new2);
  1225. }
  1226. }
  1227. /* This function is based on the device 3 function 4 registers as described on:
  1228. * Intel Xeon Processor 5500 Series Datasheet Volume 2
  1229. * http://www.intel.com/Assets/PDF/datasheet/321322.pdf
  1230. * also available at:
  1231. * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
  1232. */
  1233. static void i7core_udimm_check_mc_ecc_err(struct mem_ctl_info *mci, u8 socket)
  1234. {
  1235. struct i7core_pvt *pvt = mci->pvt_info;
  1236. u32 rcv1, rcv0;
  1237. int new0, new1, new2;
  1238. if (!pvt->pci_mcr[socket][4]) {
  1239. debugf0("%s MCR registers not found\n", __func__);
  1240. return;
  1241. }
  1242. /* Corrected test errors */
  1243. pci_read_config_dword(pvt->pci_mcr[socket][4], MC_TEST_ERR_RCV1, &rcv1);
  1244. pci_read_config_dword(pvt->pci_mcr[socket][4], MC_TEST_ERR_RCV0, &rcv0);
  1245. /* Store the new values */
  1246. new2 = DIMM2_COR_ERR(rcv1);
  1247. new1 = DIMM1_COR_ERR(rcv0);
  1248. new0 = DIMM0_COR_ERR(rcv0);
  1249. /* Updates CE counters if it is not the first time here */
  1250. if (pvt->ce_count_available[socket]) {
  1251. /* Updates CE counters */
  1252. int add0, add1, add2;
  1253. add2 = new2 - pvt->udimm_last_ce_count[socket][2];
  1254. add1 = new1 - pvt->udimm_last_ce_count[socket][1];
  1255. add0 = new0 - pvt->udimm_last_ce_count[socket][0];
  1256. if (add2 < 0)
  1257. add2 += 0x7fff;
  1258. pvt->udimm_ce_count[socket][2] += add2;
  1259. if (add1 < 0)
  1260. add1 += 0x7fff;
  1261. pvt->udimm_ce_count[socket][1] += add1;
  1262. if (add0 < 0)
  1263. add0 += 0x7fff;
  1264. pvt->udimm_ce_count[socket][0] += add0;
  1265. if (add0 | add1 | add2)
  1266. i7core_printk(KERN_ERR, "New Corrected error(s): "
  1267. "dimm0: +%d, dimm1: +%d, dimm2 +%d\n",
  1268. add0, add1, add2);
  1269. } else
  1270. pvt->ce_count_available[socket] = 1;
  1271. /* Store the new values */
  1272. pvt->udimm_last_ce_count[socket][2] = new2;
  1273. pvt->udimm_last_ce_count[socket][1] = new1;
  1274. pvt->udimm_last_ce_count[socket][0] = new0;
  1275. }
  1276. /*
  1277. * According with tables E-11 and E-12 of chapter E.3.3 of Intel 64 and IA-32
  1278. * Architectures Software Developer’s Manual Volume 3B.
  1279. * Nehalem are defined as family 0x06, model 0x1a
  1280. *
  1281. * The MCA registers used here are the following ones:
  1282. * struct mce field MCA Register
  1283. * m->status MSR_IA32_MC8_STATUS
  1284. * m->addr MSR_IA32_MC8_ADDR
  1285. * m->misc MSR_IA32_MC8_MISC
  1286. * In the case of Nehalem, the error information is masked at .status and .misc
  1287. * fields
  1288. */
  1289. static void i7core_mce_output_error(struct mem_ctl_info *mci,
  1290. struct mce *m)
  1291. {
  1292. struct i7core_pvt *pvt = mci->pvt_info;
  1293. char *type, *optype, *err, *msg;
  1294. unsigned long error = m->status & 0x1ff0000l;
  1295. u32 optypenum = (m->status >> 4) & 0x07;
  1296. u32 core_err_cnt = (m->status >> 38) && 0x7fff;
  1297. u32 dimm = (m->misc >> 16) & 0x3;
  1298. u32 channel = (m->misc >> 18) & 0x3;
  1299. u32 syndrome = m->misc >> 32;
  1300. u32 errnum = find_first_bit(&error, 32);
  1301. int csrow;
  1302. if (m->mcgstatus & 1)
  1303. type = "FATAL";
  1304. else
  1305. type = "NON_FATAL";
  1306. switch (optypenum) {
  1307. case 0:
  1308. optype = "generic undef request";
  1309. break;
  1310. case 1:
  1311. optype = "read error";
  1312. break;
  1313. case 2:
  1314. optype = "write error";
  1315. break;
  1316. case 3:
  1317. optype = "addr/cmd error";
  1318. break;
  1319. case 4:
  1320. optype = "scrubbing error";
  1321. break;
  1322. default:
  1323. optype = "reserved";
  1324. break;
  1325. }
  1326. switch (errnum) {
  1327. case 16:
  1328. err = "read ECC error";
  1329. break;
  1330. case 17:
  1331. err = "RAS ECC error";
  1332. break;
  1333. case 18:
  1334. err = "write parity error";
  1335. break;
  1336. case 19:
  1337. err = "redundacy loss";
  1338. break;
  1339. case 20:
  1340. err = "reserved";
  1341. break;
  1342. case 21:
  1343. err = "memory range error";
  1344. break;
  1345. case 22:
  1346. err = "RTID out of range";
  1347. break;
  1348. case 23:
  1349. err = "address parity error";
  1350. break;
  1351. case 24:
  1352. err = "byte enable parity error";
  1353. break;
  1354. default:
  1355. err = "unknown";
  1356. }
  1357. /* FIXME: should convert addr into bank and rank information */
  1358. msg = kasprintf(GFP_ATOMIC,
  1359. "%s (addr = 0x%08llx, socket=%d, Dimm=%d, Channel=%d, "
  1360. "syndrome=0x%08x, count=%d, Err=%08llx:%08llx (%s: %s))\n",
  1361. type, (long long) m->addr, m->cpu, dimm, channel,
  1362. syndrome, core_err_cnt, (long long)m->status,
  1363. (long long)m->misc, optype, err);
  1364. debugf0("%s", msg);
  1365. csrow = pvt->csrow_map[m->cpu][channel][dimm];
  1366. /* Call the helper to output message */
  1367. if (m->mcgstatus & 1)
  1368. edac_mc_handle_fbd_ue(mci, csrow, 0,
  1369. 0 /* FIXME: should be channel here */, msg);
  1370. else if (!pvt->is_registered)
  1371. edac_mc_handle_fbd_ce(mci, csrow,
  1372. 0 /* FIXME: should be channel here */, msg);
  1373. kfree(msg);
  1374. }
  1375. /*
  1376. * i7core_check_error Retrieve and process errors reported by the
  1377. * hardware. Called by the Core module.
  1378. */
  1379. static void i7core_check_error(struct mem_ctl_info *mci)
  1380. {
  1381. struct i7core_pvt *pvt = mci->pvt_info;
  1382. int i;
  1383. unsigned count = 0;
  1384. struct mce *m = NULL;
  1385. unsigned long flags;
  1386. /* Copy all mce errors into a temporary buffer */
  1387. spin_lock_irqsave(&pvt->mce_lock, flags);
  1388. if (pvt->mce_count) {
  1389. m = kmalloc(sizeof(*m) * pvt->mce_count, GFP_ATOMIC);
  1390. if (m) {
  1391. count = pvt->mce_count;
  1392. memcpy(m, &pvt->mce_entry, sizeof(*m) * count);
  1393. }
  1394. pvt->mce_count = 0;
  1395. }
  1396. spin_unlock_irqrestore(&pvt->mce_lock, flags);
  1397. /* proccess mcelog errors */
  1398. for (i = 0; i < count; i++)
  1399. i7core_mce_output_error(mci, &m[i]);
  1400. kfree(m);
  1401. /* check memory count errors */
  1402. for (i = 0; i < pvt->sockets; i++)
  1403. if (!pvt->is_registered)
  1404. i7core_udimm_check_mc_ecc_err(mci, i);
  1405. else
  1406. i7core_rdimm_check_mc_ecc_err(mci, i);
  1407. }
  1408. /*
  1409. * i7core_mce_check_error Replicates mcelog routine to get errors
  1410. * This routine simply queues mcelog errors, and
  1411. * return. The error itself should be handled later
  1412. * by i7core_check_error.
  1413. */
  1414. static int i7core_mce_check_error(void *priv, struct mce *mce)
  1415. {
  1416. struct mem_ctl_info *mci = priv;
  1417. struct i7core_pvt *pvt = mci->pvt_info;
  1418. unsigned long flags;
  1419. /*
  1420. * Just let mcelog handle it if the error is
  1421. * outside the memory controller
  1422. */
  1423. if (((mce->status & 0xffff) >> 7) != 1)
  1424. return 0;
  1425. /* Bank 8 registers are the only ones that we know how to handle */
  1426. if (mce->bank != 8)
  1427. return 0;
  1428. spin_lock_irqsave(&pvt->mce_lock, flags);
  1429. if (pvt->mce_count < MCE_LOG_LEN) {
  1430. memcpy(&pvt->mce_entry[pvt->mce_count], mce, sizeof(*mce));
  1431. pvt->mce_count++;
  1432. }
  1433. spin_unlock_irqrestore(&pvt->mce_lock, flags);
  1434. /* Handle fatal errors immediately */
  1435. if (mce->mcgstatus & 1)
  1436. i7core_check_error(mci);
  1437. /* Advice mcelog that the error were handled */
  1438. return 1;
  1439. }
  1440. /*
  1441. * i7core_probe Probe for ONE instance of device to see if it is
  1442. * present.
  1443. * return:
  1444. * 0 for FOUND a device
  1445. * < 0 for error code
  1446. */
  1447. static int __devinit i7core_probe(struct pci_dev *pdev,
  1448. const struct pci_device_id *id)
  1449. {
  1450. struct mem_ctl_info *mci;
  1451. struct i7core_pvt *pvt;
  1452. int num_channels = 0;
  1453. int num_csrows = 0;
  1454. int csrow = 0;
  1455. int dev_idx = id->driver_data;
  1456. int rc, i;
  1457. u8 sockets;
  1458. if (unlikely(dev_idx >= ARRAY_SIZE(i7core_devs)))
  1459. return -EINVAL;
  1460. /* get the pci devices we want to reserve for our use */
  1461. rc = i7core_get_devices();
  1462. if (unlikely(rc < 0))
  1463. return rc;
  1464. sockets = 1;
  1465. for (i = NUM_SOCKETS - 1; i > 0; i--)
  1466. if (pci_devs[0].pdev[i]) {
  1467. sockets = i + 1;
  1468. break;
  1469. }
  1470. for (i = 0; i < sockets; i++) {
  1471. int channels;
  1472. int csrows;
  1473. /* Check the number of active and not disabled channels */
  1474. rc = i7core_get_active_channels(i, &channels, &csrows);
  1475. if (unlikely(rc < 0))
  1476. goto fail0;
  1477. num_channels += channels;
  1478. num_csrows += csrows;
  1479. }
  1480. /* allocate a new MC control structure */
  1481. mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0);
  1482. if (unlikely(!mci)) {
  1483. rc = -ENOMEM;
  1484. goto fail0;
  1485. }
  1486. debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
  1487. mci->dev = &pdev->dev; /* record ptr to the generic device */
  1488. pvt = mci->pvt_info;
  1489. memset(pvt, 0, sizeof(*pvt));
  1490. pvt->sockets = sockets;
  1491. mci->mc_idx = 0;
  1492. /*
  1493. * FIXME: how to handle RDDR3 at MCI level? It is possible to have
  1494. * Mixed RDDR3/UDDR3 with Nehalem, provided that they are on different
  1495. * memory channels
  1496. */
  1497. mci->mtype_cap = MEM_FLAG_DDR3;
  1498. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  1499. mci->edac_cap = EDAC_FLAG_NONE;
  1500. mci->mod_name = "i7core_edac.c";
  1501. mci->mod_ver = I7CORE_REVISION;
  1502. mci->ctl_name = i7core_devs[dev_idx].ctl_name;
  1503. mci->dev_name = pci_name(pdev);
  1504. mci->ctl_page_to_phys = NULL;
  1505. mci->mc_driver_sysfs_attributes = i7core_inj_attrs;
  1506. /* Set the function pointer to an actual operation function */
  1507. mci->edac_check = i7core_check_error;
  1508. /* Store pci devices at mci for faster access */
  1509. rc = mci_bind_devs(mci);
  1510. if (unlikely(rc < 0))
  1511. goto fail1;
  1512. /* Get dimm basic config */
  1513. for (i = 0; i < sockets; i++)
  1514. get_dimm_config(mci, &csrow, i);
  1515. /* add this new MC control structure to EDAC's list of MCs */
  1516. if (unlikely(edac_mc_add_mc(mci))) {
  1517. debugf0("MC: " __FILE__
  1518. ": %s(): failed edac_mc_add_mc()\n", __func__);
  1519. /* FIXME: perhaps some code should go here that disables error
  1520. * reporting if we just enabled it
  1521. */
  1522. rc = -EINVAL;
  1523. goto fail1;
  1524. }
  1525. /* allocating generic PCI control info */
  1526. i7core_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  1527. if (unlikely(!i7core_pci)) {
  1528. printk(KERN_WARNING
  1529. "%s(): Unable to create PCI control\n",
  1530. __func__);
  1531. printk(KERN_WARNING
  1532. "%s(): PCI error report via EDAC not setup\n",
  1533. __func__);
  1534. }
  1535. /* Default error mask is any memory */
  1536. pvt->inject.channel = 0;
  1537. pvt->inject.dimm = -1;
  1538. pvt->inject.rank = -1;
  1539. pvt->inject.bank = -1;
  1540. pvt->inject.page = -1;
  1541. pvt->inject.col = -1;
  1542. /* Registers on edac_mce in order to receive memory errors */
  1543. pvt->edac_mce.priv = mci;
  1544. pvt->edac_mce.check_error = i7core_mce_check_error;
  1545. spin_lock_init(&pvt->mce_lock);
  1546. rc = edac_mce_register(&pvt->edac_mce);
  1547. if (unlikely(rc < 0)) {
  1548. debugf0("MC: " __FILE__
  1549. ": %s(): failed edac_mce_register()\n", __func__);
  1550. goto fail1;
  1551. }
  1552. i7core_printk(KERN_INFO, "Driver loaded.\n");
  1553. return 0;
  1554. fail1:
  1555. edac_mc_free(mci);
  1556. fail0:
  1557. i7core_put_devices();
  1558. return rc;
  1559. }
  1560. /*
  1561. * i7core_remove destructor for one instance of device
  1562. *
  1563. */
  1564. static void __devexit i7core_remove(struct pci_dev *pdev)
  1565. {
  1566. struct mem_ctl_info *mci;
  1567. struct i7core_pvt *pvt;
  1568. debugf0(__FILE__ ": %s()\n", __func__);
  1569. if (i7core_pci)
  1570. edac_pci_release_generic_ctl(i7core_pci);
  1571. mci = edac_mc_del_mc(&pdev->dev);
  1572. if (!mci)
  1573. return;
  1574. /* Unregisters on edac_mce in order to receive memory errors */
  1575. pvt = mci->pvt_info;
  1576. edac_mce_unregister(&pvt->edac_mce);
  1577. /* retrieve references to resources, and free those resources */
  1578. i7core_put_devices();
  1579. edac_mc_free(mci);
  1580. }
  1581. MODULE_DEVICE_TABLE(pci, i7core_pci_tbl);
  1582. /*
  1583. * i7core_driver pci_driver structure for this module
  1584. *
  1585. */
  1586. static struct pci_driver i7core_driver = {
  1587. .name = "i7core_edac",
  1588. .probe = i7core_probe,
  1589. .remove = __devexit_p(i7core_remove),
  1590. .id_table = i7core_pci_tbl,
  1591. };
  1592. /*
  1593. * i7core_init Module entry function
  1594. * Try to initialize this module for its devices
  1595. */
  1596. static int __init i7core_init(void)
  1597. {
  1598. int pci_rc;
  1599. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  1600. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1601. opstate_init();
  1602. pci_rc = pci_register_driver(&i7core_driver);
  1603. if (pci_rc >= 0)
  1604. return 0;
  1605. i7core_printk(KERN_ERR, "Failed to register device with error %d.\n",
  1606. pci_rc);
  1607. return pci_rc;
  1608. }
  1609. /*
  1610. * i7core_exit() Module exit function
  1611. * Unregister the driver
  1612. */
  1613. static void __exit i7core_exit(void)
  1614. {
  1615. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  1616. pci_unregister_driver(&i7core_driver);
  1617. }
  1618. module_init(i7core_init);
  1619. module_exit(i7core_exit);
  1620. MODULE_LICENSE("GPL");
  1621. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
  1622. MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
  1623. MODULE_DESCRIPTION("MC Driver for Intel i7 Core memory controllers - "
  1624. I7CORE_REVISION);
  1625. module_param(edac_op_state, int, 0444);
  1626. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");