edac_mc.c 54 KB

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