i7core_edac.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365
  1. /* Intel i7 core/Nehalem Memory Controller kernel module
  2. *
  3. * This driver supports the memory controllers found on the Intel
  4. * processor families i7core, i7core 7xx/8xx, i5core, Xeon 35xx,
  5. * Xeon 55xx and Xeon 56xx also known as Nehalem, Nehalem-EP, Lynnfield
  6. * and Westmere-EP.
  7. *
  8. * This file may be distributed under the terms of the
  9. * GNU General Public License version 2 only.
  10. *
  11. * Copyright (c) 2009-2010 by:
  12. * Mauro Carvalho Chehab <mchehab@redhat.com>
  13. *
  14. * Red Hat Inc. http://www.redhat.com
  15. *
  16. * Forked and adapted from the i5400_edac driver
  17. *
  18. * Based on the following public Intel datasheets:
  19. * Intel Core i7 Processor Extreme Edition and Intel Core i7 Processor
  20. * Datasheet, Volume 2:
  21. * http://download.intel.com/design/processor/datashts/320835.pdf
  22. * Intel Xeon Processor 5500 Series Datasheet Volume 2
  23. * http://www.intel.com/Assets/PDF/datasheet/321322.pdf
  24. * also available at:
  25. * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
  26. */
  27. #include <linux/module.h>
  28. #include <linux/init.h>
  29. #include <linux/pci.h>
  30. #include <linux/pci_ids.h>
  31. #include <linux/slab.h>
  32. #include <linux/delay.h>
  33. #include <linux/edac.h>
  34. #include <linux/mmzone.h>
  35. #include <linux/edac_mce.h>
  36. #include <linux/smp.h>
  37. #include <asm/processor.h>
  38. #include "edac_core.h"
  39. /* Static vars */
  40. static LIST_HEAD(i7core_edac_list);
  41. static DEFINE_MUTEX(i7core_edac_lock);
  42. static int probed;
  43. static int use_pci_fixup;
  44. module_param(use_pci_fixup, int, 0444);
  45. MODULE_PARM_DESC(use_pci_fixup, "Enable PCI fixup to seek for hidden devices");
  46. /*
  47. * This is used for Nehalem-EP and Nehalem-EX devices, where the non-core
  48. * registers start at bus 255, and are not reported by BIOS.
  49. * We currently find devices with only 2 sockets. In order to support more QPI
  50. * Quick Path Interconnect, just increment this number.
  51. */
  52. #define MAX_SOCKET_BUSES 2
  53. /*
  54. * Alter this version for the module when modifications are made
  55. */
  56. #define I7CORE_REVISION " Ver: 1.0.0"
  57. #define EDAC_MOD_STR "i7core_edac"
  58. /*
  59. * Debug macros
  60. */
  61. #define i7core_printk(level, fmt, arg...) \
  62. edac_printk(level, "i7core", fmt, ##arg)
  63. #define i7core_mc_printk(mci, level, fmt, arg...) \
  64. edac_mc_chipset_printk(mci, level, "i7core", fmt, ##arg)
  65. /*
  66. * i7core Memory Controller Registers
  67. */
  68. /* OFFSETS for Device 0 Function 0 */
  69. #define MC_CFG_CONTROL 0x90
  70. #define MC_CFG_UNLOCK 0x02
  71. #define MC_CFG_LOCK 0x00
  72. /* OFFSETS for Device 3 Function 0 */
  73. #define MC_CONTROL 0x48
  74. #define MC_STATUS 0x4c
  75. #define MC_MAX_DOD 0x64
  76. /*
  77. * OFFSETS for Device 3 Function 4, as inicated on Xeon 5500 datasheet:
  78. * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
  79. */
  80. #define MC_TEST_ERR_RCV1 0x60
  81. #define DIMM2_COR_ERR(r) ((r) & 0x7fff)
  82. #define MC_TEST_ERR_RCV0 0x64
  83. #define DIMM1_COR_ERR(r) (((r) >> 16) & 0x7fff)
  84. #define DIMM0_COR_ERR(r) ((r) & 0x7fff)
  85. /* OFFSETS for Device 3 Function 2, as inicated on Xeon 5500 datasheet */
  86. #define MC_SSRCONTROL 0x48
  87. #define SSR_MODE_DISABLE 0x00
  88. #define SSR_MODE_ENABLE 0x01
  89. #define SSR_MODE_MASK 0x03
  90. #define MC_SCRUB_CONTROL 0x4c
  91. #define STARTSCRUB (1 << 24)
  92. #define MC_COR_ECC_CNT_0 0x80
  93. #define MC_COR_ECC_CNT_1 0x84
  94. #define MC_COR_ECC_CNT_2 0x88
  95. #define MC_COR_ECC_CNT_3 0x8c
  96. #define MC_COR_ECC_CNT_4 0x90
  97. #define MC_COR_ECC_CNT_5 0x94
  98. #define DIMM_TOP_COR_ERR(r) (((r) >> 16) & 0x7fff)
  99. #define DIMM_BOT_COR_ERR(r) ((r) & 0x7fff)
  100. /* OFFSETS for Devices 4,5 and 6 Function 0 */
  101. #define MC_CHANNEL_DIMM_INIT_PARAMS 0x58
  102. #define THREE_DIMMS_PRESENT (1 << 24)
  103. #define SINGLE_QUAD_RANK_PRESENT (1 << 23)
  104. #define QUAD_RANK_PRESENT (1 << 22)
  105. #define REGISTERED_DIMM (1 << 15)
  106. #define MC_CHANNEL_MAPPER 0x60
  107. #define RDLCH(r, ch) ((((r) >> (3 + (ch * 6))) & 0x07) - 1)
  108. #define WRLCH(r, ch) ((((r) >> (ch * 6)) & 0x07) - 1)
  109. #define MC_CHANNEL_RANK_PRESENT 0x7c
  110. #define RANK_PRESENT_MASK 0xffff
  111. #define MC_CHANNEL_ADDR_MATCH 0xf0
  112. #define MC_CHANNEL_ERROR_MASK 0xf8
  113. #define MC_CHANNEL_ERROR_INJECT 0xfc
  114. #define INJECT_ADDR_PARITY 0x10
  115. #define INJECT_ECC 0x08
  116. #define MASK_CACHELINE 0x06
  117. #define MASK_FULL_CACHELINE 0x06
  118. #define MASK_MSB32_CACHELINE 0x04
  119. #define MASK_LSB32_CACHELINE 0x02
  120. #define NO_MASK_CACHELINE 0x00
  121. #define REPEAT_EN 0x01
  122. /* OFFSETS for Devices 4,5 and 6 Function 1 */
  123. #define MC_DOD_CH_DIMM0 0x48
  124. #define MC_DOD_CH_DIMM1 0x4c
  125. #define MC_DOD_CH_DIMM2 0x50
  126. #define RANKOFFSET_MASK ((1 << 12) | (1 << 11) | (1 << 10))
  127. #define RANKOFFSET(x) ((x & RANKOFFSET_MASK) >> 10)
  128. #define DIMM_PRESENT_MASK (1 << 9)
  129. #define DIMM_PRESENT(x) (((x) & DIMM_PRESENT_MASK) >> 9)
  130. #define MC_DOD_NUMBANK_MASK ((1 << 8) | (1 << 7))
  131. #define MC_DOD_NUMBANK(x) (((x) & MC_DOD_NUMBANK_MASK) >> 7)
  132. #define MC_DOD_NUMRANK_MASK ((1 << 6) | (1 << 5))
  133. #define MC_DOD_NUMRANK(x) (((x) & MC_DOD_NUMRANK_MASK) >> 5)
  134. #define MC_DOD_NUMROW_MASK ((1 << 4) | (1 << 3) | (1 << 2))
  135. #define MC_DOD_NUMROW(x) (((x) & MC_DOD_NUMROW_MASK) >> 2)
  136. #define MC_DOD_NUMCOL_MASK 3
  137. #define MC_DOD_NUMCOL(x) ((x) & MC_DOD_NUMCOL_MASK)
  138. #define MC_RANK_PRESENT 0x7c
  139. #define MC_SAG_CH_0 0x80
  140. #define MC_SAG_CH_1 0x84
  141. #define MC_SAG_CH_2 0x88
  142. #define MC_SAG_CH_3 0x8c
  143. #define MC_SAG_CH_4 0x90
  144. #define MC_SAG_CH_5 0x94
  145. #define MC_SAG_CH_6 0x98
  146. #define MC_SAG_CH_7 0x9c
  147. #define MC_RIR_LIMIT_CH_0 0x40
  148. #define MC_RIR_LIMIT_CH_1 0x44
  149. #define MC_RIR_LIMIT_CH_2 0x48
  150. #define MC_RIR_LIMIT_CH_3 0x4C
  151. #define MC_RIR_LIMIT_CH_4 0x50
  152. #define MC_RIR_LIMIT_CH_5 0x54
  153. #define MC_RIR_LIMIT_CH_6 0x58
  154. #define MC_RIR_LIMIT_CH_7 0x5C
  155. #define MC_RIR_LIMIT_MASK ((1 << 10) - 1)
  156. #define MC_RIR_WAY_CH 0x80
  157. #define MC_RIR_WAY_OFFSET_MASK (((1 << 14) - 1) & ~0x7)
  158. #define MC_RIR_WAY_RANK_MASK 0x7
  159. /*
  160. * i7core structs
  161. */
  162. #define NUM_CHANS 3
  163. #define MAX_DIMMS 3 /* Max DIMMS per channel */
  164. #define MAX_MCR_FUNC 4
  165. #define MAX_CHAN_FUNC 3
  166. struct i7core_info {
  167. u32 mc_control;
  168. u32 mc_status;
  169. u32 max_dod;
  170. u32 ch_map;
  171. };
  172. struct i7core_inject {
  173. int enable;
  174. u32 section;
  175. u32 type;
  176. u32 eccmask;
  177. /* Error address mask */
  178. int channel, dimm, rank, bank, page, col;
  179. };
  180. struct i7core_channel {
  181. u32 ranks;
  182. u32 dimms;
  183. };
  184. struct pci_id_descr {
  185. int dev;
  186. int func;
  187. int dev_id;
  188. int optional;
  189. };
  190. struct pci_id_table {
  191. const struct pci_id_descr *descr;
  192. int n_devs;
  193. };
  194. struct i7core_dev {
  195. struct list_head list;
  196. u8 socket;
  197. struct pci_dev **pdev;
  198. int n_devs;
  199. struct mem_ctl_info *mci;
  200. };
  201. struct i7core_pvt {
  202. struct pci_dev *pci_noncore;
  203. struct pci_dev *pci_mcr[MAX_MCR_FUNC + 1];
  204. struct pci_dev *pci_ch[NUM_CHANS][MAX_CHAN_FUNC + 1];
  205. struct i7core_dev *i7core_dev;
  206. struct i7core_info info;
  207. struct i7core_inject inject;
  208. struct i7core_channel channel[NUM_CHANS];
  209. int ce_count_available;
  210. int csrow_map[NUM_CHANS][MAX_DIMMS];
  211. /* ECC corrected errors counts per udimm */
  212. unsigned long udimm_ce_count[MAX_DIMMS];
  213. int udimm_last_ce_count[MAX_DIMMS];
  214. /* ECC corrected errors counts per rdimm */
  215. unsigned long rdimm_ce_count[NUM_CHANS][MAX_DIMMS];
  216. int rdimm_last_ce_count[NUM_CHANS][MAX_DIMMS];
  217. bool is_registered, enable_scrub;
  218. /* mcelog glue */
  219. struct edac_mce edac_mce;
  220. /* Fifo double buffers */
  221. struct mce mce_entry[MCE_LOG_LEN];
  222. struct mce mce_outentry[MCE_LOG_LEN];
  223. /* Fifo in/out counters */
  224. unsigned mce_in, mce_out;
  225. /* Count indicator to show errors not got */
  226. unsigned mce_overrun;
  227. /* Struct to control EDAC polling */
  228. struct edac_pci_ctl_info *i7core_pci;
  229. };
  230. #define PCI_DESCR(device, function, device_id) \
  231. .dev = (device), \
  232. .func = (function), \
  233. .dev_id = (device_id)
  234. static const struct pci_id_descr pci_dev_descr_i7core_nehalem[] = {
  235. /* Memory controller */
  236. { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_I7_MCR) },
  237. { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_I7_MC_TAD) },
  238. /* Exists only for RDIMM */
  239. { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_I7_MC_RAS), .optional = 1 },
  240. { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_I7_MC_TEST) },
  241. /* Channel 0 */
  242. { PCI_DESCR(4, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH0_CTRL) },
  243. { PCI_DESCR(4, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH0_ADDR) },
  244. { PCI_DESCR(4, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH0_RANK) },
  245. { PCI_DESCR(4, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH0_TC) },
  246. /* Channel 1 */
  247. { PCI_DESCR(5, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH1_CTRL) },
  248. { PCI_DESCR(5, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH1_ADDR) },
  249. { PCI_DESCR(5, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH1_RANK) },
  250. { PCI_DESCR(5, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH1_TC) },
  251. /* Channel 2 */
  252. { PCI_DESCR(6, 0, PCI_DEVICE_ID_INTEL_I7_MC_CH2_CTRL) },
  253. { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH2_ADDR) },
  254. { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH2_RANK) },
  255. { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH2_TC) },
  256. /* Generic Non-core registers */
  257. /*
  258. * This is the PCI device on i7core and on Xeon 35xx (8086:2c41)
  259. * On Xeon 55xx, however, it has a different id (8086:2c40). So,
  260. * the probing code needs to test for the other address in case of
  261. * failure of this one
  262. */
  263. { PCI_DESCR(0, 0, PCI_DEVICE_ID_INTEL_I7_NONCORE) },
  264. };
  265. static const struct pci_id_descr pci_dev_descr_lynnfield[] = {
  266. { PCI_DESCR( 3, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MCR) },
  267. { PCI_DESCR( 3, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TAD) },
  268. { PCI_DESCR( 3, 4, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TEST) },
  269. { PCI_DESCR( 4, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_CTRL) },
  270. { PCI_DESCR( 4, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_ADDR) },
  271. { PCI_DESCR( 4, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_RANK) },
  272. { PCI_DESCR( 4, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_TC) },
  273. { PCI_DESCR( 5, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_CTRL) },
  274. { PCI_DESCR( 5, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_ADDR) },
  275. { PCI_DESCR( 5, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_RANK) },
  276. { PCI_DESCR( 5, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_TC) },
  277. /*
  278. * This is the PCI device has an alternate address on some
  279. * processors like Core i7 860
  280. */
  281. { PCI_DESCR( 0, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE) },
  282. };
  283. static const struct pci_id_descr pci_dev_descr_i7core_westmere[] = {
  284. /* Memory controller */
  285. { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MCR_REV2) },
  286. { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TAD_REV2) },
  287. /* Exists only for RDIMM */
  288. { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_RAS_REV2), .optional = 1 },
  289. { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TEST_REV2) },
  290. /* Channel 0 */
  291. { PCI_DESCR(4, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_CTRL_REV2) },
  292. { PCI_DESCR(4, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_ADDR_REV2) },
  293. { PCI_DESCR(4, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_RANK_REV2) },
  294. { PCI_DESCR(4, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_TC_REV2) },
  295. /* Channel 1 */
  296. { PCI_DESCR(5, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_CTRL_REV2) },
  297. { PCI_DESCR(5, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_ADDR_REV2) },
  298. { PCI_DESCR(5, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_RANK_REV2) },
  299. { PCI_DESCR(5, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_TC_REV2) },
  300. /* Channel 2 */
  301. { PCI_DESCR(6, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_CTRL_REV2) },
  302. { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_ADDR_REV2) },
  303. { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_RANK_REV2) },
  304. { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_TC_REV2) },
  305. /* Generic Non-core registers */
  306. { PCI_DESCR(0, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_REV2) },
  307. };
  308. #define PCI_ID_TABLE_ENTRY(A) { .descr=A, .n_devs = ARRAY_SIZE(A) }
  309. static const struct pci_id_table pci_dev_table[] = {
  310. PCI_ID_TABLE_ENTRY(pci_dev_descr_i7core_nehalem),
  311. PCI_ID_TABLE_ENTRY(pci_dev_descr_lynnfield),
  312. PCI_ID_TABLE_ENTRY(pci_dev_descr_i7core_westmere),
  313. {0,} /* 0 terminated list. */
  314. };
  315. /*
  316. * pci_device_id table for which devices we are looking for
  317. */
  318. static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
  319. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
  320. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
  321. {0,} /* 0 terminated list. */
  322. };
  323. /****************************************************************************
  324. Anciliary status routines
  325. ****************************************************************************/
  326. /* MC_CONTROL bits */
  327. #define CH_ACTIVE(pvt, ch) ((pvt)->info.mc_control & (1 << (8 + ch)))
  328. #define ECCx8(pvt) ((pvt)->info.mc_control & (1 << 1))
  329. /* MC_STATUS bits */
  330. #define ECC_ENABLED(pvt) ((pvt)->info.mc_status & (1 << 4))
  331. #define CH_DISABLED(pvt, ch) ((pvt)->info.mc_status & (1 << ch))
  332. /* MC_MAX_DOD read functions */
  333. static inline int numdimms(u32 dimms)
  334. {
  335. return (dimms & 0x3) + 1;
  336. }
  337. static inline int numrank(u32 rank)
  338. {
  339. static int ranks[4] = { 1, 2, 4, -EINVAL };
  340. return ranks[rank & 0x3];
  341. }
  342. static inline int numbank(u32 bank)
  343. {
  344. static int banks[4] = { 4, 8, 16, -EINVAL };
  345. return banks[bank & 0x3];
  346. }
  347. static inline int numrow(u32 row)
  348. {
  349. static int rows[8] = {
  350. 1 << 12, 1 << 13, 1 << 14, 1 << 15,
  351. 1 << 16, -EINVAL, -EINVAL, -EINVAL,
  352. };
  353. return rows[row & 0x7];
  354. }
  355. static inline int numcol(u32 col)
  356. {
  357. static int cols[8] = {
  358. 1 << 10, 1 << 11, 1 << 12, -EINVAL,
  359. };
  360. return cols[col & 0x3];
  361. }
  362. static struct i7core_dev *get_i7core_dev(u8 socket)
  363. {
  364. struct i7core_dev *i7core_dev;
  365. list_for_each_entry(i7core_dev, &i7core_edac_list, list) {
  366. if (i7core_dev->socket == socket)
  367. return i7core_dev;
  368. }
  369. return NULL;
  370. }
  371. static struct i7core_dev *alloc_i7core_dev(u8 socket,
  372. const struct pci_id_table *table)
  373. {
  374. struct i7core_dev *i7core_dev;
  375. i7core_dev = kzalloc(sizeof(*i7core_dev), GFP_KERNEL);
  376. if (!i7core_dev)
  377. return NULL;
  378. i7core_dev->pdev = kzalloc(sizeof(*i7core_dev->pdev) * table->n_devs,
  379. GFP_KERNEL);
  380. if (!i7core_dev->pdev) {
  381. kfree(i7core_dev);
  382. return NULL;
  383. }
  384. i7core_dev->socket = socket;
  385. i7core_dev->n_devs = table->n_devs;
  386. list_add_tail(&i7core_dev->list, &i7core_edac_list);
  387. return i7core_dev;
  388. }
  389. static void free_i7core_dev(struct i7core_dev *i7core_dev)
  390. {
  391. list_del(&i7core_dev->list);
  392. kfree(i7core_dev->pdev);
  393. kfree(i7core_dev);
  394. }
  395. /****************************************************************************
  396. Memory check routines
  397. ****************************************************************************/
  398. static struct pci_dev *get_pdev_slot_func(u8 socket, unsigned slot,
  399. unsigned func)
  400. {
  401. struct i7core_dev *i7core_dev = get_i7core_dev(socket);
  402. int i;
  403. if (!i7core_dev)
  404. return NULL;
  405. for (i = 0; i < i7core_dev->n_devs; i++) {
  406. if (!i7core_dev->pdev[i])
  407. continue;
  408. if (PCI_SLOT(i7core_dev->pdev[i]->devfn) == slot &&
  409. PCI_FUNC(i7core_dev->pdev[i]->devfn) == func) {
  410. return i7core_dev->pdev[i];
  411. }
  412. }
  413. return NULL;
  414. }
  415. /**
  416. * i7core_get_active_channels() - gets the number of channels and csrows
  417. * @socket: Quick Path Interconnect socket
  418. * @channels: Number of channels that will be returned
  419. * @csrows: Number of csrows found
  420. *
  421. * Since EDAC core needs to know in advance the number of available channels
  422. * and csrows, in order to allocate memory for csrows/channels, it is needed
  423. * to run two similar steps. At the first step, implemented on this function,
  424. * it checks the number of csrows/channels present at one socket.
  425. * this is used in order to properly allocate the size of mci components.
  426. *
  427. * It should be noticed that none of the current available datasheets explain
  428. * or even mention how csrows are seen by the memory controller. So, we need
  429. * to add a fake description for csrows.
  430. * So, this driver is attributing one DIMM memory for one csrow.
  431. */
  432. static int i7core_get_active_channels(const u8 socket, unsigned *channels,
  433. unsigned *csrows)
  434. {
  435. struct pci_dev *pdev = NULL;
  436. int i, j;
  437. u32 status, control;
  438. *channels = 0;
  439. *csrows = 0;
  440. pdev = get_pdev_slot_func(socket, 3, 0);
  441. if (!pdev) {
  442. i7core_printk(KERN_ERR, "Couldn't find socket %d fn 3.0!!!\n",
  443. socket);
  444. return -ENODEV;
  445. }
  446. /* Device 3 function 0 reads */
  447. pci_read_config_dword(pdev, MC_STATUS, &status);
  448. pci_read_config_dword(pdev, MC_CONTROL, &control);
  449. for (i = 0; i < NUM_CHANS; i++) {
  450. u32 dimm_dod[3];
  451. /* Check if the channel is active */
  452. if (!(control & (1 << (8 + i))))
  453. continue;
  454. /* Check if the channel is disabled */
  455. if (status & (1 << i))
  456. continue;
  457. pdev = get_pdev_slot_func(socket, i + 4, 1);
  458. if (!pdev) {
  459. i7core_printk(KERN_ERR, "Couldn't find socket %d "
  460. "fn %d.%d!!!\n",
  461. socket, i + 4, 1);
  462. return -ENODEV;
  463. }
  464. /* Devices 4-6 function 1 */
  465. pci_read_config_dword(pdev,
  466. MC_DOD_CH_DIMM0, &dimm_dod[0]);
  467. pci_read_config_dword(pdev,
  468. MC_DOD_CH_DIMM1, &dimm_dod[1]);
  469. pci_read_config_dword(pdev,
  470. MC_DOD_CH_DIMM2, &dimm_dod[2]);
  471. (*channels)++;
  472. for (j = 0; j < 3; j++) {
  473. if (!DIMM_PRESENT(dimm_dod[j]))
  474. continue;
  475. (*csrows)++;
  476. }
  477. }
  478. debugf0("Number of active channels on socket %d: %d\n",
  479. socket, *channels);
  480. return 0;
  481. }
  482. static int get_dimm_config(const struct mem_ctl_info *mci)
  483. {
  484. struct i7core_pvt *pvt = mci->pvt_info;
  485. struct csrow_info *csr;
  486. struct pci_dev *pdev;
  487. int i, j;
  488. int csrow = 0;
  489. unsigned long last_page = 0;
  490. enum edac_type mode;
  491. enum mem_type mtype;
  492. /* Get data from the MC register, function 0 */
  493. pdev = pvt->pci_mcr[0];
  494. if (!pdev)
  495. return -ENODEV;
  496. /* Device 3 function 0 reads */
  497. pci_read_config_dword(pdev, MC_CONTROL, &pvt->info.mc_control);
  498. pci_read_config_dword(pdev, MC_STATUS, &pvt->info.mc_status);
  499. pci_read_config_dword(pdev, MC_MAX_DOD, &pvt->info.max_dod);
  500. pci_read_config_dword(pdev, MC_CHANNEL_MAPPER, &pvt->info.ch_map);
  501. debugf0("QPI %d control=0x%08x status=0x%08x dod=0x%08x map=0x%08x\n",
  502. pvt->i7core_dev->socket, pvt->info.mc_control, pvt->info.mc_status,
  503. pvt->info.max_dod, pvt->info.ch_map);
  504. if (ECC_ENABLED(pvt)) {
  505. debugf0("ECC enabled with x%d SDCC\n", ECCx8(pvt) ? 8 : 4);
  506. if (ECCx8(pvt))
  507. mode = EDAC_S8ECD8ED;
  508. else
  509. mode = EDAC_S4ECD4ED;
  510. } else {
  511. debugf0("ECC disabled\n");
  512. mode = EDAC_NONE;
  513. }
  514. /* FIXME: need to handle the error codes */
  515. debugf0("DOD Max limits: DIMMS: %d, %d-ranked, %d-banked "
  516. "x%x x 0x%x\n",
  517. numdimms(pvt->info.max_dod),
  518. numrank(pvt->info.max_dod >> 2),
  519. numbank(pvt->info.max_dod >> 4),
  520. numrow(pvt->info.max_dod >> 6),
  521. numcol(pvt->info.max_dod >> 9));
  522. for (i = 0; i < NUM_CHANS; i++) {
  523. u32 data, dimm_dod[3], value[8];
  524. if (!pvt->pci_ch[i][0])
  525. continue;
  526. if (!CH_ACTIVE(pvt, i)) {
  527. debugf0("Channel %i is not active\n", i);
  528. continue;
  529. }
  530. if (CH_DISABLED(pvt, i)) {
  531. debugf0("Channel %i is disabled\n", i);
  532. continue;
  533. }
  534. /* Devices 4-6 function 0 */
  535. pci_read_config_dword(pvt->pci_ch[i][0],
  536. MC_CHANNEL_DIMM_INIT_PARAMS, &data);
  537. pvt->channel[i].ranks = (data & QUAD_RANK_PRESENT) ?
  538. 4 : 2;
  539. if (data & REGISTERED_DIMM)
  540. mtype = MEM_RDDR3;
  541. else
  542. mtype = MEM_DDR3;
  543. #if 0
  544. if (data & THREE_DIMMS_PRESENT)
  545. pvt->channel[i].dimms = 3;
  546. else if (data & SINGLE_QUAD_RANK_PRESENT)
  547. pvt->channel[i].dimms = 1;
  548. else
  549. pvt->channel[i].dimms = 2;
  550. #endif
  551. /* Devices 4-6 function 1 */
  552. pci_read_config_dword(pvt->pci_ch[i][1],
  553. MC_DOD_CH_DIMM0, &dimm_dod[0]);
  554. pci_read_config_dword(pvt->pci_ch[i][1],
  555. MC_DOD_CH_DIMM1, &dimm_dod[1]);
  556. pci_read_config_dword(pvt->pci_ch[i][1],
  557. MC_DOD_CH_DIMM2, &dimm_dod[2]);
  558. debugf0("Ch%d phy rd%d, wr%d (0x%08x): "
  559. "%d ranks, %cDIMMs\n",
  560. i,
  561. RDLCH(pvt->info.ch_map, i), WRLCH(pvt->info.ch_map, i),
  562. data,
  563. pvt->channel[i].ranks,
  564. (data & REGISTERED_DIMM) ? 'R' : 'U');
  565. for (j = 0; j < 3; j++) {
  566. u32 banks, ranks, rows, cols;
  567. u32 size, npages;
  568. if (!DIMM_PRESENT(dimm_dod[j]))
  569. continue;
  570. banks = numbank(MC_DOD_NUMBANK(dimm_dod[j]));
  571. ranks = numrank(MC_DOD_NUMRANK(dimm_dod[j]));
  572. rows = numrow(MC_DOD_NUMROW(dimm_dod[j]));
  573. cols = numcol(MC_DOD_NUMCOL(dimm_dod[j]));
  574. /* DDR3 has 8 I/O banks */
  575. size = (rows * cols * banks * ranks) >> (20 - 3);
  576. pvt->channel[i].dimms++;
  577. debugf0("\tdimm %d %d Mb offset: %x, "
  578. "bank: %d, rank: %d, row: %#x, col: %#x\n",
  579. j, size,
  580. RANKOFFSET(dimm_dod[j]),
  581. banks, ranks, rows, cols);
  582. npages = MiB_TO_PAGES(size);
  583. csr = &mci->csrows[csrow];
  584. csr->first_page = last_page + 1;
  585. last_page += npages;
  586. csr->last_page = last_page;
  587. csr->nr_pages = npages;
  588. csr->page_mask = 0;
  589. csr->grain = 8;
  590. csr->csrow_idx = csrow;
  591. csr->nr_channels = 1;
  592. csr->channels[0].chan_idx = i;
  593. csr->channels[0].ce_count = 0;
  594. pvt->csrow_map[i][j] = csrow;
  595. switch (banks) {
  596. case 4:
  597. csr->dtype = DEV_X4;
  598. break;
  599. case 8:
  600. csr->dtype = DEV_X8;
  601. break;
  602. case 16:
  603. csr->dtype = DEV_X16;
  604. break;
  605. default:
  606. csr->dtype = DEV_UNKNOWN;
  607. }
  608. csr->edac_mode = mode;
  609. csr->mtype = mtype;
  610. csrow++;
  611. }
  612. pci_read_config_dword(pdev, MC_SAG_CH_0, &value[0]);
  613. pci_read_config_dword(pdev, MC_SAG_CH_1, &value[1]);
  614. pci_read_config_dword(pdev, MC_SAG_CH_2, &value[2]);
  615. pci_read_config_dword(pdev, MC_SAG_CH_3, &value[3]);
  616. pci_read_config_dword(pdev, MC_SAG_CH_4, &value[4]);
  617. pci_read_config_dword(pdev, MC_SAG_CH_5, &value[5]);
  618. pci_read_config_dword(pdev, MC_SAG_CH_6, &value[6]);
  619. pci_read_config_dword(pdev, MC_SAG_CH_7, &value[7]);
  620. debugf1("\t[%i] DIVBY3\tREMOVED\tOFFSET\n", i);
  621. for (j = 0; j < 8; j++)
  622. debugf1("\t\t%#x\t%#x\t%#x\n",
  623. (value[j] >> 27) & 0x1,
  624. (value[j] >> 24) & 0x7,
  625. (value[j] & ((1 << 24) - 1)));
  626. }
  627. return 0;
  628. }
  629. /****************************************************************************
  630. Error insertion routines
  631. ****************************************************************************/
  632. /* The i7core has independent error injection features per channel.
  633. However, to have a simpler code, we don't allow enabling error injection
  634. on more than one channel.
  635. Also, since a change at an inject parameter will be applied only at enable,
  636. we're disabling error injection on all write calls to the sysfs nodes that
  637. controls the error code injection.
  638. */
  639. static int disable_inject(const struct mem_ctl_info *mci)
  640. {
  641. struct i7core_pvt *pvt = mci->pvt_info;
  642. pvt->inject.enable = 0;
  643. if (!pvt->pci_ch[pvt->inject.channel][0])
  644. return -ENODEV;
  645. pci_write_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  646. MC_CHANNEL_ERROR_INJECT, 0);
  647. return 0;
  648. }
  649. /*
  650. * i7core inject inject.section
  651. *
  652. * accept and store error injection inject.section value
  653. * bit 0 - refers to the lower 32-byte half cacheline
  654. * bit 1 - refers to the upper 32-byte half cacheline
  655. */
  656. static ssize_t i7core_inject_section_store(struct mem_ctl_info *mci,
  657. const char *data, size_t count)
  658. {
  659. struct i7core_pvt *pvt = mci->pvt_info;
  660. unsigned long value;
  661. int rc;
  662. if (pvt->inject.enable)
  663. disable_inject(mci);
  664. rc = strict_strtoul(data, 10, &value);
  665. if ((rc < 0) || (value > 3))
  666. return -EIO;
  667. pvt->inject.section = (u32) value;
  668. return count;
  669. }
  670. static ssize_t i7core_inject_section_show(struct mem_ctl_info *mci,
  671. char *data)
  672. {
  673. struct i7core_pvt *pvt = mci->pvt_info;
  674. return sprintf(data, "0x%08x\n", pvt->inject.section);
  675. }
  676. /*
  677. * i7core inject.type
  678. *
  679. * accept and store error injection inject.section value
  680. * bit 0 - repeat enable - Enable error repetition
  681. * bit 1 - inject ECC error
  682. * bit 2 - inject parity error
  683. */
  684. static ssize_t i7core_inject_type_store(struct mem_ctl_info *mci,
  685. const char *data, size_t count)
  686. {
  687. struct i7core_pvt *pvt = mci->pvt_info;
  688. unsigned long value;
  689. int rc;
  690. if (pvt->inject.enable)
  691. disable_inject(mci);
  692. rc = strict_strtoul(data, 10, &value);
  693. if ((rc < 0) || (value > 7))
  694. return -EIO;
  695. pvt->inject.type = (u32) value;
  696. return count;
  697. }
  698. static ssize_t i7core_inject_type_show(struct mem_ctl_info *mci,
  699. char *data)
  700. {
  701. struct i7core_pvt *pvt = mci->pvt_info;
  702. return sprintf(data, "0x%08x\n", pvt->inject.type);
  703. }
  704. /*
  705. * i7core_inject_inject.eccmask_store
  706. *
  707. * The type of error (UE/CE) will depend on the inject.eccmask value:
  708. * Any bits set to a 1 will flip the corresponding ECC bit
  709. * Correctable errors can be injected by flipping 1 bit or the bits within
  710. * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or
  711. * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an
  712. * uncorrectable error to be injected.
  713. */
  714. static ssize_t i7core_inject_eccmask_store(struct mem_ctl_info *mci,
  715. const char *data, size_t count)
  716. {
  717. struct i7core_pvt *pvt = mci->pvt_info;
  718. unsigned long value;
  719. int rc;
  720. if (pvt->inject.enable)
  721. disable_inject(mci);
  722. rc = strict_strtoul(data, 10, &value);
  723. if (rc < 0)
  724. return -EIO;
  725. pvt->inject.eccmask = (u32) value;
  726. return count;
  727. }
  728. static ssize_t i7core_inject_eccmask_show(struct mem_ctl_info *mci,
  729. char *data)
  730. {
  731. struct i7core_pvt *pvt = mci->pvt_info;
  732. return sprintf(data, "0x%08x\n", pvt->inject.eccmask);
  733. }
  734. /*
  735. * i7core_addrmatch
  736. *
  737. * The type of error (UE/CE) will depend on the inject.eccmask value:
  738. * Any bits set to a 1 will flip the corresponding ECC bit
  739. * Correctable errors can be injected by flipping 1 bit or the bits within
  740. * a symbol pair (2 consecutive aligned 8-bit pairs - i.e. 7:0 and 15:8 or
  741. * 23:16 and 31:24). Flipping bits in two symbol pairs will cause an
  742. * uncorrectable error to be injected.
  743. */
  744. #define DECLARE_ADDR_MATCH(param, limit) \
  745. static ssize_t i7core_inject_store_##param( \
  746. struct mem_ctl_info *mci, \
  747. const char *data, size_t count) \
  748. { \
  749. struct i7core_pvt *pvt; \
  750. long value; \
  751. int rc; \
  752. \
  753. debugf1("%s()\n", __func__); \
  754. pvt = mci->pvt_info; \
  755. \
  756. if (pvt->inject.enable) \
  757. disable_inject(mci); \
  758. \
  759. if (!strcasecmp(data, "any") || !strcasecmp(data, "any\n"))\
  760. value = -1; \
  761. else { \
  762. rc = strict_strtoul(data, 10, &value); \
  763. if ((rc < 0) || (value >= limit)) \
  764. return -EIO; \
  765. } \
  766. \
  767. pvt->inject.param = value; \
  768. \
  769. return count; \
  770. } \
  771. \
  772. static ssize_t i7core_inject_show_##param( \
  773. struct mem_ctl_info *mci, \
  774. char *data) \
  775. { \
  776. struct i7core_pvt *pvt; \
  777. \
  778. pvt = mci->pvt_info; \
  779. debugf1("%s() pvt=%p\n", __func__, pvt); \
  780. if (pvt->inject.param < 0) \
  781. return sprintf(data, "any\n"); \
  782. else \
  783. return sprintf(data, "%d\n", pvt->inject.param);\
  784. }
  785. #define ATTR_ADDR_MATCH(param) \
  786. { \
  787. .attr = { \
  788. .name = #param, \
  789. .mode = (S_IRUGO | S_IWUSR) \
  790. }, \
  791. .show = i7core_inject_show_##param, \
  792. .store = i7core_inject_store_##param, \
  793. }
  794. DECLARE_ADDR_MATCH(channel, 3);
  795. DECLARE_ADDR_MATCH(dimm, 3);
  796. DECLARE_ADDR_MATCH(rank, 4);
  797. DECLARE_ADDR_MATCH(bank, 32);
  798. DECLARE_ADDR_MATCH(page, 0x10000);
  799. DECLARE_ADDR_MATCH(col, 0x4000);
  800. static int write_and_test(struct pci_dev *dev, const int where, const u32 val)
  801. {
  802. u32 read;
  803. int count;
  804. debugf0("setting pci %02x:%02x.%x reg=%02x value=%08x\n",
  805. dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn),
  806. where, val);
  807. for (count = 0; count < 10; count++) {
  808. if (count)
  809. msleep(100);
  810. pci_write_config_dword(dev, where, val);
  811. pci_read_config_dword(dev, where, &read);
  812. if (read == val)
  813. return 0;
  814. }
  815. i7core_printk(KERN_ERR, "Error during set pci %02x:%02x.%x reg=%02x "
  816. "write=%08x. Read=%08x\n",
  817. dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn),
  818. where, val, read);
  819. return -EINVAL;
  820. }
  821. /*
  822. * This routine prepares the Memory Controller for error injection.
  823. * The error will be injected when some process tries to write to the
  824. * memory that matches the given criteria.
  825. * The criteria can be set in terms of a mask where dimm, rank, bank, page
  826. * and col can be specified.
  827. * A -1 value for any of the mask items will make the MCU to ignore
  828. * that matching criteria for error injection.
  829. *
  830. * It should be noticed that the error will only happen after a write operation
  831. * on a memory that matches the condition. if REPEAT_EN is not enabled at
  832. * inject mask, then it will produce just one error. Otherwise, it will repeat
  833. * until the injectmask would be cleaned.
  834. *
  835. * FIXME: This routine assumes that MAXNUMDIMMS value of MC_MAX_DOD
  836. * is reliable enough to check if the MC is using the
  837. * three channels. However, this is not clear at the datasheet.
  838. */
  839. static ssize_t i7core_inject_enable_store(struct mem_ctl_info *mci,
  840. const char *data, size_t count)
  841. {
  842. struct i7core_pvt *pvt = mci->pvt_info;
  843. u32 injectmask;
  844. u64 mask = 0;
  845. int rc;
  846. long enable;
  847. if (!pvt->pci_ch[pvt->inject.channel][0])
  848. return 0;
  849. rc = strict_strtoul(data, 10, &enable);
  850. if ((rc < 0))
  851. return 0;
  852. if (enable) {
  853. pvt->inject.enable = 1;
  854. } else {
  855. disable_inject(mci);
  856. return count;
  857. }
  858. /* Sets pvt->inject.dimm mask */
  859. if (pvt->inject.dimm < 0)
  860. mask |= 1LL << 41;
  861. else {
  862. if (pvt->channel[pvt->inject.channel].dimms > 2)
  863. mask |= (pvt->inject.dimm & 0x3LL) << 35;
  864. else
  865. mask |= (pvt->inject.dimm & 0x1LL) << 36;
  866. }
  867. /* Sets pvt->inject.rank mask */
  868. if (pvt->inject.rank < 0)
  869. mask |= 1LL << 40;
  870. else {
  871. if (pvt->channel[pvt->inject.channel].dimms > 2)
  872. mask |= (pvt->inject.rank & 0x1LL) << 34;
  873. else
  874. mask |= (pvt->inject.rank & 0x3LL) << 34;
  875. }
  876. /* Sets pvt->inject.bank mask */
  877. if (pvt->inject.bank < 0)
  878. mask |= 1LL << 39;
  879. else
  880. mask |= (pvt->inject.bank & 0x15LL) << 30;
  881. /* Sets pvt->inject.page mask */
  882. if (pvt->inject.page < 0)
  883. mask |= 1LL << 38;
  884. else
  885. mask |= (pvt->inject.page & 0xffff) << 14;
  886. /* Sets pvt->inject.column mask */
  887. if (pvt->inject.col < 0)
  888. mask |= 1LL << 37;
  889. else
  890. mask |= (pvt->inject.col & 0x3fff);
  891. /*
  892. * bit 0: REPEAT_EN
  893. * bits 1-2: MASK_HALF_CACHELINE
  894. * bit 3: INJECT_ECC
  895. * bit 4: INJECT_ADDR_PARITY
  896. */
  897. injectmask = (pvt->inject.type & 1) |
  898. (pvt->inject.section & 0x3) << 1 |
  899. (pvt->inject.type & 0x6) << (3 - 1);
  900. /* Unlock writes to registers - this register is write only */
  901. pci_write_config_dword(pvt->pci_noncore,
  902. MC_CFG_CONTROL, 0x2);
  903. write_and_test(pvt->pci_ch[pvt->inject.channel][0],
  904. MC_CHANNEL_ADDR_MATCH, mask);
  905. write_and_test(pvt->pci_ch[pvt->inject.channel][0],
  906. MC_CHANNEL_ADDR_MATCH + 4, mask >> 32L);
  907. write_and_test(pvt->pci_ch[pvt->inject.channel][0],
  908. MC_CHANNEL_ERROR_MASK, pvt->inject.eccmask);
  909. write_and_test(pvt->pci_ch[pvt->inject.channel][0],
  910. MC_CHANNEL_ERROR_INJECT, injectmask);
  911. /*
  912. * This is something undocumented, based on my tests
  913. * Without writing 8 to this register, errors aren't injected. Not sure
  914. * why.
  915. */
  916. pci_write_config_dword(pvt->pci_noncore,
  917. MC_CFG_CONTROL, 8);
  918. debugf0("Error inject addr match 0x%016llx, ecc 0x%08x,"
  919. " inject 0x%08x\n",
  920. mask, pvt->inject.eccmask, injectmask);
  921. return count;
  922. }
  923. static ssize_t i7core_inject_enable_show(struct mem_ctl_info *mci,
  924. char *data)
  925. {
  926. struct i7core_pvt *pvt = mci->pvt_info;
  927. u32 injectmask;
  928. if (!pvt->pci_ch[pvt->inject.channel][0])
  929. return 0;
  930. pci_read_config_dword(pvt->pci_ch[pvt->inject.channel][0],
  931. MC_CHANNEL_ERROR_INJECT, &injectmask);
  932. debugf0("Inject error read: 0x%018x\n", injectmask);
  933. if (injectmask & 0x0c)
  934. pvt->inject.enable = 1;
  935. return sprintf(data, "%d\n", pvt->inject.enable);
  936. }
  937. #define DECLARE_COUNTER(param) \
  938. static ssize_t i7core_show_counter_##param( \
  939. struct mem_ctl_info *mci, \
  940. char *data) \
  941. { \
  942. struct i7core_pvt *pvt = mci->pvt_info; \
  943. \
  944. debugf1("%s() \n", __func__); \
  945. if (!pvt->ce_count_available || (pvt->is_registered)) \
  946. return sprintf(data, "data unavailable\n"); \
  947. return sprintf(data, "%lu\n", \
  948. pvt->udimm_ce_count[param]); \
  949. }
  950. #define ATTR_COUNTER(param) \
  951. { \
  952. .attr = { \
  953. .name = __stringify(udimm##param), \
  954. .mode = (S_IRUGO | S_IWUSR) \
  955. }, \
  956. .show = i7core_show_counter_##param \
  957. }
  958. DECLARE_COUNTER(0);
  959. DECLARE_COUNTER(1);
  960. DECLARE_COUNTER(2);
  961. /*
  962. * Sysfs struct
  963. */
  964. static const struct mcidev_sysfs_attribute i7core_addrmatch_attrs[] = {
  965. ATTR_ADDR_MATCH(channel),
  966. ATTR_ADDR_MATCH(dimm),
  967. ATTR_ADDR_MATCH(rank),
  968. ATTR_ADDR_MATCH(bank),
  969. ATTR_ADDR_MATCH(page),
  970. ATTR_ADDR_MATCH(col),
  971. { } /* End of list */
  972. };
  973. static const struct mcidev_sysfs_group i7core_inject_addrmatch = {
  974. .name = "inject_addrmatch",
  975. .mcidev_attr = i7core_addrmatch_attrs,
  976. };
  977. static const struct mcidev_sysfs_attribute i7core_udimm_counters_attrs[] = {
  978. ATTR_COUNTER(0),
  979. ATTR_COUNTER(1),
  980. ATTR_COUNTER(2),
  981. { .attr = { .name = NULL } }
  982. };
  983. static const struct mcidev_sysfs_group i7core_udimm_counters = {
  984. .name = "all_channel_counts",
  985. .mcidev_attr = i7core_udimm_counters_attrs,
  986. };
  987. static const struct mcidev_sysfs_attribute i7core_sysfs_rdimm_attrs[] = {
  988. {
  989. .attr = {
  990. .name = "inject_section",
  991. .mode = (S_IRUGO | S_IWUSR)
  992. },
  993. .show = i7core_inject_section_show,
  994. .store = i7core_inject_section_store,
  995. }, {
  996. .attr = {
  997. .name = "inject_type",
  998. .mode = (S_IRUGO | S_IWUSR)
  999. },
  1000. .show = i7core_inject_type_show,
  1001. .store = i7core_inject_type_store,
  1002. }, {
  1003. .attr = {
  1004. .name = "inject_eccmask",
  1005. .mode = (S_IRUGO | S_IWUSR)
  1006. },
  1007. .show = i7core_inject_eccmask_show,
  1008. .store = i7core_inject_eccmask_store,
  1009. }, {
  1010. .grp = &i7core_inject_addrmatch,
  1011. }, {
  1012. .attr = {
  1013. .name = "inject_enable",
  1014. .mode = (S_IRUGO | S_IWUSR)
  1015. },
  1016. .show = i7core_inject_enable_show,
  1017. .store = i7core_inject_enable_store,
  1018. },
  1019. { } /* End of list */
  1020. };
  1021. static const struct mcidev_sysfs_attribute i7core_sysfs_udimm_attrs[] = {
  1022. {
  1023. .attr = {
  1024. .name = "inject_section",
  1025. .mode = (S_IRUGO | S_IWUSR)
  1026. },
  1027. .show = i7core_inject_section_show,
  1028. .store = i7core_inject_section_store,
  1029. }, {
  1030. .attr = {
  1031. .name = "inject_type",
  1032. .mode = (S_IRUGO | S_IWUSR)
  1033. },
  1034. .show = i7core_inject_type_show,
  1035. .store = i7core_inject_type_store,
  1036. }, {
  1037. .attr = {
  1038. .name = "inject_eccmask",
  1039. .mode = (S_IRUGO | S_IWUSR)
  1040. },
  1041. .show = i7core_inject_eccmask_show,
  1042. .store = i7core_inject_eccmask_store,
  1043. }, {
  1044. .grp = &i7core_inject_addrmatch,
  1045. }, {
  1046. .attr = {
  1047. .name = "inject_enable",
  1048. .mode = (S_IRUGO | S_IWUSR)
  1049. },
  1050. .show = i7core_inject_enable_show,
  1051. .store = i7core_inject_enable_store,
  1052. }, {
  1053. .grp = &i7core_udimm_counters,
  1054. },
  1055. { } /* End of list */
  1056. };
  1057. /****************************************************************************
  1058. Device initialization routines: put/get, init/exit
  1059. ****************************************************************************/
  1060. /*
  1061. * i7core_put_all_devices 'put' all the devices that we have
  1062. * reserved via 'get'
  1063. */
  1064. static void i7core_put_devices(struct i7core_dev *i7core_dev)
  1065. {
  1066. int i;
  1067. debugf0(__FILE__ ": %s()\n", __func__);
  1068. for (i = 0; i < i7core_dev->n_devs; i++) {
  1069. struct pci_dev *pdev = i7core_dev->pdev[i];
  1070. if (!pdev)
  1071. continue;
  1072. debugf0("Removing dev %02x:%02x.%d\n",
  1073. pdev->bus->number,
  1074. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  1075. pci_dev_put(pdev);
  1076. }
  1077. }
  1078. static void i7core_put_all_devices(void)
  1079. {
  1080. struct i7core_dev *i7core_dev, *tmp;
  1081. list_for_each_entry_safe(i7core_dev, tmp, &i7core_edac_list, list) {
  1082. i7core_put_devices(i7core_dev);
  1083. free_i7core_dev(i7core_dev);
  1084. }
  1085. }
  1086. static void __init i7core_xeon_pci_fixup(const struct pci_id_table *table)
  1087. {
  1088. struct pci_dev *pdev = NULL;
  1089. int i;
  1090. /*
  1091. * On Xeon 55xx, the Intel Quick Path Arch Generic Non-core pci buses
  1092. * aren't announced by acpi. So, we need to use a legacy scan probing
  1093. * to detect them
  1094. */
  1095. while (table && table->descr) {
  1096. pdev = pci_get_device(PCI_VENDOR_ID_INTEL, table->descr[0].dev_id, NULL);
  1097. if (unlikely(!pdev)) {
  1098. for (i = 0; i < MAX_SOCKET_BUSES; i++)
  1099. pcibios_scan_specific_bus(255-i);
  1100. }
  1101. pci_dev_put(pdev);
  1102. table++;
  1103. }
  1104. }
  1105. static unsigned i7core_pci_lastbus(void)
  1106. {
  1107. int last_bus = 0, bus;
  1108. struct pci_bus *b = NULL;
  1109. while ((b = pci_find_next_bus(b)) != NULL) {
  1110. bus = b->number;
  1111. debugf0("Found bus %d\n", bus);
  1112. if (bus > last_bus)
  1113. last_bus = bus;
  1114. }
  1115. debugf0("Last bus %d\n", last_bus);
  1116. return last_bus;
  1117. }
  1118. /*
  1119. * i7core_get_all_devices Find and perform 'get' operation on the MCH's
  1120. * device/functions we want to reference for this driver
  1121. *
  1122. * Need to 'get' device 16 func 1 and func 2
  1123. */
  1124. static int i7core_get_onedevice(struct pci_dev **prev,
  1125. const struct pci_id_table *table,
  1126. const unsigned devno,
  1127. const unsigned last_bus)
  1128. {
  1129. struct i7core_dev *i7core_dev;
  1130. const struct pci_id_descr *dev_descr = &table->descr[devno];
  1131. struct pci_dev *pdev = NULL;
  1132. u8 bus = 0;
  1133. u8 socket = 0;
  1134. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  1135. dev_descr->dev_id, *prev);
  1136. /*
  1137. * On Xeon 55xx, the Intel Quckpath Arch Generic Non-core regs
  1138. * is at addr 8086:2c40, instead of 8086:2c41. So, we need
  1139. * to probe for the alternate address in case of failure
  1140. */
  1141. if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_I7_NONCORE && !pdev)
  1142. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  1143. PCI_DEVICE_ID_INTEL_I7_NONCORE_ALT, *prev);
  1144. if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE && !pdev)
  1145. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  1146. PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_ALT,
  1147. *prev);
  1148. if (!pdev) {
  1149. if (*prev) {
  1150. *prev = pdev;
  1151. return 0;
  1152. }
  1153. if (dev_descr->optional)
  1154. return 0;
  1155. if (devno == 0)
  1156. return -ENODEV;
  1157. i7core_printk(KERN_INFO,
  1158. "Device not found: dev %02x.%d PCI ID %04x:%04x\n",
  1159. dev_descr->dev, dev_descr->func,
  1160. PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
  1161. /* End of list, leave */
  1162. return -ENODEV;
  1163. }
  1164. bus = pdev->bus->number;
  1165. socket = last_bus - bus;
  1166. i7core_dev = get_i7core_dev(socket);
  1167. if (!i7core_dev) {
  1168. i7core_dev = alloc_i7core_dev(socket, table);
  1169. if (!i7core_dev) {
  1170. pci_dev_put(pdev);
  1171. return -ENOMEM;
  1172. }
  1173. }
  1174. if (i7core_dev->pdev[devno]) {
  1175. i7core_printk(KERN_ERR,
  1176. "Duplicated device for "
  1177. "dev %02x:%02x.%d PCI ID %04x:%04x\n",
  1178. bus, dev_descr->dev, dev_descr->func,
  1179. PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
  1180. pci_dev_put(pdev);
  1181. return -ENODEV;
  1182. }
  1183. i7core_dev->pdev[devno] = pdev;
  1184. /* Sanity check */
  1185. if (unlikely(PCI_SLOT(pdev->devfn) != dev_descr->dev ||
  1186. PCI_FUNC(pdev->devfn) != dev_descr->func)) {
  1187. i7core_printk(KERN_ERR,
  1188. "Device PCI ID %04x:%04x "
  1189. "has dev %02x:%02x.%d instead of dev %02x:%02x.%d\n",
  1190. PCI_VENDOR_ID_INTEL, dev_descr->dev_id,
  1191. bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
  1192. bus, dev_descr->dev, dev_descr->func);
  1193. return -ENODEV;
  1194. }
  1195. /* Be sure that the device is enabled */
  1196. if (unlikely(pci_enable_device(pdev) < 0)) {
  1197. i7core_printk(KERN_ERR,
  1198. "Couldn't enable "
  1199. "dev %02x:%02x.%d PCI ID %04x:%04x\n",
  1200. bus, dev_descr->dev, dev_descr->func,
  1201. PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
  1202. return -ENODEV;
  1203. }
  1204. debugf0("Detected socket %d dev %02x:%02x.%d PCI ID %04x:%04x\n",
  1205. socket, bus, dev_descr->dev,
  1206. dev_descr->func,
  1207. PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
  1208. /*
  1209. * As stated on drivers/pci/search.c, the reference count for
  1210. * @from is always decremented if it is not %NULL. So, as we need
  1211. * to get all devices up to null, we need to do a get for the device
  1212. */
  1213. pci_dev_get(pdev);
  1214. *prev = pdev;
  1215. return 0;
  1216. }
  1217. static int i7core_get_all_devices(void)
  1218. {
  1219. int i, rc, last_bus;
  1220. struct pci_dev *pdev = NULL;
  1221. const struct pci_id_table *table = pci_dev_table;
  1222. last_bus = i7core_pci_lastbus();
  1223. while (table && table->descr) {
  1224. for (i = 0; i < table->n_devs; i++) {
  1225. pdev = NULL;
  1226. do {
  1227. rc = i7core_get_onedevice(&pdev, table, i,
  1228. last_bus);
  1229. if (rc < 0) {
  1230. if (i == 0) {
  1231. i = table->n_devs;
  1232. break;
  1233. }
  1234. i7core_put_all_devices();
  1235. return -ENODEV;
  1236. }
  1237. } while (pdev);
  1238. }
  1239. table++;
  1240. }
  1241. return 0;
  1242. }
  1243. static int mci_bind_devs(struct mem_ctl_info *mci,
  1244. struct i7core_dev *i7core_dev)
  1245. {
  1246. struct i7core_pvt *pvt = mci->pvt_info;
  1247. struct pci_dev *pdev;
  1248. int i, func, slot;
  1249. char *family;
  1250. pvt->is_registered = false;
  1251. pvt->enable_scrub = false;
  1252. for (i = 0; i < i7core_dev->n_devs; i++) {
  1253. pdev = i7core_dev->pdev[i];
  1254. if (!pdev)
  1255. continue;
  1256. func = PCI_FUNC(pdev->devfn);
  1257. slot = PCI_SLOT(pdev->devfn);
  1258. if (slot == 3) {
  1259. if (unlikely(func > MAX_MCR_FUNC))
  1260. goto error;
  1261. pvt->pci_mcr[func] = pdev;
  1262. } else if (likely(slot >= 4 && slot < 4 + NUM_CHANS)) {
  1263. if (unlikely(func > MAX_CHAN_FUNC))
  1264. goto error;
  1265. pvt->pci_ch[slot - 4][func] = pdev;
  1266. } else if (!slot && !func) {
  1267. pvt->pci_noncore = pdev;
  1268. /* Detect the processor family */
  1269. switch (pdev->device) {
  1270. case PCI_DEVICE_ID_INTEL_I7_NONCORE:
  1271. family = "Xeon 35xx/ i7core";
  1272. pvt->enable_scrub = false;
  1273. break;
  1274. case PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_ALT:
  1275. family = "i7-800/i5-700";
  1276. pvt->enable_scrub = false;
  1277. break;
  1278. case PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE:
  1279. family = "Xeon 34xx";
  1280. pvt->enable_scrub = false;
  1281. break;
  1282. case PCI_DEVICE_ID_INTEL_I7_NONCORE_ALT:
  1283. family = "Xeon 55xx";
  1284. pvt->enable_scrub = true;
  1285. break;
  1286. case PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_REV2:
  1287. family = "Xeon 56xx / i7-900";
  1288. pvt->enable_scrub = true;
  1289. break;
  1290. default:
  1291. family = "unknown";
  1292. pvt->enable_scrub = false;
  1293. }
  1294. debugf0("Detected a processor type %s\n", family);
  1295. } else
  1296. goto error;
  1297. debugf0("Associated fn %d.%d, dev = %p, socket %d\n",
  1298. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
  1299. pdev, i7core_dev->socket);
  1300. if (PCI_SLOT(pdev->devfn) == 3 &&
  1301. PCI_FUNC(pdev->devfn) == 2)
  1302. pvt->is_registered = true;
  1303. }
  1304. return 0;
  1305. error:
  1306. i7core_printk(KERN_ERR, "Device %d, function %d "
  1307. "is out of the expected range\n",
  1308. slot, func);
  1309. return -EINVAL;
  1310. }
  1311. /****************************************************************************
  1312. Error check routines
  1313. ****************************************************************************/
  1314. static void i7core_rdimm_update_csrow(struct mem_ctl_info *mci,
  1315. const int chan,
  1316. const int dimm,
  1317. const int add)
  1318. {
  1319. char *msg;
  1320. struct i7core_pvt *pvt = mci->pvt_info;
  1321. int row = pvt->csrow_map[chan][dimm], i;
  1322. for (i = 0; i < add; i++) {
  1323. msg = kasprintf(GFP_KERNEL, "Corrected error "
  1324. "(Socket=%d channel=%d dimm=%d)",
  1325. pvt->i7core_dev->socket, chan, dimm);
  1326. edac_mc_handle_fbd_ce(mci, row, 0, msg);
  1327. kfree (msg);
  1328. }
  1329. }
  1330. static void i7core_rdimm_update_ce_count(struct mem_ctl_info *mci,
  1331. const int chan,
  1332. const int new0,
  1333. const int new1,
  1334. const int new2)
  1335. {
  1336. struct i7core_pvt *pvt = mci->pvt_info;
  1337. int add0 = 0, add1 = 0, add2 = 0;
  1338. /* Updates CE counters if it is not the first time here */
  1339. if (pvt->ce_count_available) {
  1340. /* Updates CE counters */
  1341. add2 = new2 - pvt->rdimm_last_ce_count[chan][2];
  1342. add1 = new1 - pvt->rdimm_last_ce_count[chan][1];
  1343. add0 = new0 - pvt->rdimm_last_ce_count[chan][0];
  1344. if (add2 < 0)
  1345. add2 += 0x7fff;
  1346. pvt->rdimm_ce_count[chan][2] += add2;
  1347. if (add1 < 0)
  1348. add1 += 0x7fff;
  1349. pvt->rdimm_ce_count[chan][1] += add1;
  1350. if (add0 < 0)
  1351. add0 += 0x7fff;
  1352. pvt->rdimm_ce_count[chan][0] += add0;
  1353. } else
  1354. pvt->ce_count_available = 1;
  1355. /* Store the new values */
  1356. pvt->rdimm_last_ce_count[chan][2] = new2;
  1357. pvt->rdimm_last_ce_count[chan][1] = new1;
  1358. pvt->rdimm_last_ce_count[chan][0] = new0;
  1359. /*updated the edac core */
  1360. if (add0 != 0)
  1361. i7core_rdimm_update_csrow(mci, chan, 0, add0);
  1362. if (add1 != 0)
  1363. i7core_rdimm_update_csrow(mci, chan, 1, add1);
  1364. if (add2 != 0)
  1365. i7core_rdimm_update_csrow(mci, chan, 2, add2);
  1366. }
  1367. static void i7core_rdimm_check_mc_ecc_err(struct mem_ctl_info *mci)
  1368. {
  1369. struct i7core_pvt *pvt = mci->pvt_info;
  1370. u32 rcv[3][2];
  1371. int i, new0, new1, new2;
  1372. /*Read DEV 3: FUN 2: MC_COR_ECC_CNT regs directly*/
  1373. pci_read_config_dword(pvt->pci_mcr[2], MC_COR_ECC_CNT_0,
  1374. &rcv[0][0]);
  1375. pci_read_config_dword(pvt->pci_mcr[2], MC_COR_ECC_CNT_1,
  1376. &rcv[0][1]);
  1377. pci_read_config_dword(pvt->pci_mcr[2], MC_COR_ECC_CNT_2,
  1378. &rcv[1][0]);
  1379. pci_read_config_dword(pvt->pci_mcr[2], MC_COR_ECC_CNT_3,
  1380. &rcv[1][1]);
  1381. pci_read_config_dword(pvt->pci_mcr[2], MC_COR_ECC_CNT_4,
  1382. &rcv[2][0]);
  1383. pci_read_config_dword(pvt->pci_mcr[2], MC_COR_ECC_CNT_5,
  1384. &rcv[2][1]);
  1385. for (i = 0 ; i < 3; i++) {
  1386. debugf3("MC_COR_ECC_CNT%d = 0x%x; MC_COR_ECC_CNT%d = 0x%x\n",
  1387. (i * 2), rcv[i][0], (i * 2) + 1, rcv[i][1]);
  1388. /*if the channel has 3 dimms*/
  1389. if (pvt->channel[i].dimms > 2) {
  1390. new0 = DIMM_BOT_COR_ERR(rcv[i][0]);
  1391. new1 = DIMM_TOP_COR_ERR(rcv[i][0]);
  1392. new2 = DIMM_BOT_COR_ERR(rcv[i][1]);
  1393. } else {
  1394. new0 = DIMM_TOP_COR_ERR(rcv[i][0]) +
  1395. DIMM_BOT_COR_ERR(rcv[i][0]);
  1396. new1 = DIMM_TOP_COR_ERR(rcv[i][1]) +
  1397. DIMM_BOT_COR_ERR(rcv[i][1]);
  1398. new2 = 0;
  1399. }
  1400. i7core_rdimm_update_ce_count(mci, i, new0, new1, new2);
  1401. }
  1402. }
  1403. /* This function is based on the device 3 function 4 registers as described on:
  1404. * Intel Xeon Processor 5500 Series Datasheet Volume 2
  1405. * http://www.intel.com/Assets/PDF/datasheet/321322.pdf
  1406. * also available at:
  1407. * http://www.arrownac.com/manufacturers/intel/s/nehalem/5500-datasheet-v2.pdf
  1408. */
  1409. static void i7core_udimm_check_mc_ecc_err(struct mem_ctl_info *mci)
  1410. {
  1411. struct i7core_pvt *pvt = mci->pvt_info;
  1412. u32 rcv1, rcv0;
  1413. int new0, new1, new2;
  1414. if (!pvt->pci_mcr[4]) {
  1415. debugf0("%s MCR registers not found\n", __func__);
  1416. return;
  1417. }
  1418. /* Corrected test errors */
  1419. pci_read_config_dword(pvt->pci_mcr[4], MC_TEST_ERR_RCV1, &rcv1);
  1420. pci_read_config_dword(pvt->pci_mcr[4], MC_TEST_ERR_RCV0, &rcv0);
  1421. /* Store the new values */
  1422. new2 = DIMM2_COR_ERR(rcv1);
  1423. new1 = DIMM1_COR_ERR(rcv0);
  1424. new0 = DIMM0_COR_ERR(rcv0);
  1425. /* Updates CE counters if it is not the first time here */
  1426. if (pvt->ce_count_available) {
  1427. /* Updates CE counters */
  1428. int add0, add1, add2;
  1429. add2 = new2 - pvt->udimm_last_ce_count[2];
  1430. add1 = new1 - pvt->udimm_last_ce_count[1];
  1431. add0 = new0 - pvt->udimm_last_ce_count[0];
  1432. if (add2 < 0)
  1433. add2 += 0x7fff;
  1434. pvt->udimm_ce_count[2] += add2;
  1435. if (add1 < 0)
  1436. add1 += 0x7fff;
  1437. pvt->udimm_ce_count[1] += add1;
  1438. if (add0 < 0)
  1439. add0 += 0x7fff;
  1440. pvt->udimm_ce_count[0] += add0;
  1441. if (add0 | add1 | add2)
  1442. i7core_printk(KERN_ERR, "New Corrected error(s): "
  1443. "dimm0: +%d, dimm1: +%d, dimm2 +%d\n",
  1444. add0, add1, add2);
  1445. } else
  1446. pvt->ce_count_available = 1;
  1447. /* Store the new values */
  1448. pvt->udimm_last_ce_count[2] = new2;
  1449. pvt->udimm_last_ce_count[1] = new1;
  1450. pvt->udimm_last_ce_count[0] = new0;
  1451. }
  1452. /*
  1453. * According with tables E-11 and E-12 of chapter E.3.3 of Intel 64 and IA-32
  1454. * Architectures Software Developer’s Manual Volume 3B.
  1455. * Nehalem are defined as family 0x06, model 0x1a
  1456. *
  1457. * The MCA registers used here are the following ones:
  1458. * struct mce field MCA Register
  1459. * m->status MSR_IA32_MC8_STATUS
  1460. * m->addr MSR_IA32_MC8_ADDR
  1461. * m->misc MSR_IA32_MC8_MISC
  1462. * In the case of Nehalem, the error information is masked at .status and .misc
  1463. * fields
  1464. */
  1465. static void i7core_mce_output_error(struct mem_ctl_info *mci,
  1466. const struct mce *m)
  1467. {
  1468. struct i7core_pvt *pvt = mci->pvt_info;
  1469. char *type, *optype, *err, *msg;
  1470. unsigned long error = m->status & 0x1ff0000l;
  1471. u32 optypenum = (m->status >> 4) & 0x07;
  1472. u32 core_err_cnt = (m->status >> 38) & 0x7fff;
  1473. u32 dimm = (m->misc >> 16) & 0x3;
  1474. u32 channel = (m->misc >> 18) & 0x3;
  1475. u32 syndrome = m->misc >> 32;
  1476. u32 errnum = find_first_bit(&error, 32);
  1477. int csrow;
  1478. if (m->mcgstatus & 1)
  1479. type = "FATAL";
  1480. else
  1481. type = "NON_FATAL";
  1482. switch (optypenum) {
  1483. case 0:
  1484. optype = "generic undef request";
  1485. break;
  1486. case 1:
  1487. optype = "read error";
  1488. break;
  1489. case 2:
  1490. optype = "write error";
  1491. break;
  1492. case 3:
  1493. optype = "addr/cmd error";
  1494. break;
  1495. case 4:
  1496. optype = "scrubbing error";
  1497. break;
  1498. default:
  1499. optype = "reserved";
  1500. break;
  1501. }
  1502. switch (errnum) {
  1503. case 16:
  1504. err = "read ECC error";
  1505. break;
  1506. case 17:
  1507. err = "RAS ECC error";
  1508. break;
  1509. case 18:
  1510. err = "write parity error";
  1511. break;
  1512. case 19:
  1513. err = "redundacy loss";
  1514. break;
  1515. case 20:
  1516. err = "reserved";
  1517. break;
  1518. case 21:
  1519. err = "memory range error";
  1520. break;
  1521. case 22:
  1522. err = "RTID out of range";
  1523. break;
  1524. case 23:
  1525. err = "address parity error";
  1526. break;
  1527. case 24:
  1528. err = "byte enable parity error";
  1529. break;
  1530. default:
  1531. err = "unknown";
  1532. }
  1533. /* FIXME: should convert addr into bank and rank information */
  1534. msg = kasprintf(GFP_ATOMIC,
  1535. "%s (addr = 0x%08llx, cpu=%d, Dimm=%d, Channel=%d, "
  1536. "syndrome=0x%08x, count=%d, Err=%08llx:%08llx (%s: %s))\n",
  1537. type, (long long) m->addr, m->cpu, dimm, channel,
  1538. syndrome, core_err_cnt, (long long)m->status,
  1539. (long long)m->misc, optype, err);
  1540. debugf0("%s", msg);
  1541. csrow = pvt->csrow_map[channel][dimm];
  1542. /* Call the helper to output message */
  1543. if (m->mcgstatus & 1)
  1544. edac_mc_handle_fbd_ue(mci, csrow, 0,
  1545. 0 /* FIXME: should be channel here */, msg);
  1546. else if (!pvt->is_registered)
  1547. edac_mc_handle_fbd_ce(mci, csrow,
  1548. 0 /* FIXME: should be channel here */, msg);
  1549. kfree(msg);
  1550. }
  1551. /*
  1552. * i7core_check_error Retrieve and process errors reported by the
  1553. * hardware. Called by the Core module.
  1554. */
  1555. static void i7core_check_error(struct mem_ctl_info *mci)
  1556. {
  1557. struct i7core_pvt *pvt = mci->pvt_info;
  1558. int i;
  1559. unsigned count = 0;
  1560. struct mce *m;
  1561. /*
  1562. * MCE first step: Copy all mce errors into a temporary buffer
  1563. * We use a double buffering here, to reduce the risk of
  1564. * losing an error.
  1565. */
  1566. smp_rmb();
  1567. count = (pvt->mce_out + MCE_LOG_LEN - pvt->mce_in)
  1568. % MCE_LOG_LEN;
  1569. if (!count)
  1570. goto check_ce_error;
  1571. m = pvt->mce_outentry;
  1572. if (pvt->mce_in + count > MCE_LOG_LEN) {
  1573. unsigned l = MCE_LOG_LEN - pvt->mce_in;
  1574. memcpy(m, &pvt->mce_entry[pvt->mce_in], sizeof(*m) * l);
  1575. smp_wmb();
  1576. pvt->mce_in = 0;
  1577. count -= l;
  1578. m += l;
  1579. }
  1580. memcpy(m, &pvt->mce_entry[pvt->mce_in], sizeof(*m) * count);
  1581. smp_wmb();
  1582. pvt->mce_in += count;
  1583. smp_rmb();
  1584. if (pvt->mce_overrun) {
  1585. i7core_printk(KERN_ERR, "Lost %d memory errors\n",
  1586. pvt->mce_overrun);
  1587. smp_wmb();
  1588. pvt->mce_overrun = 0;
  1589. }
  1590. /*
  1591. * MCE second step: parse errors and display
  1592. */
  1593. for (i = 0; i < count; i++)
  1594. i7core_mce_output_error(mci, &pvt->mce_outentry[i]);
  1595. /*
  1596. * Now, let's increment CE error counts
  1597. */
  1598. check_ce_error:
  1599. if (!pvt->is_registered)
  1600. i7core_udimm_check_mc_ecc_err(mci);
  1601. else
  1602. i7core_rdimm_check_mc_ecc_err(mci);
  1603. }
  1604. /*
  1605. * i7core_mce_check_error Replicates mcelog routine to get errors
  1606. * This routine simply queues mcelog errors, and
  1607. * return. The error itself should be handled later
  1608. * by i7core_check_error.
  1609. * WARNING: As this routine should be called at NMI time, extra care should
  1610. * be taken to avoid deadlocks, and to be as fast as possible.
  1611. */
  1612. static int i7core_mce_check_error(void *priv, struct mce *mce)
  1613. {
  1614. struct mem_ctl_info *mci = priv;
  1615. struct i7core_pvt *pvt = mci->pvt_info;
  1616. /*
  1617. * Just let mcelog handle it if the error is
  1618. * outside the memory controller
  1619. */
  1620. if (((mce->status & 0xffff) >> 7) != 1)
  1621. return 0;
  1622. /* Bank 8 registers are the only ones that we know how to handle */
  1623. if (mce->bank != 8)
  1624. return 0;
  1625. #ifdef CONFIG_SMP
  1626. /* Only handle if it is the right mc controller */
  1627. if (cpu_data(mce->cpu).phys_proc_id != pvt->i7core_dev->socket)
  1628. return 0;
  1629. #endif
  1630. smp_rmb();
  1631. if ((pvt->mce_out + 1) % MCE_LOG_LEN == pvt->mce_in) {
  1632. smp_wmb();
  1633. pvt->mce_overrun++;
  1634. return 0;
  1635. }
  1636. /* Copy memory error at the ringbuffer */
  1637. memcpy(&pvt->mce_entry[pvt->mce_out], mce, sizeof(*mce));
  1638. smp_wmb();
  1639. pvt->mce_out = (pvt->mce_out + 1) % MCE_LOG_LEN;
  1640. /* Handle fatal errors immediately */
  1641. if (mce->mcgstatus & 1)
  1642. i7core_check_error(mci);
  1643. /* Advise mcelog that the errors were handled */
  1644. return 1;
  1645. }
  1646. /*
  1647. * set_sdram_scrub_rate This routine sets byte/sec bandwidth scrub rate
  1648. * to hardware according to SCRUBINTERVAL formula
  1649. * found in datasheet.
  1650. */
  1651. static int set_sdram_scrub_rate(struct mem_ctl_info *mci, u32 new_bw)
  1652. {
  1653. struct i7core_pvt *pvt = mci->pvt_info;
  1654. struct pci_dev *pdev;
  1655. const u32 cache_line_size = 64;
  1656. const u32 freq_dclk = 800*1000000;
  1657. u32 dw_scrub;
  1658. u32 dw_ssr;
  1659. /* Get data from the MC register, function 2 */
  1660. pdev = pvt->pci_mcr[2];
  1661. if (!pdev)
  1662. return -ENODEV;
  1663. pci_read_config_dword(pdev, MC_SCRUB_CONTROL, &dw_scrub);
  1664. if (new_bw == 0) {
  1665. /* Prepare to disable petrol scrub */
  1666. dw_scrub &= ~STARTSCRUB;
  1667. /* Stop the patrol scrub engine */
  1668. write_and_test(pdev, MC_SCRUB_CONTROL, dw_scrub & ~0x00ffffff);
  1669. /* Get current status of scrub rate and set bit to disable */
  1670. pci_read_config_dword(pdev, MC_SSRCONTROL, &dw_ssr);
  1671. dw_ssr &= ~SSR_MODE_MASK;
  1672. dw_ssr |= SSR_MODE_DISABLE;
  1673. } else {
  1674. /*
  1675. * Translate the desired scrub rate to a register value and
  1676. * program the cooresponding register value.
  1677. */
  1678. dw_scrub = 0x00ffffff & (cache_line_size * freq_dclk / new_bw);
  1679. /* Start the patrol scrub engine */
  1680. pci_write_config_dword(pdev, MC_SCRUB_CONTROL,
  1681. STARTSCRUB | dw_scrub);
  1682. /* Get current status of scrub rate and set bit to enable */
  1683. pci_read_config_dword(pdev, MC_SSRCONTROL, &dw_ssr);
  1684. dw_ssr &= ~SSR_MODE_MASK;
  1685. dw_ssr |= SSR_MODE_ENABLE;
  1686. }
  1687. /* Disable or enable scrubbing */
  1688. pci_write_config_dword(pdev, MC_SSRCONTROL, dw_ssr);
  1689. return new_bw;
  1690. }
  1691. /*
  1692. * get_sdram_scrub_rate This routine convert current scrub rate value
  1693. * into byte/sec bandwidth accourding to
  1694. * SCRUBINTERVAL formula found in datasheet.
  1695. */
  1696. static int get_sdram_scrub_rate(struct mem_ctl_info *mci)
  1697. {
  1698. struct i7core_pvt *pvt = mci->pvt_info;
  1699. struct pci_dev *pdev;
  1700. const u32 cache_line_size = 64;
  1701. const u32 freq_dclk = 800*1000000;
  1702. u32 scrubval;
  1703. /* Get data from the MC register, function 2 */
  1704. pdev = pvt->pci_mcr[2];
  1705. if (!pdev)
  1706. return -ENODEV;
  1707. /* Get current scrub control data */
  1708. pci_read_config_dword(pdev, MC_SCRUB_CONTROL, &scrubval);
  1709. /* Mask highest 8-bits to 0 */
  1710. scrubval &= 0x00ffffff;
  1711. if (!scrubval)
  1712. return 0;
  1713. /* Calculate scrub rate value into byte/sec bandwidth */
  1714. return 0xffffffff & (cache_line_size * freq_dclk / (u64) scrubval);
  1715. }
  1716. static void enable_sdram_scrub_setting(struct mem_ctl_info *mci)
  1717. {
  1718. struct i7core_pvt *pvt = mci->pvt_info;
  1719. u32 pci_lock;
  1720. /* Unlock writes to pci registers */
  1721. pci_read_config_dword(pvt->pci_noncore, MC_CFG_CONTROL, &pci_lock);
  1722. pci_lock &= ~0x3;
  1723. pci_write_config_dword(pvt->pci_noncore, MC_CFG_CONTROL,
  1724. pci_lock | MC_CFG_UNLOCK);
  1725. mci->set_sdram_scrub_rate = set_sdram_scrub_rate;
  1726. mci->get_sdram_scrub_rate = get_sdram_scrub_rate;
  1727. }
  1728. static void disable_sdram_scrub_setting(struct mem_ctl_info *mci)
  1729. {
  1730. struct i7core_pvt *pvt = mci->pvt_info;
  1731. u32 pci_lock;
  1732. /* Lock writes to pci registers */
  1733. pci_read_config_dword(pvt->pci_noncore, MC_CFG_CONTROL, &pci_lock);
  1734. pci_lock &= ~0x3;
  1735. pci_write_config_dword(pvt->pci_noncore, MC_CFG_CONTROL,
  1736. pci_lock | MC_CFG_LOCK);
  1737. }
  1738. static void i7core_pci_ctl_create(struct i7core_pvt *pvt)
  1739. {
  1740. pvt->i7core_pci = edac_pci_create_generic_ctl(
  1741. &pvt->i7core_dev->pdev[0]->dev,
  1742. EDAC_MOD_STR);
  1743. if (unlikely(!pvt->i7core_pci))
  1744. pr_warn("Unable to setup PCI error report via EDAC\n");
  1745. }
  1746. static void i7core_pci_ctl_release(struct i7core_pvt *pvt)
  1747. {
  1748. if (likely(pvt->i7core_pci))
  1749. edac_pci_release_generic_ctl(pvt->i7core_pci);
  1750. else
  1751. i7core_printk(KERN_ERR,
  1752. "Couldn't find mem_ctl_info for socket %d\n",
  1753. pvt->i7core_dev->socket);
  1754. pvt->i7core_pci = NULL;
  1755. }
  1756. static void i7core_unregister_mci(struct i7core_dev *i7core_dev)
  1757. {
  1758. struct mem_ctl_info *mci = i7core_dev->mci;
  1759. struct i7core_pvt *pvt;
  1760. if (unlikely(!mci || !mci->pvt_info)) {
  1761. debugf0("MC: " __FILE__ ": %s(): dev = %p\n",
  1762. __func__, &i7core_dev->pdev[0]->dev);
  1763. i7core_printk(KERN_ERR, "Couldn't find mci handler\n");
  1764. return;
  1765. }
  1766. pvt = mci->pvt_info;
  1767. debugf0("MC: " __FILE__ ": %s(): mci = %p, dev = %p\n",
  1768. __func__, mci, &i7core_dev->pdev[0]->dev);
  1769. /* Disable scrubrate setting */
  1770. if (pvt->enable_scrub)
  1771. disable_sdram_scrub_setting(mci);
  1772. /* Disable MCE NMI handler */
  1773. edac_mce_unregister(&pvt->edac_mce);
  1774. /* Disable EDAC polling */
  1775. i7core_pci_ctl_release(pvt);
  1776. /* Remove MC sysfs nodes */
  1777. edac_mc_del_mc(mci->dev);
  1778. debugf1("%s: free mci struct\n", mci->ctl_name);
  1779. kfree(mci->ctl_name);
  1780. edac_mc_free(mci);
  1781. i7core_dev->mci = NULL;
  1782. }
  1783. static int i7core_register_mci(struct i7core_dev *i7core_dev)
  1784. {
  1785. struct mem_ctl_info *mci;
  1786. struct i7core_pvt *pvt;
  1787. int rc, channels, csrows;
  1788. /* Check the number of active and not disabled channels */
  1789. rc = i7core_get_active_channels(i7core_dev->socket, &channels, &csrows);
  1790. if (unlikely(rc < 0))
  1791. return rc;
  1792. /* allocate a new MC control structure */
  1793. mci = edac_mc_alloc(sizeof(*pvt), csrows, channels, i7core_dev->socket);
  1794. if (unlikely(!mci))
  1795. return -ENOMEM;
  1796. debugf0("MC: " __FILE__ ": %s(): mci = %p, dev = %p\n",
  1797. __func__, mci, &i7core_dev->pdev[0]->dev);
  1798. pvt = mci->pvt_info;
  1799. memset(pvt, 0, sizeof(*pvt));
  1800. /* Associates i7core_dev and mci for future usage */
  1801. pvt->i7core_dev = i7core_dev;
  1802. i7core_dev->mci = mci;
  1803. /*
  1804. * FIXME: how to handle RDDR3 at MCI level? It is possible to have
  1805. * Mixed RDDR3/UDDR3 with Nehalem, provided that they are on different
  1806. * memory channels
  1807. */
  1808. mci->mtype_cap = MEM_FLAG_DDR3;
  1809. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  1810. mci->edac_cap = EDAC_FLAG_NONE;
  1811. mci->mod_name = "i7core_edac.c";
  1812. mci->mod_ver = I7CORE_REVISION;
  1813. mci->ctl_name = kasprintf(GFP_KERNEL, "i7 core #%d",
  1814. i7core_dev->socket);
  1815. mci->dev_name = pci_name(i7core_dev->pdev[0]);
  1816. mci->ctl_page_to_phys = NULL;
  1817. /* Store pci devices at mci for faster access */
  1818. rc = mci_bind_devs(mci, i7core_dev);
  1819. if (unlikely(rc < 0))
  1820. goto fail0;
  1821. if (pvt->is_registered)
  1822. mci->mc_driver_sysfs_attributes = i7core_sysfs_rdimm_attrs;
  1823. else
  1824. mci->mc_driver_sysfs_attributes = i7core_sysfs_udimm_attrs;
  1825. /* Get dimm basic config */
  1826. get_dimm_config(mci);
  1827. /* record ptr to the generic device */
  1828. mci->dev = &i7core_dev->pdev[0]->dev;
  1829. /* Set the function pointer to an actual operation function */
  1830. mci->edac_check = i7core_check_error;
  1831. /* Enable scrubrate setting */
  1832. if (pvt->enable_scrub)
  1833. enable_sdram_scrub_setting(mci);
  1834. /* add this new MC control structure to EDAC's list of MCs */
  1835. if (unlikely(edac_mc_add_mc(mci))) {
  1836. debugf0("MC: " __FILE__
  1837. ": %s(): failed edac_mc_add_mc()\n", __func__);
  1838. /* FIXME: perhaps some code should go here that disables error
  1839. * reporting if we just enabled it
  1840. */
  1841. rc = -EINVAL;
  1842. goto fail0;
  1843. }
  1844. /* Default error mask is any memory */
  1845. pvt->inject.channel = 0;
  1846. pvt->inject.dimm = -1;
  1847. pvt->inject.rank = -1;
  1848. pvt->inject.bank = -1;
  1849. pvt->inject.page = -1;
  1850. pvt->inject.col = -1;
  1851. /* allocating generic PCI control info */
  1852. i7core_pci_ctl_create(pvt);
  1853. /* Registers on edac_mce in order to receive memory errors */
  1854. pvt->edac_mce.priv = mci;
  1855. pvt->edac_mce.check_error = i7core_mce_check_error;
  1856. rc = edac_mce_register(&pvt->edac_mce);
  1857. if (unlikely(rc < 0)) {
  1858. debugf0("MC: " __FILE__
  1859. ": %s(): failed edac_mce_register()\n", __func__);
  1860. goto fail1;
  1861. }
  1862. return 0;
  1863. fail1:
  1864. i7core_pci_ctl_release(pvt);
  1865. edac_mc_del_mc(mci->dev);
  1866. fail0:
  1867. kfree(mci->ctl_name);
  1868. edac_mc_free(mci);
  1869. i7core_dev->mci = NULL;
  1870. return rc;
  1871. }
  1872. /*
  1873. * i7core_probe Probe for ONE instance of device to see if it is
  1874. * present.
  1875. * return:
  1876. * 0 for FOUND a device
  1877. * < 0 for error code
  1878. */
  1879. static int __devinit i7core_probe(struct pci_dev *pdev,
  1880. const struct pci_device_id *id)
  1881. {
  1882. int rc;
  1883. struct i7core_dev *i7core_dev;
  1884. /* get the pci devices we want to reserve for our use */
  1885. mutex_lock(&i7core_edac_lock);
  1886. /*
  1887. * All memory controllers are allocated at the first pass.
  1888. */
  1889. if (unlikely(probed >= 1)) {
  1890. mutex_unlock(&i7core_edac_lock);
  1891. return -ENODEV;
  1892. }
  1893. probed++;
  1894. rc = i7core_get_all_devices();
  1895. if (unlikely(rc < 0))
  1896. goto fail0;
  1897. list_for_each_entry(i7core_dev, &i7core_edac_list, list) {
  1898. rc = i7core_register_mci(i7core_dev);
  1899. if (unlikely(rc < 0))
  1900. goto fail1;
  1901. }
  1902. i7core_printk(KERN_INFO, "Driver loaded.\n");
  1903. mutex_unlock(&i7core_edac_lock);
  1904. return 0;
  1905. fail1:
  1906. list_for_each_entry(i7core_dev, &i7core_edac_list, list)
  1907. i7core_unregister_mci(i7core_dev);
  1908. i7core_put_all_devices();
  1909. fail0:
  1910. mutex_unlock(&i7core_edac_lock);
  1911. return rc;
  1912. }
  1913. /*
  1914. * i7core_remove destructor for one instance of device
  1915. *
  1916. */
  1917. static void __devexit i7core_remove(struct pci_dev *pdev)
  1918. {
  1919. struct i7core_dev *i7core_dev;
  1920. debugf0(__FILE__ ": %s()\n", __func__);
  1921. /*
  1922. * we have a trouble here: pdev value for removal will be wrong, since
  1923. * it will point to the X58 register used to detect that the machine
  1924. * is a Nehalem or upper design. However, due to the way several PCI
  1925. * devices are grouped together to provide MC functionality, we need
  1926. * to use a different method for releasing the devices
  1927. */
  1928. mutex_lock(&i7core_edac_lock);
  1929. if (unlikely(!probed)) {
  1930. mutex_unlock(&i7core_edac_lock);
  1931. return;
  1932. }
  1933. list_for_each_entry(i7core_dev, &i7core_edac_list, list)
  1934. i7core_unregister_mci(i7core_dev);
  1935. /* Release PCI resources */
  1936. i7core_put_all_devices();
  1937. probed--;
  1938. mutex_unlock(&i7core_edac_lock);
  1939. }
  1940. MODULE_DEVICE_TABLE(pci, i7core_pci_tbl);
  1941. /*
  1942. * i7core_driver pci_driver structure for this module
  1943. *
  1944. */
  1945. static struct pci_driver i7core_driver = {
  1946. .name = "i7core_edac",
  1947. .probe = i7core_probe,
  1948. .remove = __devexit_p(i7core_remove),
  1949. .id_table = i7core_pci_tbl,
  1950. };
  1951. /*
  1952. * i7core_init Module entry function
  1953. * Try to initialize this module for its devices
  1954. */
  1955. static int __init i7core_init(void)
  1956. {
  1957. int pci_rc;
  1958. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  1959. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1960. opstate_init();
  1961. if (use_pci_fixup)
  1962. i7core_xeon_pci_fixup(pci_dev_table);
  1963. pci_rc = pci_register_driver(&i7core_driver);
  1964. if (pci_rc >= 0)
  1965. return 0;
  1966. i7core_printk(KERN_ERR, "Failed to register device with error %d.\n",
  1967. pci_rc);
  1968. return pci_rc;
  1969. }
  1970. /*
  1971. * i7core_exit() Module exit function
  1972. * Unregister the driver
  1973. */
  1974. static void __exit i7core_exit(void)
  1975. {
  1976. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  1977. pci_unregister_driver(&i7core_driver);
  1978. }
  1979. module_init(i7core_init);
  1980. module_exit(i7core_exit);
  1981. MODULE_LICENSE("GPL");
  1982. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
  1983. MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
  1984. MODULE_DESCRIPTION("MC Driver for Intel i7 Core memory controllers - "
  1985. I7CORE_REVISION);
  1986. module_param(edac_op_state, int, 0444);
  1987. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");