edac_mc.c 52 KB

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