edac_mc_sysfs.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. /*
  2. * edac_mc kernel module
  3. * (C) 2005, 2006 Linux Networx (http://lnxi.com)
  4. * This file may be distributed under the terms of the
  5. * GNU General Public License.
  6. *
  7. * Written Doug Thompson <norsk5@xmission.com>
  8. *
  9. */
  10. #include <linux/module.h>
  11. #include <linux/sysdev.h>
  12. #include <linux/ctype.h>
  13. #include "edac_mc.h"
  14. #include "edac_module.h"
  15. /* MC EDAC Controls, setable by module parameter, and sysfs */
  16. static int log_ue = 1;
  17. static int log_ce = 1;
  18. static int panic_on_ue;
  19. static int poll_msec = 1000;
  20. /* Getter functions for above */
  21. int edac_get_log_ue()
  22. {
  23. return log_ue;
  24. }
  25. int edac_get_log_ce()
  26. {
  27. return log_ce;
  28. }
  29. int edac_get_panic_on_ue()
  30. {
  31. return panic_on_ue;
  32. }
  33. int edac_get_poll_msec()
  34. {
  35. return poll_msec;
  36. }
  37. /* Parameter declarations for above */
  38. module_param(panic_on_ue, int, 0644);
  39. MODULE_PARM_DESC(panic_on_ue, "Panic on uncorrected error: 0=off 1=on");
  40. module_param(log_ue, int, 0644);
  41. MODULE_PARM_DESC(log_ue, "Log uncorrectable error to console: 0=off 1=on");
  42. module_param(log_ce, int, 0644);
  43. MODULE_PARM_DESC(log_ce, "Log correctable error to console: 0=off 1=on");
  44. module_param(poll_msec, int, 0644);
  45. MODULE_PARM_DESC(poll_msec, "Polling period in milliseconds");
  46. /*
  47. * various constants for Memory Controllers
  48. */
  49. static const char *mem_types[] = {
  50. [MEM_EMPTY] = "Empty",
  51. [MEM_RESERVED] = "Reserved",
  52. [MEM_UNKNOWN] = "Unknown",
  53. [MEM_FPM] = "FPM",
  54. [MEM_EDO] = "EDO",
  55. [MEM_BEDO] = "BEDO",
  56. [MEM_SDR] = "Unbuffered-SDR",
  57. [MEM_RDR] = "Registered-SDR",
  58. [MEM_DDR] = "Unbuffered-DDR",
  59. [MEM_RDDR] = "Registered-DDR",
  60. [MEM_RMBS] = "RMBS",
  61. [MEM_DDR2] = "Unbuffered-DDR2",
  62. [MEM_FB_DDR2] = "FullyBuffered-DDR2",
  63. [MEM_RDDR2] = "Registered-DDR2"
  64. };
  65. static const char *dev_types[] = {
  66. [DEV_UNKNOWN] = "Unknown",
  67. [DEV_X1] = "x1",
  68. [DEV_X2] = "x2",
  69. [DEV_X4] = "x4",
  70. [DEV_X8] = "x8",
  71. [DEV_X16] = "x16",
  72. [DEV_X32] = "x32",
  73. [DEV_X64] = "x64"
  74. };
  75. static const char *edac_caps[] = {
  76. [EDAC_UNKNOWN] = "Unknown",
  77. [EDAC_NONE] = "None",
  78. [EDAC_RESERVED] = "Reserved",
  79. [EDAC_PARITY] = "PARITY",
  80. [EDAC_EC] = "EC",
  81. [EDAC_SECDED] = "SECDED",
  82. [EDAC_S2ECD2ED] = "S2ECD2ED",
  83. [EDAC_S4ECD4ED] = "S4ECD4ED",
  84. [EDAC_S8ECD8ED] = "S8ECD8ED",
  85. [EDAC_S16ECD16ED] = "S16ECD16ED"
  86. };
  87. /* sysfs object:
  88. * /sys/devices/system/edac/mc
  89. */
  90. static struct kobject edac_memctrl_kobj;
  91. /* We use these to wait for the reference counts on edac_memctrl_kobj and
  92. * edac_pci_kobj to reach 0.
  93. */
  94. static struct completion edac_memctrl_kobj_complete;
  95. /*
  96. * /sys/devices/system/edac/mc;
  97. * data structures and methods
  98. */
  99. static ssize_t memctrl_int_show(void *ptr, char *buffer)
  100. {
  101. int *value = (int*) ptr;
  102. return sprintf(buffer, "%u\n", *value);
  103. }
  104. static ssize_t memctrl_int_store(void *ptr, const char *buffer, size_t count)
  105. {
  106. int *value = (int*) ptr;
  107. if (isdigit(*buffer))
  108. *value = simple_strtoul(buffer, NULL, 0);
  109. return count;
  110. }
  111. struct memctrl_dev_attribute {
  112. struct attribute attr;
  113. void *value;
  114. ssize_t (*show)(void *,char *);
  115. ssize_t (*store)(void *, const char *, size_t);
  116. };
  117. /* Set of show/store abstract level functions for memory control object */
  118. static ssize_t memctrl_dev_show(struct kobject *kobj,
  119. struct attribute *attr, char *buffer)
  120. {
  121. struct memctrl_dev_attribute *memctrl_dev;
  122. memctrl_dev = (struct memctrl_dev_attribute*)attr;
  123. if (memctrl_dev->show)
  124. return memctrl_dev->show(memctrl_dev->value, buffer);
  125. return -EIO;
  126. }
  127. static ssize_t memctrl_dev_store(struct kobject *kobj, struct attribute *attr,
  128. const char *buffer, size_t count)
  129. {
  130. struct memctrl_dev_attribute *memctrl_dev;
  131. memctrl_dev = (struct memctrl_dev_attribute*)attr;
  132. if (memctrl_dev->store)
  133. return memctrl_dev->store(memctrl_dev->value, buffer, count);
  134. return -EIO;
  135. }
  136. static struct sysfs_ops memctrlfs_ops = {
  137. .show = memctrl_dev_show,
  138. .store = memctrl_dev_store
  139. };
  140. #define MEMCTRL_ATTR(_name,_mode,_show,_store) \
  141. static struct memctrl_dev_attribute attr_##_name = { \
  142. .attr = {.name = __stringify(_name), .mode = _mode }, \
  143. .value = &_name, \
  144. .show = _show, \
  145. .store = _store, \
  146. };
  147. #define MEMCTRL_STRING_ATTR(_name,_data,_mode,_show,_store) \
  148. static struct memctrl_dev_attribute attr_##_name = { \
  149. .attr = {.name = __stringify(_name), .mode = _mode }, \
  150. .value = _data, \
  151. .show = _show, \
  152. .store = _store, \
  153. };
  154. /* csrow<id> control files */
  155. MEMCTRL_ATTR(panic_on_ue,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store);
  156. MEMCTRL_ATTR(log_ue,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store);
  157. MEMCTRL_ATTR(log_ce,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store);
  158. MEMCTRL_ATTR(poll_msec,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store);
  159. /* Base Attributes of the memory ECC object */
  160. static struct memctrl_dev_attribute *memctrl_attr[] = {
  161. &attr_panic_on_ue,
  162. &attr_log_ue,
  163. &attr_log_ce,
  164. &attr_poll_msec,
  165. NULL,
  166. };
  167. /* Main MC kobject release() function */
  168. static void edac_memctrl_master_release(struct kobject *kobj)
  169. {
  170. debugf1("%s()\n", __func__);
  171. complete(&edac_memctrl_kobj_complete);
  172. }
  173. static struct kobj_type ktype_memctrl = {
  174. .release = edac_memctrl_master_release,
  175. .sysfs_ops = &memctrlfs_ops,
  176. .default_attrs = (struct attribute **) memctrl_attr,
  177. };
  178. /* Initialize the main sysfs entries for edac:
  179. * /sys/devices/system/edac
  180. *
  181. * and children
  182. *
  183. * Return: 0 SUCCESS
  184. * !0 FAILURE
  185. */
  186. int edac_sysfs_memctrl_setup(void)
  187. {
  188. int err = 0;
  189. struct sysdev_class *edac_class;
  190. debugf1("%s()\n", __func__);
  191. /* get the /sys/devices/system/edac class reference */
  192. edac_class = edac_get_edac_class();
  193. if (edac_class == NULL) {
  194. debugf1("%s() no edac_class error=%d\n", __func__, err);
  195. return err;
  196. }
  197. /* Init the MC's kobject */
  198. memset(&edac_memctrl_kobj, 0, sizeof (edac_memctrl_kobj));
  199. edac_memctrl_kobj.parent = &edac_class->kset.kobj;
  200. edac_memctrl_kobj.ktype = &ktype_memctrl;
  201. /* generate sysfs "..../edac/mc" */
  202. err = kobject_set_name(&edac_memctrl_kobj,"mc");
  203. if (err) {
  204. debugf1("%s() Failed to set name '.../edac/mc'\n", __func__ );
  205. return err;
  206. }
  207. /* FIXME: maybe new sysdev_create_subdir() */
  208. err = kobject_register(&edac_memctrl_kobj);
  209. if (err) {
  210. debugf1("%s() Failed to register '.../edac/mc'\n", __func__ );
  211. return err;
  212. }
  213. debugf1("%s() Registered '.../edac/mc' kobject\n",__func__);
  214. return 0;
  215. }
  216. /*
  217. * MC teardown:
  218. * the '..../edac/mc' kobject followed by '..../edac' itself
  219. */
  220. void edac_sysfs_memctrl_teardown(void)
  221. {
  222. debugf0("MC: " __FILE__ ": %s()\n", __func__);
  223. /* Unregister the MC's kobject and wait for reference count to reach 0.
  224. */
  225. init_completion(&edac_memctrl_kobj_complete);
  226. kobject_unregister(&edac_memctrl_kobj);
  227. wait_for_completion(&edac_memctrl_kobj_complete);
  228. }
  229. /* EDAC sysfs CSROW data structures and methods
  230. */
  231. /* Set of more default csrow<id> attribute show/store functions */
  232. static ssize_t csrow_ue_count_show(struct csrow_info *csrow, char *data,
  233. int private)
  234. {
  235. return sprintf(data,"%u\n", csrow->ue_count);
  236. }
  237. static ssize_t csrow_ce_count_show(struct csrow_info *csrow, char *data,
  238. int private)
  239. {
  240. return sprintf(data,"%u\n", csrow->ce_count);
  241. }
  242. static ssize_t csrow_size_show(struct csrow_info *csrow, char *data,
  243. int private)
  244. {
  245. return sprintf(data,"%u\n", PAGES_TO_MiB(csrow->nr_pages));
  246. }
  247. static ssize_t csrow_mem_type_show(struct csrow_info *csrow, char *data,
  248. int private)
  249. {
  250. return sprintf(data,"%s\n", mem_types[csrow->mtype]);
  251. }
  252. static ssize_t csrow_dev_type_show(struct csrow_info *csrow, char *data,
  253. int private)
  254. {
  255. return sprintf(data,"%s\n", dev_types[csrow->dtype]);
  256. }
  257. static ssize_t csrow_edac_mode_show(struct csrow_info *csrow, char *data,
  258. int private)
  259. {
  260. return sprintf(data,"%s\n", edac_caps[csrow->edac_mode]);
  261. }
  262. /* show/store functions for DIMM Label attributes */
  263. static ssize_t channel_dimm_label_show(struct csrow_info *csrow,
  264. char *data, int channel)
  265. {
  266. return snprintf(data, EDAC_MC_LABEL_LEN,"%s",
  267. csrow->channels[channel].label);
  268. }
  269. static ssize_t channel_dimm_label_store(struct csrow_info *csrow,
  270. const char *data,
  271. size_t count,
  272. int channel)
  273. {
  274. ssize_t max_size = 0;
  275. max_size = min((ssize_t)count,(ssize_t)EDAC_MC_LABEL_LEN-1);
  276. strncpy(csrow->channels[channel].label, data, max_size);
  277. csrow->channels[channel].label[max_size] = '\0';
  278. return max_size;
  279. }
  280. /* show function for dynamic chX_ce_count attribute */
  281. static ssize_t channel_ce_count_show(struct csrow_info *csrow,
  282. char *data,
  283. int channel)
  284. {
  285. return sprintf(data, "%u\n", csrow->channels[channel].ce_count);
  286. }
  287. /* csrow specific attribute structure */
  288. struct csrowdev_attribute {
  289. struct attribute attr;
  290. ssize_t (*show)(struct csrow_info *,char *,int);
  291. ssize_t (*store)(struct csrow_info *, const char *,size_t,int);
  292. int private;
  293. };
  294. #define to_csrow(k) container_of(k, struct csrow_info, kobj)
  295. #define to_csrowdev_attr(a) container_of(a, struct csrowdev_attribute, attr)
  296. /* Set of show/store higher level functions for default csrow attributes */
  297. static ssize_t csrowdev_show(struct kobject *kobj,
  298. struct attribute *attr,
  299. char *buffer)
  300. {
  301. struct csrow_info *csrow = to_csrow(kobj);
  302. struct csrowdev_attribute *csrowdev_attr = to_csrowdev_attr(attr);
  303. if (csrowdev_attr->show)
  304. return csrowdev_attr->show(csrow,
  305. buffer,
  306. csrowdev_attr->private);
  307. return -EIO;
  308. }
  309. static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr,
  310. const char *buffer, size_t count)
  311. {
  312. struct csrow_info *csrow = to_csrow(kobj);
  313. struct csrowdev_attribute * csrowdev_attr = to_csrowdev_attr(attr);
  314. if (csrowdev_attr->store)
  315. return csrowdev_attr->store(csrow,
  316. buffer,
  317. count,
  318. csrowdev_attr->private);
  319. return -EIO;
  320. }
  321. static struct sysfs_ops csrowfs_ops = {
  322. .show = csrowdev_show,
  323. .store = csrowdev_store
  324. };
  325. #define CSROWDEV_ATTR(_name,_mode,_show,_store,_private) \
  326. static struct csrowdev_attribute attr_##_name = { \
  327. .attr = {.name = __stringify(_name), .mode = _mode }, \
  328. .show = _show, \
  329. .store = _store, \
  330. .private = _private, \
  331. };
  332. /* default cwrow<id>/attribute files */
  333. CSROWDEV_ATTR(size_mb,S_IRUGO,csrow_size_show,NULL,0);
  334. CSROWDEV_ATTR(dev_type,S_IRUGO,csrow_dev_type_show,NULL,0);
  335. CSROWDEV_ATTR(mem_type,S_IRUGO,csrow_mem_type_show,NULL,0);
  336. CSROWDEV_ATTR(edac_mode,S_IRUGO,csrow_edac_mode_show,NULL,0);
  337. CSROWDEV_ATTR(ue_count,S_IRUGO,csrow_ue_count_show,NULL,0);
  338. CSROWDEV_ATTR(ce_count,S_IRUGO,csrow_ce_count_show,NULL,0);
  339. /* default attributes of the CSROW<id> object */
  340. static struct csrowdev_attribute *default_csrow_attr[] = {
  341. &attr_dev_type,
  342. &attr_mem_type,
  343. &attr_edac_mode,
  344. &attr_size_mb,
  345. &attr_ue_count,
  346. &attr_ce_count,
  347. NULL,
  348. };
  349. /* possible dynamic channel DIMM Label attribute files */
  350. CSROWDEV_ATTR(ch0_dimm_label,S_IRUGO|S_IWUSR,
  351. channel_dimm_label_show,
  352. channel_dimm_label_store,
  353. 0 );
  354. CSROWDEV_ATTR(ch1_dimm_label,S_IRUGO|S_IWUSR,
  355. channel_dimm_label_show,
  356. channel_dimm_label_store,
  357. 1 );
  358. CSROWDEV_ATTR(ch2_dimm_label,S_IRUGO|S_IWUSR,
  359. channel_dimm_label_show,
  360. channel_dimm_label_store,
  361. 2 );
  362. CSROWDEV_ATTR(ch3_dimm_label,S_IRUGO|S_IWUSR,
  363. channel_dimm_label_show,
  364. channel_dimm_label_store,
  365. 3 );
  366. CSROWDEV_ATTR(ch4_dimm_label,S_IRUGO|S_IWUSR,
  367. channel_dimm_label_show,
  368. channel_dimm_label_store,
  369. 4 );
  370. CSROWDEV_ATTR(ch5_dimm_label,S_IRUGO|S_IWUSR,
  371. channel_dimm_label_show,
  372. channel_dimm_label_store,
  373. 5 );
  374. /* Total possible dynamic DIMM Label attribute file table */
  375. static struct csrowdev_attribute *dynamic_csrow_dimm_attr[] = {
  376. &attr_ch0_dimm_label,
  377. &attr_ch1_dimm_label,
  378. &attr_ch2_dimm_label,
  379. &attr_ch3_dimm_label,
  380. &attr_ch4_dimm_label,
  381. &attr_ch5_dimm_label
  382. };
  383. /* possible dynamic channel ce_count attribute files */
  384. CSROWDEV_ATTR(ch0_ce_count,S_IRUGO|S_IWUSR,
  385. channel_ce_count_show,
  386. NULL,
  387. 0 );
  388. CSROWDEV_ATTR(ch1_ce_count,S_IRUGO|S_IWUSR,
  389. channel_ce_count_show,
  390. NULL,
  391. 1 );
  392. CSROWDEV_ATTR(ch2_ce_count,S_IRUGO|S_IWUSR,
  393. channel_ce_count_show,
  394. NULL,
  395. 2 );
  396. CSROWDEV_ATTR(ch3_ce_count,S_IRUGO|S_IWUSR,
  397. channel_ce_count_show,
  398. NULL,
  399. 3 );
  400. CSROWDEV_ATTR(ch4_ce_count,S_IRUGO|S_IWUSR,
  401. channel_ce_count_show,
  402. NULL,
  403. 4 );
  404. CSROWDEV_ATTR(ch5_ce_count,S_IRUGO|S_IWUSR,
  405. channel_ce_count_show,
  406. NULL,
  407. 5 );
  408. /* Total possible dynamic ce_count attribute file table */
  409. static struct csrowdev_attribute *dynamic_csrow_ce_count_attr[] = {
  410. &attr_ch0_ce_count,
  411. &attr_ch1_ce_count,
  412. &attr_ch2_ce_count,
  413. &attr_ch3_ce_count,
  414. &attr_ch4_ce_count,
  415. &attr_ch5_ce_count
  416. };
  417. #define EDAC_NR_CHANNELS 6
  418. /* Create dynamic CHANNEL files, indexed by 'chan', under specifed CSROW */
  419. static int edac_create_channel_files(struct kobject *kobj, int chan)
  420. {
  421. int err=-ENODEV;
  422. if (chan >= EDAC_NR_CHANNELS)
  423. return err;
  424. /* create the DIMM label attribute file */
  425. err = sysfs_create_file(kobj,
  426. (struct attribute *) dynamic_csrow_dimm_attr[chan]);
  427. if (!err) {
  428. /* create the CE Count attribute file */
  429. err = sysfs_create_file(kobj,
  430. (struct attribute *)dynamic_csrow_ce_count_attr[chan]);
  431. } else {
  432. debugf1("%s() dimm labels and ce_count files created",
  433. __func__);
  434. }
  435. return err;
  436. }
  437. /* No memory to release for this kobj */
  438. static void edac_csrow_instance_release(struct kobject *kobj)
  439. {
  440. struct csrow_info *cs;
  441. cs = container_of(kobj, struct csrow_info, kobj);
  442. complete(&cs->kobj_complete);
  443. }
  444. /* the kobj_type instance for a CSROW */
  445. static struct kobj_type ktype_csrow = {
  446. .release = edac_csrow_instance_release,
  447. .sysfs_ops = &csrowfs_ops,
  448. .default_attrs = (struct attribute **) default_csrow_attr,
  449. };
  450. /* Create a CSROW object under specifed edac_mc_device */
  451. static int edac_create_csrow_object(
  452. struct kobject *edac_mci_kobj,
  453. struct csrow_info *csrow,
  454. int index)
  455. {
  456. int err = 0;
  457. int chan;
  458. memset(&csrow->kobj, 0, sizeof(csrow->kobj));
  459. /* generate ..../edac/mc/mc<id>/csrow<index> */
  460. csrow->kobj.parent = edac_mci_kobj;
  461. csrow->kobj.ktype = &ktype_csrow;
  462. /* name this instance of csrow<id> */
  463. err = kobject_set_name(&csrow->kobj,"csrow%d",index);
  464. if (err)
  465. goto error_exit;
  466. /* Instanstiate the csrow object */
  467. err = kobject_register(&csrow->kobj);
  468. if (!err) {
  469. /* Create the dyanmic attribute files on this csrow,
  470. * namely, the DIMM labels and the channel ce_count
  471. */
  472. for (chan = 0; chan < csrow->nr_channels; chan++) {
  473. err = edac_create_channel_files(&csrow->kobj,chan);
  474. if (err)
  475. break;
  476. }
  477. }
  478. error_exit:
  479. return err;
  480. }
  481. /* default sysfs methods and data structures for the main MCI kobject */
  482. static ssize_t mci_reset_counters_store(struct mem_ctl_info *mci,
  483. const char *data, size_t count)
  484. {
  485. int row, chan;
  486. mci->ue_noinfo_count = 0;
  487. mci->ce_noinfo_count = 0;
  488. mci->ue_count = 0;
  489. mci->ce_count = 0;
  490. for (row = 0; row < mci->nr_csrows; row++) {
  491. struct csrow_info *ri = &mci->csrows[row];
  492. ri->ue_count = 0;
  493. ri->ce_count = 0;
  494. for (chan = 0; chan < ri->nr_channels; chan++)
  495. ri->channels[chan].ce_count = 0;
  496. }
  497. mci->start_time = jiffies;
  498. return count;
  499. }
  500. /* memory scrubbing */
  501. static ssize_t mci_sdram_scrub_rate_store(struct mem_ctl_info *mci,
  502. const char *data, size_t count)
  503. {
  504. u32 bandwidth = -1;
  505. if (mci->set_sdram_scrub_rate) {
  506. memctrl_int_store(&bandwidth, data, count);
  507. if (!(*mci->set_sdram_scrub_rate)(mci, &bandwidth)) {
  508. edac_printk(KERN_DEBUG, EDAC_MC,
  509. "Scrub rate set successfully, applied: %d\n",
  510. bandwidth);
  511. } else {
  512. /* FIXME: error codes maybe? */
  513. edac_printk(KERN_DEBUG, EDAC_MC,
  514. "Scrub rate set FAILED, could not apply: %d\n",
  515. bandwidth);
  516. }
  517. } else {
  518. /* FIXME: produce "not implemented" ERROR for user-side. */
  519. edac_printk(KERN_WARNING, EDAC_MC,
  520. "Memory scrubbing 'set'control is not implemented!\n");
  521. }
  522. return count;
  523. }
  524. static ssize_t mci_sdram_scrub_rate_show(struct mem_ctl_info *mci, char *data)
  525. {
  526. u32 bandwidth = -1;
  527. if (mci->get_sdram_scrub_rate) {
  528. if (!(*mci->get_sdram_scrub_rate)(mci, &bandwidth)) {
  529. edac_printk(KERN_DEBUG, EDAC_MC,
  530. "Scrub rate successfully, fetched: %d\n",
  531. bandwidth);
  532. } else {
  533. /* FIXME: error codes maybe? */
  534. edac_printk(KERN_DEBUG, EDAC_MC,
  535. "Scrub rate fetch FAILED, got: %d\n",
  536. bandwidth);
  537. }
  538. } else {
  539. /* FIXME: produce "not implemented" ERROR for user-side. */
  540. edac_printk(KERN_WARNING, EDAC_MC,
  541. "Memory scrubbing 'get' control is not implemented\n");
  542. }
  543. return sprintf(data, "%d\n", bandwidth);
  544. }
  545. /* default attribute files for the MCI object */
  546. static ssize_t mci_ue_count_show(struct mem_ctl_info *mci, char *data)
  547. {
  548. return sprintf(data,"%d\n", mci->ue_count);
  549. }
  550. static ssize_t mci_ce_count_show(struct mem_ctl_info *mci, char *data)
  551. {
  552. return sprintf(data,"%d\n", mci->ce_count);
  553. }
  554. static ssize_t mci_ce_noinfo_show(struct mem_ctl_info *mci, char *data)
  555. {
  556. return sprintf(data,"%d\n", mci->ce_noinfo_count);
  557. }
  558. static ssize_t mci_ue_noinfo_show(struct mem_ctl_info *mci, char *data)
  559. {
  560. return sprintf(data,"%d\n", mci->ue_noinfo_count);
  561. }
  562. static ssize_t mci_seconds_show(struct mem_ctl_info *mci, char *data)
  563. {
  564. return sprintf(data,"%ld\n", (jiffies - mci->start_time) / HZ);
  565. }
  566. static ssize_t mci_ctl_name_show(struct mem_ctl_info *mci, char *data)
  567. {
  568. return sprintf(data,"%s\n", mci->ctl_name);
  569. }
  570. static ssize_t mci_size_mb_show(struct mem_ctl_info *mci, char *data)
  571. {
  572. int total_pages, csrow_idx;
  573. for (total_pages = csrow_idx = 0; csrow_idx < mci->nr_csrows;
  574. csrow_idx++) {
  575. struct csrow_info *csrow = &mci->csrows[csrow_idx];
  576. if (!csrow->nr_pages)
  577. continue;
  578. total_pages += csrow->nr_pages;
  579. }
  580. return sprintf(data,"%u\n", PAGES_TO_MiB(total_pages));
  581. }
  582. struct mcidev_attribute {
  583. struct attribute attr;
  584. ssize_t (*show)(struct mem_ctl_info *,char *);
  585. ssize_t (*store)(struct mem_ctl_info *, const char *,size_t);
  586. };
  587. #define to_mci(k) container_of(k, struct mem_ctl_info, edac_mci_kobj)
  588. #define to_mcidev_attr(a) container_of(a, struct mcidev_attribute, attr)
  589. /* MCI show/store functions for top most object */
  590. static ssize_t mcidev_show(struct kobject *kobj, struct attribute *attr,
  591. char *buffer)
  592. {
  593. struct mem_ctl_info *mem_ctl_info = to_mci(kobj);
  594. struct mcidev_attribute * mcidev_attr = to_mcidev_attr(attr);
  595. if (mcidev_attr->show)
  596. return mcidev_attr->show(mem_ctl_info, buffer);
  597. return -EIO;
  598. }
  599. static ssize_t mcidev_store(struct kobject *kobj, struct attribute *attr,
  600. const char *buffer, size_t count)
  601. {
  602. struct mem_ctl_info *mem_ctl_info = to_mci(kobj);
  603. struct mcidev_attribute * mcidev_attr = to_mcidev_attr(attr);
  604. if (mcidev_attr->store)
  605. return mcidev_attr->store(mem_ctl_info, buffer, count);
  606. return -EIO;
  607. }
  608. static struct sysfs_ops mci_ops = {
  609. .show = mcidev_show,
  610. .store = mcidev_store
  611. };
  612. #define MCIDEV_ATTR(_name,_mode,_show,_store) \
  613. static struct mcidev_attribute mci_attr_##_name = { \
  614. .attr = {.name = __stringify(_name), .mode = _mode }, \
  615. .show = _show, \
  616. .store = _store, \
  617. };
  618. /* default Control file */
  619. MCIDEV_ATTR(reset_counters,S_IWUSR,NULL,mci_reset_counters_store);
  620. /* default Attribute files */
  621. MCIDEV_ATTR(mc_name,S_IRUGO,mci_ctl_name_show,NULL);
  622. MCIDEV_ATTR(size_mb,S_IRUGO,mci_size_mb_show,NULL);
  623. MCIDEV_ATTR(seconds_since_reset,S_IRUGO,mci_seconds_show,NULL);
  624. MCIDEV_ATTR(ue_noinfo_count,S_IRUGO,mci_ue_noinfo_show,NULL);
  625. MCIDEV_ATTR(ce_noinfo_count,S_IRUGO,mci_ce_noinfo_show,NULL);
  626. MCIDEV_ATTR(ue_count,S_IRUGO,mci_ue_count_show,NULL);
  627. MCIDEV_ATTR(ce_count,S_IRUGO,mci_ce_count_show,NULL);
  628. /* memory scrubber attribute file */
  629. MCIDEV_ATTR(sdram_scrub_rate,S_IRUGO|S_IWUSR,mci_sdram_scrub_rate_show,\
  630. mci_sdram_scrub_rate_store);
  631. static struct mcidev_attribute *mci_attr[] = {
  632. &mci_attr_reset_counters,
  633. &mci_attr_mc_name,
  634. &mci_attr_size_mb,
  635. &mci_attr_seconds_since_reset,
  636. &mci_attr_ue_noinfo_count,
  637. &mci_attr_ce_noinfo_count,
  638. &mci_attr_ue_count,
  639. &mci_attr_ce_count,
  640. &mci_attr_sdram_scrub_rate,
  641. NULL
  642. };
  643. /*
  644. * Release of a MC controlling instance
  645. */
  646. static void edac_mci_instance_release(struct kobject *kobj)
  647. {
  648. struct mem_ctl_info *mci;
  649. mci = to_mci(kobj);
  650. debugf0("%s() idx=%d\n", __func__, mci->mc_idx);
  651. complete(&mci->kobj_complete);
  652. }
  653. static struct kobj_type ktype_mci = {
  654. .release = edac_mci_instance_release,
  655. .sysfs_ops = &mci_ops,
  656. .default_attrs = (struct attribute **) mci_attr,
  657. };
  658. #define EDAC_DEVICE_SYMLINK "device"
  659. /*
  660. * Create a new Memory Controller kobject instance,
  661. * mc<id> under the 'mc' directory
  662. *
  663. * Return:
  664. * 0 Success
  665. * !0 Failure
  666. */
  667. int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
  668. {
  669. int i;
  670. int err;
  671. struct csrow_info *csrow;
  672. struct kobject *edac_mci_kobj=&mci->edac_mci_kobj;
  673. debugf0("%s() idx=%d\n", __func__, mci->mc_idx);
  674. memset(edac_mci_kobj, 0, sizeof(*edac_mci_kobj));
  675. /* set the name of the mc<id> object */
  676. err = kobject_set_name(edac_mci_kobj,"mc%d",mci->mc_idx);
  677. if (err)
  678. return err;
  679. /* link to our parent the '..../edac/mc' object */
  680. edac_mci_kobj->parent = &edac_memctrl_kobj;
  681. edac_mci_kobj->ktype = &ktype_mci;
  682. /* register the mc<id> kobject */
  683. err = kobject_register(edac_mci_kobj);
  684. if (err)
  685. return err;
  686. /* create a symlink for the device */
  687. err = sysfs_create_link(edac_mci_kobj, &mci->dev->kobj,
  688. EDAC_DEVICE_SYMLINK);
  689. if (err)
  690. goto fail0;
  691. /* Make directories for each CSROW object
  692. * under the mc<id> kobject
  693. */
  694. for (i = 0; i < mci->nr_csrows; i++) {
  695. csrow = &mci->csrows[i];
  696. /* Only expose populated CSROWs */
  697. if (csrow->nr_pages > 0) {
  698. err = edac_create_csrow_object(edac_mci_kobj,csrow,i);
  699. if (err)
  700. goto fail1;
  701. }
  702. }
  703. return 0;
  704. /* CSROW error: backout what has already been registered, */
  705. fail1:
  706. for ( i--; i >= 0; i--) {
  707. if (csrow->nr_pages > 0) {
  708. init_completion(&csrow->kobj_complete);
  709. kobject_unregister(&mci->csrows[i].kobj);
  710. wait_for_completion(&csrow->kobj_complete);
  711. }
  712. }
  713. fail0:
  714. init_completion(&mci->kobj_complete);
  715. kobject_unregister(edac_mci_kobj);
  716. wait_for_completion(&mci->kobj_complete);
  717. return err;
  718. }
  719. /*
  720. * remove a Memory Controller instance
  721. */
  722. void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
  723. {
  724. int i;
  725. debugf0("%s()\n", __func__);
  726. /* remove all csrow kobjects */
  727. for (i = 0; i < mci->nr_csrows; i++) {
  728. if (mci->csrows[i].nr_pages > 0) {
  729. init_completion(&mci->csrows[i].kobj_complete);
  730. kobject_unregister(&mci->csrows[i].kobj);
  731. wait_for_completion(&mci->csrows[i].kobj_complete);
  732. }
  733. }
  734. sysfs_remove_link(&mci->edac_mci_kobj, EDAC_DEVICE_SYMLINK);
  735. init_completion(&mci->kobj_complete);
  736. kobject_unregister(&mci->edac_mci_kobj);
  737. wait_for_completion(&mci->kobj_complete);
  738. }