edac_mc.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129
  1. /*
  2. * edac_mc kernel module
  3. * (C) 2005 Linux Networx (http://lnxi.com)
  4. * This file may be distributed under the terms of the
  5. * GNU General Public License.
  6. *
  7. * Written by Thayne Harbaugh
  8. * Based on work by Dan Hollis <goemon at anime dot net> and others.
  9. * http://www.anime.net/~goemon/linux-ecc/
  10. *
  11. * Modified by Dave Peterson and Doug Thompson
  12. *
  13. */
  14. #include <linux/config.h>
  15. #include <linux/module.h>
  16. #include <linux/proc_fs.h>
  17. #include <linux/kernel.h>
  18. #include <linux/types.h>
  19. #include <linux/smp.h>
  20. #include <linux/init.h>
  21. #include <linux/sysctl.h>
  22. #include <linux/highmem.h>
  23. #include <linux/timer.h>
  24. #include <linux/slab.h>
  25. #include <linux/jiffies.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/list.h>
  28. #include <linux/sysdev.h>
  29. #include <linux/ctype.h>
  30. #include <linux/kthread.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/page.h>
  33. #include <asm/edac.h>
  34. #include "edac_mc.h"
  35. #define EDAC_MC_VERSION "Ver: 2.0.0 " __DATE__
  36. /* For now, disable the EDAC sysfs code. The sysfs interface that EDAC
  37. * presents to user space needs more thought, and is likely to change
  38. * substantially.
  39. */
  40. #define DISABLE_EDAC_SYSFS
  41. #ifdef CONFIG_EDAC_DEBUG
  42. /* Values of 0 to 4 will generate output */
  43. int edac_debug_level = 1;
  44. EXPORT_SYMBOL_GPL(edac_debug_level);
  45. #endif
  46. /* EDAC Controls, setable by module parameter, and sysfs */
  47. static int log_ue = 1;
  48. static int log_ce = 1;
  49. static int panic_on_ue;
  50. static int poll_msec = 1000;
  51. /* lock to memory controller's control array */
  52. static DECLARE_MUTEX(mem_ctls_mutex);
  53. static struct list_head mc_devices = LIST_HEAD_INIT(mc_devices);
  54. static struct task_struct *edac_thread;
  55. #ifdef CONFIG_PCI
  56. static int check_pci_parity = 0; /* default YES check PCI parity */
  57. static int panic_on_pci_parity; /* default no panic on PCI Parity */
  58. static atomic_t pci_parity_count = ATOMIC_INIT(0);
  59. /* Structure of the whitelist and blacklist arrays */
  60. struct edac_pci_device_list {
  61. unsigned int vendor; /* Vendor ID */
  62. unsigned int device; /* Deviice ID */
  63. };
  64. #define MAX_LISTED_PCI_DEVICES 32
  65. /* List of PCI devices (vendor-id:device-id) that should be skipped */
  66. static struct edac_pci_device_list pci_blacklist[MAX_LISTED_PCI_DEVICES];
  67. static int pci_blacklist_count;
  68. /* List of PCI devices (vendor-id:device-id) that should be scanned */
  69. static struct edac_pci_device_list pci_whitelist[MAX_LISTED_PCI_DEVICES];
  70. static int pci_whitelist_count ;
  71. #ifndef DISABLE_EDAC_SYSFS
  72. static struct kobject edac_pci_kobj; /* /sys/devices/system/edac/pci */
  73. static struct completion edac_pci_kobj_complete;
  74. #endif /* DISABLE_EDAC_SYSFS */
  75. #endif /* CONFIG_PCI */
  76. /* START sysfs data and methods */
  77. #ifndef DISABLE_EDAC_SYSFS
  78. static const char *mem_types[] = {
  79. [MEM_EMPTY] = "Empty",
  80. [MEM_RESERVED] = "Reserved",
  81. [MEM_UNKNOWN] = "Unknown",
  82. [MEM_FPM] = "FPM",
  83. [MEM_EDO] = "EDO",
  84. [MEM_BEDO] = "BEDO",
  85. [MEM_SDR] = "Unbuffered-SDR",
  86. [MEM_RDR] = "Registered-SDR",
  87. [MEM_DDR] = "Unbuffered-DDR",
  88. [MEM_RDDR] = "Registered-DDR",
  89. [MEM_RMBS] = "RMBS"
  90. };
  91. static const char *dev_types[] = {
  92. [DEV_UNKNOWN] = "Unknown",
  93. [DEV_X1] = "x1",
  94. [DEV_X2] = "x2",
  95. [DEV_X4] = "x4",
  96. [DEV_X8] = "x8",
  97. [DEV_X16] = "x16",
  98. [DEV_X32] = "x32",
  99. [DEV_X64] = "x64"
  100. };
  101. static const char *edac_caps[] = {
  102. [EDAC_UNKNOWN] = "Unknown",
  103. [EDAC_NONE] = "None",
  104. [EDAC_RESERVED] = "Reserved",
  105. [EDAC_PARITY] = "PARITY",
  106. [EDAC_EC] = "EC",
  107. [EDAC_SECDED] = "SECDED",
  108. [EDAC_S2ECD2ED] = "S2ECD2ED",
  109. [EDAC_S4ECD4ED] = "S4ECD4ED",
  110. [EDAC_S8ECD8ED] = "S8ECD8ED",
  111. [EDAC_S16ECD16ED] = "S16ECD16ED"
  112. };
  113. /* sysfs object: /sys/devices/system/edac */
  114. static struct sysdev_class edac_class = {
  115. set_kset_name("edac"),
  116. };
  117. /* sysfs object:
  118. * /sys/devices/system/edac/mc
  119. */
  120. static struct kobject edac_memctrl_kobj;
  121. /* We use these to wait for the reference counts on edac_memctrl_kobj and
  122. * edac_pci_kobj to reach 0.
  123. */
  124. static struct completion edac_memctrl_kobj_complete;
  125. /*
  126. * /sys/devices/system/edac/mc;
  127. * data structures and methods
  128. */
  129. #if 0
  130. static ssize_t memctrl_string_show(void *ptr, char *buffer)
  131. {
  132. char *value = (char*) ptr;
  133. return sprintf(buffer, "%s\n", value);
  134. }
  135. #endif
  136. static ssize_t memctrl_int_show(void *ptr, char *buffer)
  137. {
  138. int *value = (int*) ptr;
  139. return sprintf(buffer, "%d\n", *value);
  140. }
  141. static ssize_t memctrl_int_store(void *ptr, const char *buffer, size_t count)
  142. {
  143. int *value = (int*) ptr;
  144. if (isdigit(*buffer))
  145. *value = simple_strtoul(buffer, NULL, 0);
  146. return count;
  147. }
  148. struct memctrl_dev_attribute {
  149. struct attribute attr;
  150. void *value;
  151. ssize_t (*show)(void *,char *);
  152. ssize_t (*store)(void *, const char *, size_t);
  153. };
  154. /* Set of show/store abstract level functions for memory control object */
  155. static ssize_t memctrl_dev_show(struct kobject *kobj,
  156. struct attribute *attr, char *buffer)
  157. {
  158. struct memctrl_dev_attribute *memctrl_dev;
  159. memctrl_dev = (struct memctrl_dev_attribute*)attr;
  160. if (memctrl_dev->show)
  161. return memctrl_dev->show(memctrl_dev->value, buffer);
  162. return -EIO;
  163. }
  164. static ssize_t memctrl_dev_store(struct kobject *kobj, struct attribute *attr,
  165. const char *buffer, size_t count)
  166. {
  167. struct memctrl_dev_attribute *memctrl_dev;
  168. memctrl_dev = (struct memctrl_dev_attribute*)attr;
  169. if (memctrl_dev->store)
  170. return memctrl_dev->store(memctrl_dev->value, buffer, count);
  171. return -EIO;
  172. }
  173. static struct sysfs_ops memctrlfs_ops = {
  174. .show = memctrl_dev_show,
  175. .store = memctrl_dev_store
  176. };
  177. #define MEMCTRL_ATTR(_name,_mode,_show,_store) \
  178. struct memctrl_dev_attribute attr_##_name = { \
  179. .attr = {.name = __stringify(_name), .mode = _mode }, \
  180. .value = &_name, \
  181. .show = _show, \
  182. .store = _store, \
  183. };
  184. #define MEMCTRL_STRING_ATTR(_name,_data,_mode,_show,_store) \
  185. struct memctrl_dev_attribute attr_##_name = { \
  186. .attr = {.name = __stringify(_name), .mode = _mode }, \
  187. .value = _data, \
  188. .show = _show, \
  189. .store = _store, \
  190. };
  191. /* cwrow<id> attribute f*/
  192. #if 0
  193. MEMCTRL_STRING_ATTR(mc_version,EDAC_MC_VERSION,S_IRUGO,memctrl_string_show,NULL);
  194. #endif
  195. /* csrow<id> control files */
  196. MEMCTRL_ATTR(panic_on_ue,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store);
  197. MEMCTRL_ATTR(log_ue,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store);
  198. MEMCTRL_ATTR(log_ce,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store);
  199. MEMCTRL_ATTR(poll_msec,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store);
  200. /* Base Attributes of the memory ECC object */
  201. static struct memctrl_dev_attribute *memctrl_attr[] = {
  202. &attr_panic_on_ue,
  203. &attr_log_ue,
  204. &attr_log_ce,
  205. &attr_poll_msec,
  206. NULL,
  207. };
  208. /* Main MC kobject release() function */
  209. static void edac_memctrl_master_release(struct kobject *kobj)
  210. {
  211. debugf1("%s()\n", __func__);
  212. complete(&edac_memctrl_kobj_complete);
  213. }
  214. static struct kobj_type ktype_memctrl = {
  215. .release = edac_memctrl_master_release,
  216. .sysfs_ops = &memctrlfs_ops,
  217. .default_attrs = (struct attribute **) memctrl_attr,
  218. };
  219. #endif /* DISABLE_EDAC_SYSFS */
  220. /* Initialize the main sysfs entries for edac:
  221. * /sys/devices/system/edac
  222. *
  223. * and children
  224. *
  225. * Return: 0 SUCCESS
  226. * !0 FAILURE
  227. */
  228. static int edac_sysfs_memctrl_setup(void)
  229. #ifdef DISABLE_EDAC_SYSFS
  230. {
  231. return 0;
  232. }
  233. #else
  234. {
  235. int err=0;
  236. debugf1("%s()\n", __func__);
  237. /* create the /sys/devices/system/edac directory */
  238. err = sysdev_class_register(&edac_class);
  239. if (!err) {
  240. /* Init the MC's kobject */
  241. memset(&edac_memctrl_kobj, 0, sizeof (edac_memctrl_kobj));
  242. edac_memctrl_kobj.parent = &edac_class.kset.kobj;
  243. edac_memctrl_kobj.ktype = &ktype_memctrl;
  244. /* generate sysfs "..../edac/mc" */
  245. err = kobject_set_name(&edac_memctrl_kobj,"mc");
  246. if (!err) {
  247. /* FIXME: maybe new sysdev_create_subdir() */
  248. err = kobject_register(&edac_memctrl_kobj);
  249. if (err)
  250. debugf1("Failed to register '.../edac/mc'\n");
  251. else
  252. debugf1("Registered '.../edac/mc' kobject\n");
  253. }
  254. } else
  255. debugf1("%s() error=%d\n", __func__, err);
  256. return err;
  257. }
  258. #endif /* DISABLE_EDAC_SYSFS */
  259. /*
  260. * MC teardown:
  261. * the '..../edac/mc' kobject followed by '..../edac' itself
  262. */
  263. static void edac_sysfs_memctrl_teardown(void)
  264. {
  265. #ifndef DISABLE_EDAC_SYSFS
  266. debugf0("MC: " __FILE__ ": %s()\n", __func__);
  267. /* Unregister the MC's kobject and wait for reference count to reach
  268. * 0.
  269. */
  270. init_completion(&edac_memctrl_kobj_complete);
  271. kobject_unregister(&edac_memctrl_kobj);
  272. wait_for_completion(&edac_memctrl_kobj_complete);
  273. /* Unregister the 'edac' object */
  274. sysdev_class_unregister(&edac_class);
  275. #endif /* DISABLE_EDAC_SYSFS */
  276. }
  277. #ifdef CONFIG_PCI
  278. #ifndef DISABLE_EDAC_SYSFS
  279. /*
  280. * /sys/devices/system/edac/pci;
  281. * data structures and methods
  282. */
  283. struct list_control {
  284. struct edac_pci_device_list *list;
  285. int *count;
  286. };
  287. #if 0
  288. /* Output the list as: vendor_id:device:id<,vendor_id:device_id> */
  289. static ssize_t edac_pci_list_string_show(void *ptr, char *buffer)
  290. {
  291. struct list_control *listctl;
  292. struct edac_pci_device_list *list;
  293. char *p = buffer;
  294. int len=0;
  295. int i;
  296. listctl = ptr;
  297. list = listctl->list;
  298. for (i = 0; i < *(listctl->count); i++, list++ ) {
  299. if (len > 0)
  300. len += snprintf(p + len, (PAGE_SIZE-len), ",");
  301. len += snprintf(p + len,
  302. (PAGE_SIZE-len),
  303. "%x:%x",
  304. list->vendor,list->device);
  305. }
  306. len += snprintf(p + len,(PAGE_SIZE-len), "\n");
  307. return (ssize_t) len;
  308. }
  309. /**
  310. *
  311. * Scan string from **s to **e looking for one 'vendor:device' tuple
  312. * where each field is a hex value
  313. *
  314. * return 0 if an entry is NOT found
  315. * return 1 if an entry is found
  316. * fill in *vendor_id and *device_id with values found
  317. *
  318. * In both cases, make sure *s has been moved forward toward *e
  319. */
  320. static int parse_one_device(const char **s,const char **e,
  321. unsigned int *vendor_id, unsigned int *device_id)
  322. {
  323. const char *runner, *p;
  324. /* if null byte, we are done */
  325. if (!**s) {
  326. (*s)++; /* keep *s moving */
  327. return 0;
  328. }
  329. /* skip over newlines & whitespace */
  330. if ((**s == '\n') || isspace(**s)) {
  331. (*s)++;
  332. return 0;
  333. }
  334. if (!isxdigit(**s)) {
  335. (*s)++;
  336. return 0;
  337. }
  338. /* parse vendor_id */
  339. runner = *s;
  340. while (runner < *e) {
  341. /* scan for vendor:device delimiter */
  342. if (*runner == ':') {
  343. *vendor_id = simple_strtol((char*) *s, (char**) &p, 16);
  344. runner = p + 1;
  345. break;
  346. }
  347. runner++;
  348. }
  349. if (!isxdigit(*runner)) {
  350. *s = ++runner;
  351. return 0;
  352. }
  353. /* parse device_id */
  354. if (runner < *e) {
  355. *device_id = simple_strtol((char*)runner, (char**)&p, 16);
  356. runner = p;
  357. }
  358. *s = runner;
  359. return 1;
  360. }
  361. static ssize_t edac_pci_list_string_store(void *ptr, const char *buffer,
  362. size_t count)
  363. {
  364. struct list_control *listctl;
  365. struct edac_pci_device_list *list;
  366. unsigned int vendor_id, device_id;
  367. const char *s, *e;
  368. int *index;
  369. s = (char*)buffer;
  370. e = s + count;
  371. listctl = ptr;
  372. list = listctl->list;
  373. index = listctl->count;
  374. *index = 0;
  375. while (*index < MAX_LISTED_PCI_DEVICES) {
  376. if (parse_one_device(&s,&e,&vendor_id,&device_id)) {
  377. list[ *index ].vendor = vendor_id;
  378. list[ *index ].device = device_id;
  379. (*index)++;
  380. }
  381. /* check for all data consume */
  382. if (s >= e)
  383. break;
  384. }
  385. return count;
  386. }
  387. #endif
  388. static ssize_t edac_pci_int_show(void *ptr, char *buffer)
  389. {
  390. int *value = ptr;
  391. return sprintf(buffer,"%d\n",*value);
  392. }
  393. static ssize_t edac_pci_int_store(void *ptr, const char *buffer, size_t count)
  394. {
  395. int *value = ptr;
  396. if (isdigit(*buffer))
  397. *value = simple_strtoul(buffer,NULL,0);
  398. return count;
  399. }
  400. struct edac_pci_dev_attribute {
  401. struct attribute attr;
  402. void *value;
  403. ssize_t (*show)(void *,char *);
  404. ssize_t (*store)(void *, const char *,size_t);
  405. };
  406. /* Set of show/store abstract level functions for PCI Parity object */
  407. static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
  408. char *buffer)
  409. {
  410. struct edac_pci_dev_attribute *edac_pci_dev;
  411. edac_pci_dev= (struct edac_pci_dev_attribute*)attr;
  412. if (edac_pci_dev->show)
  413. return edac_pci_dev->show(edac_pci_dev->value, buffer);
  414. return -EIO;
  415. }
  416. static ssize_t edac_pci_dev_store(struct kobject *kobj,
  417. struct attribute *attr, const char *buffer, size_t count)
  418. {
  419. struct edac_pci_dev_attribute *edac_pci_dev;
  420. edac_pci_dev= (struct edac_pci_dev_attribute*)attr;
  421. if (edac_pci_dev->show)
  422. return edac_pci_dev->store(edac_pci_dev->value, buffer, count);
  423. return -EIO;
  424. }
  425. static struct sysfs_ops edac_pci_sysfs_ops = {
  426. .show = edac_pci_dev_show,
  427. .store = edac_pci_dev_store
  428. };
  429. #define EDAC_PCI_ATTR(_name,_mode,_show,_store) \
  430. struct edac_pci_dev_attribute edac_pci_attr_##_name = { \
  431. .attr = {.name = __stringify(_name), .mode = _mode }, \
  432. .value = &_name, \
  433. .show = _show, \
  434. .store = _store, \
  435. };
  436. #define EDAC_PCI_STRING_ATTR(_name,_data,_mode,_show,_store) \
  437. struct edac_pci_dev_attribute edac_pci_attr_##_name = { \
  438. .attr = {.name = __stringify(_name), .mode = _mode }, \
  439. .value = _data, \
  440. .show = _show, \
  441. .store = _store, \
  442. };
  443. #if 0
  444. static struct list_control pci_whitelist_control = {
  445. .list = pci_whitelist,
  446. .count = &pci_whitelist_count
  447. };
  448. static struct list_control pci_blacklist_control = {
  449. .list = pci_blacklist,
  450. .count = &pci_blacklist_count
  451. };
  452. /* whitelist attribute */
  453. EDAC_PCI_STRING_ATTR(pci_parity_whitelist,
  454. &pci_whitelist_control,
  455. S_IRUGO|S_IWUSR,
  456. edac_pci_list_string_show,
  457. edac_pci_list_string_store);
  458. EDAC_PCI_STRING_ATTR(pci_parity_blacklist,
  459. &pci_blacklist_control,
  460. S_IRUGO|S_IWUSR,
  461. edac_pci_list_string_show,
  462. edac_pci_list_string_store);
  463. #endif
  464. /* PCI Parity control files */
  465. EDAC_PCI_ATTR(check_pci_parity, S_IRUGO|S_IWUSR, edac_pci_int_show,
  466. edac_pci_int_store);
  467. EDAC_PCI_ATTR(panic_on_pci_parity, S_IRUGO|S_IWUSR, edac_pci_int_show,
  468. edac_pci_int_store);
  469. EDAC_PCI_ATTR(pci_parity_count, S_IRUGO, edac_pci_int_show, NULL);
  470. /* Base Attributes of the memory ECC object */
  471. static struct edac_pci_dev_attribute *edac_pci_attr[] = {
  472. &edac_pci_attr_check_pci_parity,
  473. &edac_pci_attr_panic_on_pci_parity,
  474. &edac_pci_attr_pci_parity_count,
  475. NULL,
  476. };
  477. /* No memory to release */
  478. static void edac_pci_release(struct kobject *kobj)
  479. {
  480. debugf1("%s()\n", __func__);
  481. complete(&edac_pci_kobj_complete);
  482. }
  483. static struct kobj_type ktype_edac_pci = {
  484. .release = edac_pci_release,
  485. .sysfs_ops = &edac_pci_sysfs_ops,
  486. .default_attrs = (struct attribute **) edac_pci_attr,
  487. };
  488. #endif /* DISABLE_EDAC_SYSFS */
  489. /**
  490. * edac_sysfs_pci_setup()
  491. *
  492. */
  493. static int edac_sysfs_pci_setup(void)
  494. #ifdef DISABLE_EDAC_SYSFS
  495. {
  496. return 0;
  497. }
  498. #else
  499. {
  500. int err;
  501. debugf1("%s()\n", __func__);
  502. memset(&edac_pci_kobj, 0, sizeof(edac_pci_kobj));
  503. edac_pci_kobj.parent = &edac_class.kset.kobj;
  504. edac_pci_kobj.ktype = &ktype_edac_pci;
  505. err = kobject_set_name(&edac_pci_kobj, "pci");
  506. if (!err) {
  507. /* Instanstiate the csrow object */
  508. /* FIXME: maybe new sysdev_create_subdir() */
  509. err = kobject_register(&edac_pci_kobj);
  510. if (err)
  511. debugf1("Failed to register '.../edac/pci'\n");
  512. else
  513. debugf1("Registered '.../edac/pci' kobject\n");
  514. }
  515. return err;
  516. }
  517. #endif /* DISABLE_EDAC_SYSFS */
  518. static void edac_sysfs_pci_teardown(void)
  519. {
  520. #ifndef DISABLE_EDAC_SYSFS
  521. debugf0("%s()\n", __func__);
  522. init_completion(&edac_pci_kobj_complete);
  523. kobject_unregister(&edac_pci_kobj);
  524. wait_for_completion(&edac_pci_kobj_complete);
  525. #endif
  526. }
  527. static u16 get_pci_parity_status(struct pci_dev *dev, int secondary)
  528. {
  529. int where;
  530. u16 status;
  531. where = secondary ? PCI_SEC_STATUS : PCI_STATUS;
  532. pci_read_config_word(dev, where, &status);
  533. /* If we get back 0xFFFF then we must suspect that the card has been
  534. * pulled but the Linux PCI layer has not yet finished cleaning up.
  535. * We don't want to report on such devices
  536. */
  537. if (status == 0xFFFF) {
  538. u32 sanity;
  539. pci_read_config_dword(dev, 0, &sanity);
  540. if (sanity == 0xFFFFFFFF)
  541. return 0;
  542. }
  543. status &= PCI_STATUS_DETECTED_PARITY | PCI_STATUS_SIG_SYSTEM_ERROR |
  544. PCI_STATUS_PARITY;
  545. if (status)
  546. /* reset only the bits we are interested in */
  547. pci_write_config_word(dev, where, status);
  548. return status;
  549. }
  550. typedef void (*pci_parity_check_fn_t) (struct pci_dev *dev);
  551. /* Clear any PCI parity errors logged by this device. */
  552. static void edac_pci_dev_parity_clear(struct pci_dev *dev)
  553. {
  554. u8 header_type;
  555. get_pci_parity_status(dev, 0);
  556. /* read the device TYPE, looking for bridges */
  557. pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
  558. if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE)
  559. get_pci_parity_status(dev, 1);
  560. }
  561. /*
  562. * PCI Parity polling
  563. *
  564. */
  565. static void edac_pci_dev_parity_test(struct pci_dev *dev)
  566. {
  567. u16 status;
  568. u8 header_type;
  569. /* read the STATUS register on this device
  570. */
  571. status = get_pci_parity_status(dev, 0);
  572. debugf2("PCI STATUS= 0x%04x %s\n", status, dev->dev.bus_id );
  573. /* check the status reg for errors */
  574. if (status) {
  575. if (status & (PCI_STATUS_SIG_SYSTEM_ERROR))
  576. edac_printk(KERN_CRIT, EDAC_PCI,
  577. "Signaled System Error on %s\n",
  578. pci_name(dev));
  579. if (status & (PCI_STATUS_PARITY)) {
  580. edac_printk(KERN_CRIT, EDAC_PCI,
  581. "Master Data Parity Error on %s\n",
  582. pci_name(dev));
  583. atomic_inc(&pci_parity_count);
  584. }
  585. if (status & (PCI_STATUS_DETECTED_PARITY)) {
  586. edac_printk(KERN_CRIT, EDAC_PCI,
  587. "Detected Parity Error on %s\n",
  588. pci_name(dev));
  589. atomic_inc(&pci_parity_count);
  590. }
  591. }
  592. /* read the device TYPE, looking for bridges */
  593. pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
  594. debugf2("PCI HEADER TYPE= 0x%02x %s\n", header_type, dev->dev.bus_id );
  595. if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
  596. /* On bridges, need to examine secondary status register */
  597. status = get_pci_parity_status(dev, 1);
  598. debugf2("PCI SEC_STATUS= 0x%04x %s\n",
  599. status, dev->dev.bus_id );
  600. /* check the secondary status reg for errors */
  601. if (status) {
  602. if (status & (PCI_STATUS_SIG_SYSTEM_ERROR))
  603. edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
  604. "Signaled System Error on %s\n",
  605. pci_name(dev));
  606. if (status & (PCI_STATUS_PARITY)) {
  607. edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
  608. "Master Data Parity Error on "
  609. "%s\n", pci_name(dev));
  610. atomic_inc(&pci_parity_count);
  611. }
  612. if (status & (PCI_STATUS_DETECTED_PARITY)) {
  613. edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
  614. "Detected Parity Error on %s\n",
  615. pci_name(dev));
  616. atomic_inc(&pci_parity_count);
  617. }
  618. }
  619. }
  620. }
  621. /*
  622. * check_dev_on_list: Scan for a PCI device on a white/black list
  623. * @list: an EDAC &edac_pci_device_list white/black list pointer
  624. * @free_index: index of next free entry on the list
  625. * @pci_dev: PCI Device pointer
  626. *
  627. * see if list contains the device.
  628. *
  629. * Returns: 0 not found
  630. * 1 found on list
  631. */
  632. static int check_dev_on_list(struct edac_pci_device_list *list,
  633. int free_index, struct pci_dev *dev)
  634. {
  635. int i;
  636. int rc = 0; /* Assume not found */
  637. unsigned short vendor=dev->vendor;
  638. unsigned short device=dev->device;
  639. /* Scan the list, looking for a vendor/device match */
  640. for (i = 0; i < free_index; i++, list++ ) {
  641. if ((list->vendor == vendor ) && (list->device == device )) {
  642. rc = 1;
  643. break;
  644. }
  645. }
  646. return rc;
  647. }
  648. /*
  649. * pci_dev parity list iterator
  650. * Scan the PCI device list for one iteration, looking for SERRORs
  651. * Master Parity ERRORS or Parity ERRORs on primary or secondary devices
  652. */
  653. static inline void edac_pci_dev_parity_iterator(pci_parity_check_fn_t fn)
  654. {
  655. struct pci_dev *dev = NULL;
  656. /* request for kernel access to the next PCI device, if any,
  657. * and while we are looking at it have its reference count
  658. * bumped until we are done with it
  659. */
  660. while((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
  661. /* if whitelist exists then it has priority, so only scan
  662. * those devices on the whitelist
  663. */
  664. if (pci_whitelist_count > 0 ) {
  665. if (check_dev_on_list(pci_whitelist,
  666. pci_whitelist_count, dev))
  667. fn(dev);
  668. } else {
  669. /*
  670. * if no whitelist, then check if this devices is
  671. * blacklisted
  672. */
  673. if (!check_dev_on_list(pci_blacklist,
  674. pci_blacklist_count, dev))
  675. fn(dev);
  676. }
  677. }
  678. }
  679. static void do_pci_parity_check(void)
  680. {
  681. unsigned long flags;
  682. int before_count;
  683. debugf3("%s()\n", __func__);
  684. if (!check_pci_parity)
  685. return;
  686. before_count = atomic_read(&pci_parity_count);
  687. /* scan all PCI devices looking for a Parity Error on devices and
  688. * bridges
  689. */
  690. local_irq_save(flags);
  691. edac_pci_dev_parity_iterator(edac_pci_dev_parity_test);
  692. local_irq_restore(flags);
  693. /* Only if operator has selected panic on PCI Error */
  694. if (panic_on_pci_parity) {
  695. /* If the count is different 'after' from 'before' */
  696. if (before_count != atomic_read(&pci_parity_count))
  697. panic("EDAC: PCI Parity Error");
  698. }
  699. }
  700. static inline void clear_pci_parity_errors(void)
  701. {
  702. /* Clear any PCI bus parity errors that devices initially have logged
  703. * in their registers.
  704. */
  705. edac_pci_dev_parity_iterator(edac_pci_dev_parity_clear);
  706. }
  707. #else /* CONFIG_PCI */
  708. static inline void do_pci_parity_check(void)
  709. {
  710. /* no-op */
  711. }
  712. static inline void clear_pci_parity_errors(void)
  713. {
  714. /* no-op */
  715. }
  716. static void edac_sysfs_pci_teardown(void)
  717. {
  718. }
  719. static int edac_sysfs_pci_setup(void)
  720. {
  721. return 0;
  722. }
  723. #endif /* CONFIG_PCI */
  724. #ifndef DISABLE_EDAC_SYSFS
  725. /* EDAC sysfs CSROW data structures and methods */
  726. /* Set of more detailed csrow<id> attribute show/store functions */
  727. static ssize_t csrow_ch0_dimm_label_show(struct csrow_info *csrow, char *data)
  728. {
  729. ssize_t size = 0;
  730. if (csrow->nr_channels > 0) {
  731. size = snprintf(data, EDAC_MC_LABEL_LEN,"%s\n",
  732. csrow->channels[0].label);
  733. }
  734. return size;
  735. }
  736. static ssize_t csrow_ch1_dimm_label_show(struct csrow_info *csrow, char *data)
  737. {
  738. ssize_t size = 0;
  739. if (csrow->nr_channels > 0) {
  740. size = snprintf(data, EDAC_MC_LABEL_LEN, "%s\n",
  741. csrow->channels[1].label);
  742. }
  743. return size;
  744. }
  745. static ssize_t csrow_ch0_dimm_label_store(struct csrow_info *csrow,
  746. const char *data, size_t size)
  747. {
  748. ssize_t max_size = 0;
  749. if (csrow->nr_channels > 0) {
  750. max_size = min((ssize_t)size,(ssize_t)EDAC_MC_LABEL_LEN-1);
  751. strncpy(csrow->channels[0].label, data, max_size);
  752. csrow->channels[0].label[max_size] = '\0';
  753. }
  754. return size;
  755. }
  756. static ssize_t csrow_ch1_dimm_label_store(struct csrow_info *csrow,
  757. const char *data, size_t size)
  758. {
  759. ssize_t max_size = 0;
  760. if (csrow->nr_channels > 1) {
  761. max_size = min((ssize_t)size,(ssize_t)EDAC_MC_LABEL_LEN-1);
  762. strncpy(csrow->channels[1].label, data, max_size);
  763. csrow->channels[1].label[max_size] = '\0';
  764. }
  765. return max_size;
  766. }
  767. static ssize_t csrow_ue_count_show(struct csrow_info *csrow, char *data)
  768. {
  769. return sprintf(data,"%u\n", csrow->ue_count);
  770. }
  771. static ssize_t csrow_ce_count_show(struct csrow_info *csrow, char *data)
  772. {
  773. return sprintf(data,"%u\n", csrow->ce_count);
  774. }
  775. static ssize_t csrow_ch0_ce_count_show(struct csrow_info *csrow, char *data)
  776. {
  777. ssize_t size = 0;
  778. if (csrow->nr_channels > 0) {
  779. size = sprintf(data,"%u\n", csrow->channels[0].ce_count);
  780. }
  781. return size;
  782. }
  783. static ssize_t csrow_ch1_ce_count_show(struct csrow_info *csrow, char *data)
  784. {
  785. ssize_t size = 0;
  786. if (csrow->nr_channels > 1) {
  787. size = sprintf(data,"%u\n", csrow->channels[1].ce_count);
  788. }
  789. return size;
  790. }
  791. static ssize_t csrow_size_show(struct csrow_info *csrow, char *data)
  792. {
  793. return sprintf(data,"%u\n", PAGES_TO_MiB(csrow->nr_pages));
  794. }
  795. static ssize_t csrow_mem_type_show(struct csrow_info *csrow, char *data)
  796. {
  797. return sprintf(data,"%s\n", mem_types[csrow->mtype]);
  798. }
  799. static ssize_t csrow_dev_type_show(struct csrow_info *csrow, char *data)
  800. {
  801. return sprintf(data,"%s\n", dev_types[csrow->dtype]);
  802. }
  803. static ssize_t csrow_edac_mode_show(struct csrow_info *csrow, char *data)
  804. {
  805. return sprintf(data,"%s\n", edac_caps[csrow->edac_mode]);
  806. }
  807. struct csrowdev_attribute {
  808. struct attribute attr;
  809. ssize_t (*show)(struct csrow_info *,char *);
  810. ssize_t (*store)(struct csrow_info *, const char *,size_t);
  811. };
  812. #define to_csrow(k) container_of(k, struct csrow_info, kobj)
  813. #define to_csrowdev_attr(a) container_of(a, struct csrowdev_attribute, attr)
  814. /* Set of show/store higher level functions for csrow objects */
  815. static ssize_t csrowdev_show(struct kobject *kobj, struct attribute *attr,
  816. char *buffer)
  817. {
  818. struct csrow_info *csrow = to_csrow(kobj);
  819. struct csrowdev_attribute *csrowdev_attr = to_csrowdev_attr(attr);
  820. if (csrowdev_attr->show)
  821. return csrowdev_attr->show(csrow, buffer);
  822. return -EIO;
  823. }
  824. static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr,
  825. const char *buffer, size_t count)
  826. {
  827. struct csrow_info *csrow = to_csrow(kobj);
  828. struct csrowdev_attribute * csrowdev_attr = to_csrowdev_attr(attr);
  829. if (csrowdev_attr->store)
  830. return csrowdev_attr->store(csrow, buffer, count);
  831. return -EIO;
  832. }
  833. static struct sysfs_ops csrowfs_ops = {
  834. .show = csrowdev_show,
  835. .store = csrowdev_store
  836. };
  837. #define CSROWDEV_ATTR(_name,_mode,_show,_store) \
  838. struct csrowdev_attribute attr_##_name = { \
  839. .attr = {.name = __stringify(_name), .mode = _mode }, \
  840. .show = _show, \
  841. .store = _store, \
  842. };
  843. /* cwrow<id>/attribute files */
  844. CSROWDEV_ATTR(size_mb,S_IRUGO,csrow_size_show,NULL);
  845. CSROWDEV_ATTR(dev_type,S_IRUGO,csrow_dev_type_show,NULL);
  846. CSROWDEV_ATTR(mem_type,S_IRUGO,csrow_mem_type_show,NULL);
  847. CSROWDEV_ATTR(edac_mode,S_IRUGO,csrow_edac_mode_show,NULL);
  848. CSROWDEV_ATTR(ue_count,S_IRUGO,csrow_ue_count_show,NULL);
  849. CSROWDEV_ATTR(ce_count,S_IRUGO,csrow_ce_count_show,NULL);
  850. CSROWDEV_ATTR(ch0_ce_count,S_IRUGO,csrow_ch0_ce_count_show,NULL);
  851. CSROWDEV_ATTR(ch1_ce_count,S_IRUGO,csrow_ch1_ce_count_show,NULL);
  852. /* control/attribute files */
  853. CSROWDEV_ATTR(ch0_dimm_label,S_IRUGO|S_IWUSR,
  854. csrow_ch0_dimm_label_show,
  855. csrow_ch0_dimm_label_store);
  856. CSROWDEV_ATTR(ch1_dimm_label,S_IRUGO|S_IWUSR,
  857. csrow_ch1_dimm_label_show,
  858. csrow_ch1_dimm_label_store);
  859. /* Attributes of the CSROW<id> object */
  860. static struct csrowdev_attribute *csrow_attr[] = {
  861. &attr_dev_type,
  862. &attr_mem_type,
  863. &attr_edac_mode,
  864. &attr_size_mb,
  865. &attr_ue_count,
  866. &attr_ce_count,
  867. &attr_ch0_ce_count,
  868. &attr_ch1_ce_count,
  869. &attr_ch0_dimm_label,
  870. &attr_ch1_dimm_label,
  871. NULL,
  872. };
  873. /* No memory to release */
  874. static void edac_csrow_instance_release(struct kobject *kobj)
  875. {
  876. struct csrow_info *cs;
  877. debugf1("%s()\n", __func__);
  878. cs = container_of(kobj, struct csrow_info, kobj);
  879. complete(&cs->kobj_complete);
  880. }
  881. static struct kobj_type ktype_csrow = {
  882. .release = edac_csrow_instance_release,
  883. .sysfs_ops = &csrowfs_ops,
  884. .default_attrs = (struct attribute **) csrow_attr,
  885. };
  886. /* Create a CSROW object under specifed edac_mc_device */
  887. static int edac_create_csrow_object(struct kobject *edac_mci_kobj,
  888. struct csrow_info *csrow, int index)
  889. {
  890. int err = 0;
  891. debugf0("%s()\n", __func__);
  892. memset(&csrow->kobj, 0, sizeof(csrow->kobj));
  893. /* generate ..../edac/mc/mc<id>/csrow<index> */
  894. csrow->kobj.parent = edac_mci_kobj;
  895. csrow->kobj.ktype = &ktype_csrow;
  896. /* name this instance of csrow<id> */
  897. err = kobject_set_name(&csrow->kobj,"csrow%d",index);
  898. if (!err) {
  899. /* Instanstiate the csrow object */
  900. err = kobject_register(&csrow->kobj);
  901. if (err)
  902. debugf0("Failed to register CSROW%d\n",index);
  903. else
  904. debugf0("Registered CSROW%d\n",index);
  905. }
  906. return err;
  907. }
  908. /* sysfs data structures and methods for the MCI kobjects */
  909. static ssize_t mci_reset_counters_store(struct mem_ctl_info *mci,
  910. const char *data, size_t count)
  911. {
  912. int row, chan;
  913. mci->ue_noinfo_count = 0;
  914. mci->ce_noinfo_count = 0;
  915. mci->ue_count = 0;
  916. mci->ce_count = 0;
  917. for (row = 0; row < mci->nr_csrows; row++) {
  918. struct csrow_info *ri = &mci->csrows[row];
  919. ri->ue_count = 0;
  920. ri->ce_count = 0;
  921. for (chan = 0; chan < ri->nr_channels; chan++)
  922. ri->channels[chan].ce_count = 0;
  923. }
  924. mci->start_time = jiffies;
  925. return count;
  926. }
  927. static ssize_t mci_ue_count_show(struct mem_ctl_info *mci, char *data)
  928. {
  929. return sprintf(data,"%d\n", mci->ue_count);
  930. }
  931. static ssize_t mci_ce_count_show(struct mem_ctl_info *mci, char *data)
  932. {
  933. return sprintf(data,"%d\n", mci->ce_count);
  934. }
  935. static ssize_t mci_ce_noinfo_show(struct mem_ctl_info *mci, char *data)
  936. {
  937. return sprintf(data,"%d\n", mci->ce_noinfo_count);
  938. }
  939. static ssize_t mci_ue_noinfo_show(struct mem_ctl_info *mci, char *data)
  940. {
  941. return sprintf(data,"%d\n", mci->ue_noinfo_count);
  942. }
  943. static ssize_t mci_seconds_show(struct mem_ctl_info *mci, char *data)
  944. {
  945. return sprintf(data,"%ld\n", (jiffies - mci->start_time) / HZ);
  946. }
  947. static ssize_t mci_mod_name_show(struct mem_ctl_info *mci, char *data)
  948. {
  949. return sprintf(data,"%s %s\n", mci->mod_name, mci->mod_ver);
  950. }
  951. static ssize_t mci_ctl_name_show(struct mem_ctl_info *mci, char *data)
  952. {
  953. return sprintf(data,"%s\n", mci->ctl_name);
  954. }
  955. static int mci_output_edac_cap(char *buf, unsigned long edac_cap)
  956. {
  957. char *p = buf;
  958. int bit_idx;
  959. for (bit_idx = 0; bit_idx < 8 * sizeof(edac_cap); bit_idx++) {
  960. if ((edac_cap >> bit_idx) & 0x1)
  961. p += sprintf(p, "%s ", edac_caps[bit_idx]);
  962. }
  963. return p - buf;
  964. }
  965. static ssize_t mci_edac_capability_show(struct mem_ctl_info *mci, char *data)
  966. {
  967. char *p = data;
  968. p += mci_output_edac_cap(p,mci->edac_ctl_cap);
  969. p += sprintf(p, "\n");
  970. return p - data;
  971. }
  972. static ssize_t mci_edac_current_capability_show(struct mem_ctl_info *mci,
  973. char *data)
  974. {
  975. char *p = data;
  976. p += mci_output_edac_cap(p,mci->edac_cap);
  977. p += sprintf(p, "\n");
  978. return p - data;
  979. }
  980. static int mci_output_mtype_cap(char *buf, unsigned long mtype_cap)
  981. {
  982. char *p = buf;
  983. int bit_idx;
  984. for (bit_idx = 0; bit_idx < 8 * sizeof(mtype_cap); bit_idx++) {
  985. if ((mtype_cap >> bit_idx) & 0x1)
  986. p += sprintf(p, "%s ", mem_types[bit_idx]);
  987. }
  988. return p - buf;
  989. }
  990. static ssize_t mci_supported_mem_type_show(struct mem_ctl_info *mci,
  991. char *data)
  992. {
  993. char *p = data;
  994. p += mci_output_mtype_cap(p,mci->mtype_cap);
  995. p += sprintf(p, "\n");
  996. return p - data;
  997. }
  998. static ssize_t mci_size_mb_show(struct mem_ctl_info *mci, char *data)
  999. {
  1000. int total_pages, csrow_idx;
  1001. for (total_pages = csrow_idx = 0; csrow_idx < mci->nr_csrows;
  1002. csrow_idx++) {
  1003. struct csrow_info *csrow = &mci->csrows[csrow_idx];
  1004. if (!csrow->nr_pages)
  1005. continue;
  1006. total_pages += csrow->nr_pages;
  1007. }
  1008. return sprintf(data,"%u\n", PAGES_TO_MiB(total_pages));
  1009. }
  1010. struct mcidev_attribute {
  1011. struct attribute attr;
  1012. ssize_t (*show)(struct mem_ctl_info *,char *);
  1013. ssize_t (*store)(struct mem_ctl_info *, const char *,size_t);
  1014. };
  1015. #define to_mci(k) container_of(k, struct mem_ctl_info, edac_mci_kobj)
  1016. #define to_mcidev_attr(a) container_of(a, struct mcidev_attribute, attr)
  1017. static ssize_t mcidev_show(struct kobject *kobj, struct attribute *attr,
  1018. char *buffer)
  1019. {
  1020. struct mem_ctl_info *mem_ctl_info = to_mci(kobj);
  1021. struct mcidev_attribute * mcidev_attr = to_mcidev_attr(attr);
  1022. if (mcidev_attr->show)
  1023. return mcidev_attr->show(mem_ctl_info, buffer);
  1024. return -EIO;
  1025. }
  1026. static ssize_t mcidev_store(struct kobject *kobj, struct attribute *attr,
  1027. const char *buffer, size_t count)
  1028. {
  1029. struct mem_ctl_info *mem_ctl_info = to_mci(kobj);
  1030. struct mcidev_attribute * mcidev_attr = to_mcidev_attr(attr);
  1031. if (mcidev_attr->store)
  1032. return mcidev_attr->store(mem_ctl_info, buffer, count);
  1033. return -EIO;
  1034. }
  1035. static struct sysfs_ops mci_ops = {
  1036. .show = mcidev_show,
  1037. .store = mcidev_store
  1038. };
  1039. #define MCIDEV_ATTR(_name,_mode,_show,_store) \
  1040. struct mcidev_attribute mci_attr_##_name = { \
  1041. .attr = {.name = __stringify(_name), .mode = _mode }, \
  1042. .show = _show, \
  1043. .store = _store, \
  1044. };
  1045. /* Control file */
  1046. MCIDEV_ATTR(reset_counters,S_IWUSR,NULL,mci_reset_counters_store);
  1047. /* Attribute files */
  1048. MCIDEV_ATTR(mc_name,S_IRUGO,mci_ctl_name_show,NULL);
  1049. MCIDEV_ATTR(module_name,S_IRUGO,mci_mod_name_show,NULL);
  1050. MCIDEV_ATTR(edac_capability,S_IRUGO,mci_edac_capability_show,NULL);
  1051. MCIDEV_ATTR(size_mb,S_IRUGO,mci_size_mb_show,NULL);
  1052. MCIDEV_ATTR(seconds_since_reset,S_IRUGO,mci_seconds_show,NULL);
  1053. MCIDEV_ATTR(ue_noinfo_count,S_IRUGO,mci_ue_noinfo_show,NULL);
  1054. MCIDEV_ATTR(ce_noinfo_count,S_IRUGO,mci_ce_noinfo_show,NULL);
  1055. MCIDEV_ATTR(ue_count,S_IRUGO,mci_ue_count_show,NULL);
  1056. MCIDEV_ATTR(ce_count,S_IRUGO,mci_ce_count_show,NULL);
  1057. MCIDEV_ATTR(edac_current_capability,S_IRUGO,
  1058. mci_edac_current_capability_show,NULL);
  1059. MCIDEV_ATTR(supported_mem_type,S_IRUGO,
  1060. mci_supported_mem_type_show,NULL);
  1061. static struct mcidev_attribute *mci_attr[] = {
  1062. &mci_attr_reset_counters,
  1063. &mci_attr_module_name,
  1064. &mci_attr_mc_name,
  1065. &mci_attr_edac_capability,
  1066. &mci_attr_edac_current_capability,
  1067. &mci_attr_supported_mem_type,
  1068. &mci_attr_size_mb,
  1069. &mci_attr_seconds_since_reset,
  1070. &mci_attr_ue_noinfo_count,
  1071. &mci_attr_ce_noinfo_count,
  1072. &mci_attr_ue_count,
  1073. &mci_attr_ce_count,
  1074. NULL
  1075. };
  1076. /*
  1077. * Release of a MC controlling instance
  1078. */
  1079. static void edac_mci_instance_release(struct kobject *kobj)
  1080. {
  1081. struct mem_ctl_info *mci;
  1082. mci = to_mci(kobj);
  1083. debugf0("%s() idx=%d\n", __func__, mci->mc_idx);
  1084. complete(&mci->kobj_complete);
  1085. }
  1086. static struct kobj_type ktype_mci = {
  1087. .release = edac_mci_instance_release,
  1088. .sysfs_ops = &mci_ops,
  1089. .default_attrs = (struct attribute **) mci_attr,
  1090. };
  1091. #endif /* DISABLE_EDAC_SYSFS */
  1092. #define EDAC_DEVICE_SYMLINK "device"
  1093. /*
  1094. * Create a new Memory Controller kobject instance,
  1095. * mc<id> under the 'mc' directory
  1096. *
  1097. * Return:
  1098. * 0 Success
  1099. * !0 Failure
  1100. */
  1101. static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
  1102. #ifdef DISABLE_EDAC_SYSFS
  1103. {
  1104. return 0;
  1105. }
  1106. #else
  1107. {
  1108. int i;
  1109. int err;
  1110. struct csrow_info *csrow;
  1111. struct kobject *edac_mci_kobj=&mci->edac_mci_kobj;
  1112. debugf0("%s() idx=%d\n", __func__, mci->mc_idx);
  1113. memset(edac_mci_kobj, 0, sizeof(*edac_mci_kobj));
  1114. /* set the name of the mc<id> object */
  1115. err = kobject_set_name(edac_mci_kobj,"mc%d",mci->mc_idx);
  1116. if (err)
  1117. return err;
  1118. /* link to our parent the '..../edac/mc' object */
  1119. edac_mci_kobj->parent = &edac_memctrl_kobj;
  1120. edac_mci_kobj->ktype = &ktype_mci;
  1121. /* register the mc<id> kobject */
  1122. err = kobject_register(edac_mci_kobj);
  1123. if (err)
  1124. return err;
  1125. /* create a symlink for the device */
  1126. err = sysfs_create_link(edac_mci_kobj, &mci->dev->kobj,
  1127. EDAC_DEVICE_SYMLINK);
  1128. if (err)
  1129. goto fail0;
  1130. /* Make directories for each CSROW object
  1131. * under the mc<id> kobject
  1132. */
  1133. for (i = 0; i < mci->nr_csrows; i++) {
  1134. csrow = &mci->csrows[i];
  1135. /* Only expose populated CSROWs */
  1136. if (csrow->nr_pages > 0) {
  1137. err = edac_create_csrow_object(edac_mci_kobj,csrow,i);
  1138. if (err)
  1139. goto fail1;
  1140. }
  1141. }
  1142. return 0;
  1143. /* CSROW error: backout what has already been registered, */
  1144. fail1:
  1145. for ( i--; i >= 0; i--) {
  1146. if (csrow->nr_pages > 0) {
  1147. init_completion(&csrow->kobj_complete);
  1148. kobject_unregister(&mci->csrows[i].kobj);
  1149. wait_for_completion(&csrow->kobj_complete);
  1150. }
  1151. }
  1152. fail0:
  1153. init_completion(&mci->kobj_complete);
  1154. kobject_unregister(edac_mci_kobj);
  1155. wait_for_completion(&mci->kobj_complete);
  1156. return err;
  1157. }
  1158. #endif /* DISABLE_EDAC_SYSFS */
  1159. /*
  1160. * remove a Memory Controller instance
  1161. */
  1162. static void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
  1163. {
  1164. #ifndef DISABLE_EDAC_SYSFS
  1165. int i;
  1166. debugf0("%s()\n", __func__);
  1167. /* remove all csrow kobjects */
  1168. for (i = 0; i < mci->nr_csrows; i++) {
  1169. if (mci->csrows[i].nr_pages > 0) {
  1170. init_completion(&mci->csrows[i].kobj_complete);
  1171. kobject_unregister(&mci->csrows[i].kobj);
  1172. wait_for_completion(&mci->csrows[i].kobj_complete);
  1173. }
  1174. }
  1175. sysfs_remove_link(&mci->edac_mci_kobj, EDAC_DEVICE_SYMLINK);
  1176. init_completion(&mci->kobj_complete);
  1177. kobject_unregister(&mci->edac_mci_kobj);
  1178. wait_for_completion(&mci->kobj_complete);
  1179. #endif /* DISABLE_EDAC_SYSFS */
  1180. }
  1181. /* END OF sysfs data and methods */
  1182. #ifdef CONFIG_EDAC_DEBUG
  1183. void edac_mc_dump_channel(struct channel_info *chan)
  1184. {
  1185. debugf4("\tchannel = %p\n", chan);
  1186. debugf4("\tchannel->chan_idx = %d\n", chan->chan_idx);
  1187. debugf4("\tchannel->ce_count = %d\n", chan->ce_count);
  1188. debugf4("\tchannel->label = '%s'\n", chan->label);
  1189. debugf4("\tchannel->csrow = %p\n\n", chan->csrow);
  1190. }
  1191. EXPORT_SYMBOL_GPL(edac_mc_dump_channel);
  1192. void edac_mc_dump_csrow(struct csrow_info *csrow)
  1193. {
  1194. debugf4("\tcsrow = %p\n", csrow);
  1195. debugf4("\tcsrow->csrow_idx = %d\n", csrow->csrow_idx);
  1196. debugf4("\tcsrow->first_page = 0x%lx\n",
  1197. csrow->first_page);
  1198. debugf4("\tcsrow->last_page = 0x%lx\n", csrow->last_page);
  1199. debugf4("\tcsrow->page_mask = 0x%lx\n", csrow->page_mask);
  1200. debugf4("\tcsrow->nr_pages = 0x%x\n", csrow->nr_pages);
  1201. debugf4("\tcsrow->nr_channels = %d\n",
  1202. csrow->nr_channels);
  1203. debugf4("\tcsrow->channels = %p\n", csrow->channels);
  1204. debugf4("\tcsrow->mci = %p\n\n", csrow->mci);
  1205. }
  1206. EXPORT_SYMBOL_GPL(edac_mc_dump_csrow);
  1207. void edac_mc_dump_mci(struct mem_ctl_info *mci)
  1208. {
  1209. debugf3("\tmci = %p\n", mci);
  1210. debugf3("\tmci->mtype_cap = %lx\n", mci->mtype_cap);
  1211. debugf3("\tmci->edac_ctl_cap = %lx\n", mci->edac_ctl_cap);
  1212. debugf3("\tmci->edac_cap = %lx\n", mci->edac_cap);
  1213. debugf4("\tmci->edac_check = %p\n", mci->edac_check);
  1214. debugf3("\tmci->nr_csrows = %d, csrows = %p\n",
  1215. mci->nr_csrows, mci->csrows);
  1216. debugf3("\tdev = %p\n", mci->dev);
  1217. debugf3("\tmod_name:ctl_name = %s:%s\n",
  1218. mci->mod_name, mci->ctl_name);
  1219. debugf3("\tpvt_info = %p\n\n", mci->pvt_info);
  1220. }
  1221. EXPORT_SYMBOL_GPL(edac_mc_dump_mci);
  1222. #endif /* CONFIG_EDAC_DEBUG */
  1223. /* 'ptr' points to a possibly unaligned item X such that sizeof(X) is 'size'.
  1224. * Adjust 'ptr' so that its alignment is at least as stringent as what the
  1225. * compiler would provide for X and return the aligned result.
  1226. *
  1227. * If 'size' is a constant, the compiler will optimize this whole function
  1228. * down to either a no-op or the addition of a constant to the value of 'ptr'.
  1229. */
  1230. static inline char * align_ptr(void *ptr, unsigned size)
  1231. {
  1232. unsigned align, r;
  1233. /* Here we assume that the alignment of a "long long" is the most
  1234. * stringent alignment that the compiler will ever provide by default.
  1235. * As far as I know, this is a reasonable assumption.
  1236. */
  1237. if (size > sizeof(long))
  1238. align = sizeof(long long);
  1239. else if (size > sizeof(int))
  1240. align = sizeof(long);
  1241. else if (size > sizeof(short))
  1242. align = sizeof(int);
  1243. else if (size > sizeof(char))
  1244. align = sizeof(short);
  1245. else
  1246. return (char *) ptr;
  1247. r = size % align;
  1248. if (r == 0)
  1249. return (char *) ptr;
  1250. return (char *) (((unsigned long) ptr) + align - r);
  1251. }
  1252. /**
  1253. * edac_mc_alloc: Allocate a struct mem_ctl_info structure
  1254. * @size_pvt: size of private storage needed
  1255. * @nr_csrows: Number of CWROWS needed for this MC
  1256. * @nr_chans: Number of channels for the MC
  1257. *
  1258. * Everything is kmalloc'ed as one big chunk - more efficient.
  1259. * Only can be used if all structures have the same lifetime - otherwise
  1260. * you have to allocate and initialize your own structures.
  1261. *
  1262. * Use edac_mc_free() to free mc structures allocated by this function.
  1263. *
  1264. * Returns:
  1265. * NULL allocation failed
  1266. * struct mem_ctl_info pointer
  1267. */
  1268. struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
  1269. unsigned nr_chans)
  1270. {
  1271. struct mem_ctl_info *mci;
  1272. struct csrow_info *csi, *csrow;
  1273. struct channel_info *chi, *chp, *chan;
  1274. void *pvt;
  1275. unsigned size;
  1276. int row, chn;
  1277. /* Figure out the offsets of the various items from the start of an mc
  1278. * structure. We want the alignment of each item to be at least as
  1279. * stringent as what the compiler would provide if we could simply
  1280. * hardcode everything into a single struct.
  1281. */
  1282. mci = (struct mem_ctl_info *) 0;
  1283. csi = (struct csrow_info *)align_ptr(&mci[1], sizeof(*csi));
  1284. chi = (struct channel_info *)
  1285. align_ptr(&csi[nr_csrows], sizeof(*chi));
  1286. pvt = align_ptr(&chi[nr_chans * nr_csrows], sz_pvt);
  1287. size = ((unsigned long) pvt) + sz_pvt;
  1288. if ((mci = kmalloc(size, GFP_KERNEL)) == NULL)
  1289. return NULL;
  1290. /* Adjust pointers so they point within the memory we just allocated
  1291. * rather than an imaginary chunk of memory located at address 0.
  1292. */
  1293. csi = (struct csrow_info *) (((char *) mci) + ((unsigned long) csi));
  1294. chi = (struct channel_info *) (((char *) mci) + ((unsigned long) chi));
  1295. pvt = sz_pvt ? (((char *) mci) + ((unsigned long) pvt)) : NULL;
  1296. memset(mci, 0, size); /* clear all fields */
  1297. mci->csrows = csi;
  1298. mci->pvt_info = pvt;
  1299. mci->nr_csrows = nr_csrows;
  1300. for (row = 0; row < nr_csrows; row++) {
  1301. csrow = &csi[row];
  1302. csrow->csrow_idx = row;
  1303. csrow->mci = mci;
  1304. csrow->nr_channels = nr_chans;
  1305. chp = &chi[row * nr_chans];
  1306. csrow->channels = chp;
  1307. for (chn = 0; chn < nr_chans; chn++) {
  1308. chan = &chp[chn];
  1309. chan->chan_idx = chn;
  1310. chan->csrow = csrow;
  1311. }
  1312. }
  1313. return mci;
  1314. }
  1315. EXPORT_SYMBOL_GPL(edac_mc_alloc);
  1316. /**
  1317. * edac_mc_free: Free a previously allocated 'mci' structure
  1318. * @mci: pointer to a struct mem_ctl_info structure
  1319. */
  1320. void edac_mc_free(struct mem_ctl_info *mci)
  1321. {
  1322. kfree(mci);
  1323. }
  1324. EXPORT_SYMBOL_GPL(edac_mc_free);
  1325. static struct mem_ctl_info *find_mci_by_dev(struct device *dev)
  1326. {
  1327. struct mem_ctl_info *mci;
  1328. struct list_head *item;
  1329. debugf3("%s()\n", __func__);
  1330. list_for_each(item, &mc_devices) {
  1331. mci = list_entry(item, struct mem_ctl_info, link);
  1332. if (mci->dev == dev)
  1333. return mci;
  1334. }
  1335. return NULL;
  1336. }
  1337. /* Return 0 on success, 1 on failure.
  1338. * Before calling this function, caller must
  1339. * assign a unique value to mci->mc_idx.
  1340. */
  1341. static int add_mc_to_global_list (struct mem_ctl_info *mci)
  1342. {
  1343. struct list_head *item, *insert_before;
  1344. struct mem_ctl_info *p;
  1345. insert_before = &mc_devices;
  1346. if (unlikely((p = find_mci_by_dev(mci->dev)) != NULL))
  1347. goto fail0;
  1348. list_for_each(item, &mc_devices) {
  1349. p = list_entry(item, struct mem_ctl_info, link);
  1350. if (p->mc_idx >= mci->mc_idx) {
  1351. if (unlikely(p->mc_idx == mci->mc_idx))
  1352. goto fail1;
  1353. insert_before = item;
  1354. break;
  1355. }
  1356. }
  1357. list_add_tail_rcu(&mci->link, insert_before);
  1358. return 0;
  1359. fail0:
  1360. edac_printk(KERN_WARNING, EDAC_MC,
  1361. "%s (%s) %s %s already assigned %d\n", p->dev->bus_id,
  1362. dev_name(p->dev), p->mod_name, p->ctl_name, p->mc_idx);
  1363. return 1;
  1364. fail1:
  1365. edac_printk(KERN_WARNING, EDAC_MC,
  1366. "bug in low-level driver: attempt to assign\n"
  1367. " duplicate mc_idx %d in %s()\n", p->mc_idx, __func__);
  1368. return 1;
  1369. }
  1370. static void complete_mc_list_del(struct rcu_head *head)
  1371. {
  1372. struct mem_ctl_info *mci;
  1373. mci = container_of(head, struct mem_ctl_info, rcu);
  1374. INIT_LIST_HEAD(&mci->link);
  1375. complete(&mci->complete);
  1376. }
  1377. static void del_mc_from_global_list(struct mem_ctl_info *mci)
  1378. {
  1379. list_del_rcu(&mci->link);
  1380. init_completion(&mci->complete);
  1381. call_rcu(&mci->rcu, complete_mc_list_del);
  1382. wait_for_completion(&mci->complete);
  1383. }
  1384. /**
  1385. * edac_mc_add_mc: Insert the 'mci' structure into the mci global list and
  1386. * create sysfs entries associated with mci structure
  1387. * @mci: pointer to the mci structure to be added to the list
  1388. * @mc_idx: A unique numeric identifier to be assigned to the 'mci' structure.
  1389. *
  1390. * Return:
  1391. * 0 Success
  1392. * !0 Failure
  1393. */
  1394. /* FIXME - should a warning be printed if no error detection? correction? */
  1395. int edac_mc_add_mc(struct mem_ctl_info *mci, int mc_idx)
  1396. {
  1397. debugf0("%s()\n", __func__);
  1398. mci->mc_idx = mc_idx;
  1399. #ifdef CONFIG_EDAC_DEBUG
  1400. if (edac_debug_level >= 3)
  1401. edac_mc_dump_mci(mci);
  1402. if (edac_debug_level >= 4) {
  1403. int i;
  1404. for (i = 0; i < mci->nr_csrows; i++) {
  1405. int j;
  1406. edac_mc_dump_csrow(&mci->csrows[i]);
  1407. for (j = 0; j < mci->csrows[i].nr_channels; j++)
  1408. edac_mc_dump_channel(
  1409. &mci->csrows[i].channels[j]);
  1410. }
  1411. }
  1412. #endif
  1413. down(&mem_ctls_mutex);
  1414. if (add_mc_to_global_list(mci))
  1415. goto fail0;
  1416. /* set load time so that error rate can be tracked */
  1417. mci->start_time = jiffies;
  1418. if (edac_create_sysfs_mci_device(mci)) {
  1419. edac_mc_printk(mci, KERN_WARNING,
  1420. "failed to create sysfs device\n");
  1421. goto fail1;
  1422. }
  1423. /* Report action taken */
  1424. edac_mc_printk(mci, KERN_INFO, "Giving out device to %s %s: DEV %s\n",
  1425. mci->mod_name, mci->ctl_name, dev_name(mci->dev));
  1426. up(&mem_ctls_mutex);
  1427. return 0;
  1428. fail1:
  1429. del_mc_from_global_list(mci);
  1430. fail0:
  1431. up(&mem_ctls_mutex);
  1432. return 1;
  1433. }
  1434. EXPORT_SYMBOL_GPL(edac_mc_add_mc);
  1435. /**
  1436. * edac_mc_del_mc: Remove sysfs entries for specified mci structure and
  1437. * remove mci structure from global list
  1438. * @pdev: Pointer to 'struct device' representing mci structure to remove.
  1439. *
  1440. * Return pointer to removed mci structure, or NULL if device not found.
  1441. */
  1442. struct mem_ctl_info * edac_mc_del_mc(struct device *dev)
  1443. {
  1444. struct mem_ctl_info *mci;
  1445. debugf0("MC: %s()\n", __func__);
  1446. down(&mem_ctls_mutex);
  1447. if ((mci = find_mci_by_dev(dev)) == NULL) {
  1448. up(&mem_ctls_mutex);
  1449. return NULL;
  1450. }
  1451. edac_remove_sysfs_mci_device(mci);
  1452. del_mc_from_global_list(mci);
  1453. up(&mem_ctls_mutex);
  1454. edac_printk(KERN_INFO, EDAC_MC,
  1455. "Removed device %d for %s %s: DEV %s\n", mci->mc_idx,
  1456. mci->mod_name, mci->ctl_name, dev_name(mci->dev));
  1457. return mci;
  1458. }
  1459. EXPORT_SYMBOL_GPL(edac_mc_del_mc);
  1460. void edac_mc_scrub_block(unsigned long page, unsigned long offset, u32 size)
  1461. {
  1462. struct page *pg;
  1463. void *virt_addr;
  1464. unsigned long flags = 0;
  1465. debugf3("%s()\n", __func__);
  1466. /* ECC error page was not in our memory. Ignore it. */
  1467. if(!pfn_valid(page))
  1468. return;
  1469. /* Find the actual page structure then map it and fix */
  1470. pg = pfn_to_page(page);
  1471. if (PageHighMem(pg))
  1472. local_irq_save(flags);
  1473. virt_addr = kmap_atomic(pg, KM_BOUNCE_READ);
  1474. /* Perform architecture specific atomic scrub operation */
  1475. atomic_scrub(virt_addr + offset, size);
  1476. /* Unmap and complete */
  1477. kunmap_atomic(virt_addr, KM_BOUNCE_READ);
  1478. if (PageHighMem(pg))
  1479. local_irq_restore(flags);
  1480. }
  1481. EXPORT_SYMBOL_GPL(edac_mc_scrub_block);
  1482. /* FIXME - should return -1 */
  1483. int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, unsigned long page)
  1484. {
  1485. struct csrow_info *csrows = mci->csrows;
  1486. int row, i;
  1487. debugf1("MC%d: %s(): 0x%lx\n", mci->mc_idx, __func__, page);
  1488. row = -1;
  1489. for (i = 0; i < mci->nr_csrows; i++) {
  1490. struct csrow_info *csrow = &csrows[i];
  1491. if (csrow->nr_pages == 0)
  1492. continue;
  1493. debugf3("MC%d: %s(): first(0x%lx) page(0x%lx) last(0x%lx) "
  1494. "mask(0x%lx)\n", mci->mc_idx, __func__,
  1495. csrow->first_page, page, csrow->last_page,
  1496. csrow->page_mask);
  1497. if ((page >= csrow->first_page) &&
  1498. (page <= csrow->last_page) &&
  1499. ((page & csrow->page_mask) ==
  1500. (csrow->first_page & csrow->page_mask))) {
  1501. row = i;
  1502. break;
  1503. }
  1504. }
  1505. if (row == -1)
  1506. edac_mc_printk(mci, KERN_ERR,
  1507. "could not look up page error address %lx\n",
  1508. (unsigned long) page);
  1509. return row;
  1510. }
  1511. EXPORT_SYMBOL_GPL(edac_mc_find_csrow_by_page);
  1512. /* FIXME - setable log (warning/emerg) levels */
  1513. /* FIXME - integrate with evlog: http://evlog.sourceforge.net/ */
  1514. void edac_mc_handle_ce(struct mem_ctl_info *mci,
  1515. unsigned long page_frame_number, unsigned long offset_in_page,
  1516. unsigned long syndrome, int row, int channel, const char *msg)
  1517. {
  1518. unsigned long remapped_page;
  1519. debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
  1520. /* FIXME - maybe make panic on INTERNAL ERROR an option */
  1521. if (row >= mci->nr_csrows || row < 0) {
  1522. /* something is wrong */
  1523. edac_mc_printk(mci, KERN_ERR,
  1524. "INTERNAL ERROR: row out of range "
  1525. "(%d >= %d)\n", row, mci->nr_csrows);
  1526. edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
  1527. return;
  1528. }
  1529. if (channel >= mci->csrows[row].nr_channels || channel < 0) {
  1530. /* something is wrong */
  1531. edac_mc_printk(mci, KERN_ERR,
  1532. "INTERNAL ERROR: channel out of range "
  1533. "(%d >= %d)\n", channel,
  1534. mci->csrows[row].nr_channels);
  1535. edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
  1536. return;
  1537. }
  1538. if (log_ce)
  1539. /* FIXME - put in DIMM location */
  1540. edac_mc_printk(mci, KERN_WARNING,
  1541. "CE page 0x%lx, offset 0x%lx, grain %d, syndrome "
  1542. "0x%lx, row %d, channel %d, label \"%s\": %s\n",
  1543. page_frame_number, offset_in_page,
  1544. mci->csrows[row].grain, syndrome, row, channel,
  1545. mci->csrows[row].channels[channel].label, msg);
  1546. mci->ce_count++;
  1547. mci->csrows[row].ce_count++;
  1548. mci->csrows[row].channels[channel].ce_count++;
  1549. if (mci->scrub_mode & SCRUB_SW_SRC) {
  1550. /*
  1551. * Some MC's can remap memory so that it is still available
  1552. * at a different address when PCI devices map into memory.
  1553. * MC's that can't do this lose the memory where PCI devices
  1554. * are mapped. This mapping is MC dependant and so we call
  1555. * back into the MC driver for it to map the MC page to
  1556. * a physical (CPU) page which can then be mapped to a virtual
  1557. * page - which can then be scrubbed.
  1558. */
  1559. remapped_page = mci->ctl_page_to_phys ?
  1560. mci->ctl_page_to_phys(mci, page_frame_number) :
  1561. page_frame_number;
  1562. edac_mc_scrub_block(remapped_page, offset_in_page,
  1563. mci->csrows[row].grain);
  1564. }
  1565. }
  1566. EXPORT_SYMBOL_GPL(edac_mc_handle_ce);
  1567. void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci, const char *msg)
  1568. {
  1569. if (log_ce)
  1570. edac_mc_printk(mci, KERN_WARNING,
  1571. "CE - no information available: %s\n", msg);
  1572. mci->ce_noinfo_count++;
  1573. mci->ce_count++;
  1574. }
  1575. EXPORT_SYMBOL_GPL(edac_mc_handle_ce_no_info);
  1576. void edac_mc_handle_ue(struct mem_ctl_info *mci,
  1577. unsigned long page_frame_number, unsigned long offset_in_page,
  1578. int row, const char *msg)
  1579. {
  1580. int len = EDAC_MC_LABEL_LEN * 4;
  1581. char labels[len + 1];
  1582. char *pos = labels;
  1583. int chan;
  1584. int chars;
  1585. debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
  1586. /* FIXME - maybe make panic on INTERNAL ERROR an option */
  1587. if (row >= mci->nr_csrows || row < 0) {
  1588. /* something is wrong */
  1589. edac_mc_printk(mci, KERN_ERR,
  1590. "INTERNAL ERROR: row out of range "
  1591. "(%d >= %d)\n", row, mci->nr_csrows);
  1592. edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
  1593. return;
  1594. }
  1595. chars = snprintf(pos, len + 1, "%s",
  1596. mci->csrows[row].channels[0].label);
  1597. len -= chars;
  1598. pos += chars;
  1599. for (chan = 1; (chan < mci->csrows[row].nr_channels) && (len > 0);
  1600. chan++) {
  1601. chars = snprintf(pos, len + 1, ":%s",
  1602. mci->csrows[row].channels[chan].label);
  1603. len -= chars;
  1604. pos += chars;
  1605. }
  1606. if (log_ue)
  1607. edac_mc_printk(mci, KERN_EMERG,
  1608. "UE page 0x%lx, offset 0x%lx, grain %d, row %d, "
  1609. "labels \"%s\": %s\n", page_frame_number,
  1610. offset_in_page, mci->csrows[row].grain, row, labels,
  1611. msg);
  1612. if (panic_on_ue)
  1613. panic("EDAC MC%d: UE page 0x%lx, offset 0x%lx, grain %d, "
  1614. "row %d, labels \"%s\": %s\n", mci->mc_idx,
  1615. page_frame_number, offset_in_page,
  1616. mci->csrows[row].grain, row, labels, msg);
  1617. mci->ue_count++;
  1618. mci->csrows[row].ue_count++;
  1619. }
  1620. EXPORT_SYMBOL_GPL(edac_mc_handle_ue);
  1621. void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci, const char *msg)
  1622. {
  1623. if (panic_on_ue)
  1624. panic("EDAC MC%d: Uncorrected Error", mci->mc_idx);
  1625. if (log_ue)
  1626. edac_mc_printk(mci, KERN_WARNING,
  1627. "UE - no information available: %s\n", msg);
  1628. mci->ue_noinfo_count++;
  1629. mci->ue_count++;
  1630. }
  1631. EXPORT_SYMBOL_GPL(edac_mc_handle_ue_no_info);
  1632. /*
  1633. * Iterate over all MC instances and check for ECC, et al, errors
  1634. */
  1635. static inline void check_mc_devices(void)
  1636. {
  1637. struct list_head *item;
  1638. struct mem_ctl_info *mci;
  1639. debugf3("%s()\n", __func__);
  1640. down(&mem_ctls_mutex);
  1641. list_for_each(item, &mc_devices) {
  1642. mci = list_entry(item, struct mem_ctl_info, link);
  1643. if (mci->edac_check != NULL)
  1644. mci->edac_check(mci);
  1645. }
  1646. up(&mem_ctls_mutex);
  1647. }
  1648. /*
  1649. * Check MC status every poll_msec.
  1650. * Check PCI status every poll_msec as well.
  1651. *
  1652. * This where the work gets done for edac.
  1653. *
  1654. * SMP safe, doesn't use NMI, and auto-rate-limits.
  1655. */
  1656. static void do_edac_check(void)
  1657. {
  1658. debugf3("%s()\n", __func__);
  1659. check_mc_devices();
  1660. do_pci_parity_check();
  1661. }
  1662. static int edac_kernel_thread(void *arg)
  1663. {
  1664. while (!kthread_should_stop()) {
  1665. do_edac_check();
  1666. /* goto sleep for the interval */
  1667. schedule_timeout_interruptible((HZ * poll_msec) / 1000);
  1668. try_to_freeze();
  1669. }
  1670. return 0;
  1671. }
  1672. /*
  1673. * edac_mc_init
  1674. * module initialization entry point
  1675. */
  1676. static int __init edac_mc_init(void)
  1677. {
  1678. edac_printk(KERN_INFO, EDAC_MC, EDAC_MC_VERSION "\n");
  1679. /*
  1680. * Harvest and clear any boot/initialization PCI parity errors
  1681. *
  1682. * FIXME: This only clears errors logged by devices present at time of
  1683. * module initialization. We should also do an initial clear
  1684. * of each newly hotplugged device.
  1685. */
  1686. clear_pci_parity_errors();
  1687. /* Create the MC sysfs entries */
  1688. if (edac_sysfs_memctrl_setup()) {
  1689. edac_printk(KERN_ERR, EDAC_MC,
  1690. "Error initializing sysfs code\n");
  1691. return -ENODEV;
  1692. }
  1693. /* Create the PCI parity sysfs entries */
  1694. if (edac_sysfs_pci_setup()) {
  1695. edac_sysfs_memctrl_teardown();
  1696. edac_printk(KERN_ERR, EDAC_MC,
  1697. "EDAC PCI: Error initializing sysfs code\n");
  1698. return -ENODEV;
  1699. }
  1700. /* create our kernel thread */
  1701. edac_thread = kthread_run(edac_kernel_thread, NULL, "kedac");
  1702. if (IS_ERR(edac_thread)) {
  1703. /* remove the sysfs entries */
  1704. edac_sysfs_memctrl_teardown();
  1705. edac_sysfs_pci_teardown();
  1706. return PTR_ERR(edac_thread);
  1707. }
  1708. return 0;
  1709. }
  1710. /*
  1711. * edac_mc_exit()
  1712. * module exit/termination functioni
  1713. */
  1714. static void __exit edac_mc_exit(void)
  1715. {
  1716. debugf0("%s()\n", __func__);
  1717. kthread_stop(edac_thread);
  1718. /* tear down the sysfs device */
  1719. edac_sysfs_memctrl_teardown();
  1720. edac_sysfs_pci_teardown();
  1721. }
  1722. module_init(edac_mc_init);
  1723. module_exit(edac_mc_exit);
  1724. MODULE_LICENSE("GPL");
  1725. MODULE_AUTHOR("Linux Networx (http://lnxi.com) Thayne Harbaugh et al\n"
  1726. "Based on work by Dan Hollis et al");
  1727. MODULE_DESCRIPTION("Core library routines for MC reporting");
  1728. module_param(panic_on_ue, int, 0644);
  1729. MODULE_PARM_DESC(panic_on_ue, "Panic on uncorrected error: 0=off 1=on");
  1730. #ifdef CONFIG_PCI
  1731. module_param(check_pci_parity, int, 0644);
  1732. MODULE_PARM_DESC(check_pci_parity, "Check for PCI bus parity errors: 0=off 1=on");
  1733. module_param(panic_on_pci_parity, int, 0644);
  1734. MODULE_PARM_DESC(panic_on_pci_parity, "Panic on PCI Bus Parity error: 0=off 1=on");
  1735. #endif
  1736. module_param(log_ue, int, 0644);
  1737. MODULE_PARM_DESC(log_ue, "Log uncorrectable error to console: 0=off 1=on");
  1738. module_param(log_ce, int, 0644);
  1739. MODULE_PARM_DESC(log_ce, "Log correctable error to console: 0=off 1=on");
  1740. module_param(poll_msec, int, 0644);
  1741. MODULE_PARM_DESC(poll_msec, "Polling period in milliseconds");
  1742. #ifdef CONFIG_EDAC_DEBUG
  1743. module_param(edac_debug_level, int, 0644);
  1744. MODULE_PARM_DESC(edac_debug_level, "Debug level");
  1745. #endif