edac_device.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /*
  2. * edac_device.c
  3. * (C) 2007 www.douglaskthompson.com
  4. *
  5. * This file may be distributed under the terms of the
  6. * GNU General Public License.
  7. *
  8. * Written by Doug Thompson <norsk5@xmission.com>
  9. *
  10. * edac_device API implementation
  11. * 19 Jan 2007
  12. */
  13. #include <linux/module.h>
  14. #include <linux/types.h>
  15. #include <linux/smp.h>
  16. #include <linux/init.h>
  17. #include <linux/sysctl.h>
  18. #include <linux/highmem.h>
  19. #include <linux/timer.h>
  20. #include <linux/slab.h>
  21. #include <linux/jiffies.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/list.h>
  24. #include <linux/ctype.h>
  25. #include <linux/workqueue.h>
  26. #include <asm/uaccess.h>
  27. #include <asm/page.h>
  28. #include "edac_core.h"
  29. #include "edac_module.h"
  30. /* lock for the list: 'edac_device_list', manipulation of this list
  31. * is protected by the 'device_ctls_mutex' lock
  32. */
  33. static DEFINE_MUTEX(device_ctls_mutex);
  34. static LIST_HEAD(edac_device_list);
  35. #ifdef CONFIG_EDAC_DEBUG
  36. static void edac_device_dump_device(struct edac_device_ctl_info *edac_dev)
  37. {
  38. edac_dbg(3, "\tedac_dev = %p dev_idx=%d\n",
  39. edac_dev, edac_dev->dev_idx);
  40. edac_dbg(4, "\tedac_dev->edac_check = %p\n", edac_dev->edac_check);
  41. edac_dbg(3, "\tdev = %p\n", edac_dev->dev);
  42. edac_dbg(3, "\tmod_name:ctl_name = %s:%s\n",
  43. edac_dev->mod_name, edac_dev->ctl_name);
  44. edac_dbg(3, "\tpvt_info = %p\n\n", edac_dev->pvt_info);
  45. }
  46. #endif /* CONFIG_EDAC_DEBUG */
  47. /*
  48. * edac_device_alloc_ctl_info()
  49. * Allocate a new edac device control info structure
  50. *
  51. * The control structure is allocated in complete chunk
  52. * from the OS. It is in turn sub allocated to the
  53. * various objects that compose the structure
  54. *
  55. * The structure has a 'nr_instance' array within itself.
  56. * Each instance represents a major component
  57. * Example: L1 cache and L2 cache are 2 instance components
  58. *
  59. * Within each instance is an array of 'nr_blocks' blockoffsets
  60. */
  61. struct edac_device_ctl_info *edac_device_alloc_ctl_info(
  62. unsigned sz_private,
  63. char *edac_device_name, unsigned nr_instances,
  64. char *edac_block_name, unsigned nr_blocks,
  65. unsigned offset_value, /* zero, 1, or other based offset */
  66. struct edac_dev_sysfs_block_attribute *attrib_spec, unsigned nr_attrib,
  67. int device_index)
  68. {
  69. struct edac_device_ctl_info *dev_ctl;
  70. struct edac_device_instance *dev_inst, *inst;
  71. struct edac_device_block *dev_blk, *blk_p, *blk;
  72. struct edac_dev_sysfs_block_attribute *dev_attrib, *attrib_p, *attrib;
  73. unsigned total_size;
  74. unsigned count;
  75. unsigned instance, block, attr;
  76. void *pvt, *p;
  77. int err;
  78. edac_dbg(4, "instances=%d blocks=%d\n", nr_instances, nr_blocks);
  79. /* Calculate the size of memory we need to allocate AND
  80. * determine the offsets of the various item arrays
  81. * (instance,block,attrib) from the start of an allocated structure.
  82. * We want the alignment of each item (instance,block,attrib)
  83. * to be at least as stringent as what the compiler would
  84. * provide if we could simply hardcode everything into a single struct.
  85. */
  86. p = NULL;
  87. dev_ctl = edac_align_ptr(&p, sizeof(*dev_ctl), 1);
  88. /* Calc the 'end' offset past end of ONE ctl_info structure
  89. * which will become the start of the 'instance' array
  90. */
  91. dev_inst = edac_align_ptr(&p, sizeof(*dev_inst), nr_instances);
  92. /* Calc the 'end' offset past the instance array within the ctl_info
  93. * which will become the start of the block array
  94. */
  95. count = nr_instances * nr_blocks;
  96. dev_blk = edac_align_ptr(&p, sizeof(*dev_blk), count);
  97. /* Calc the 'end' offset past the dev_blk array
  98. * which will become the start of the attrib array, if any.
  99. */
  100. /* calc how many nr_attrib we need */
  101. if (nr_attrib > 0)
  102. count *= nr_attrib;
  103. dev_attrib = edac_align_ptr(&p, sizeof(*dev_attrib), count);
  104. /* Calc the 'end' offset past the attributes array */
  105. pvt = edac_align_ptr(&p, sz_private, 1);
  106. /* 'pvt' now points to where the private data area is.
  107. * At this point 'pvt' (like dev_inst,dev_blk and dev_attrib)
  108. * is baselined at ZERO
  109. */
  110. total_size = ((unsigned long)pvt) + sz_private;
  111. /* Allocate the amount of memory for the set of control structures */
  112. dev_ctl = kzalloc(total_size, GFP_KERNEL);
  113. if (dev_ctl == NULL)
  114. return NULL;
  115. /* Adjust pointers so they point within the actual memory we
  116. * just allocated rather than an imaginary chunk of memory
  117. * located at address 0.
  118. * 'dev_ctl' points to REAL memory, while the others are
  119. * ZERO based and thus need to be adjusted to point within
  120. * the allocated memory.
  121. */
  122. dev_inst = (struct edac_device_instance *)
  123. (((char *)dev_ctl) + ((unsigned long)dev_inst));
  124. dev_blk = (struct edac_device_block *)
  125. (((char *)dev_ctl) + ((unsigned long)dev_blk));
  126. dev_attrib = (struct edac_dev_sysfs_block_attribute *)
  127. (((char *)dev_ctl) + ((unsigned long)dev_attrib));
  128. pvt = sz_private ? (((char *)dev_ctl) + ((unsigned long)pvt)) : NULL;
  129. /* Begin storing the information into the control info structure */
  130. dev_ctl->dev_idx = device_index;
  131. dev_ctl->nr_instances = nr_instances;
  132. dev_ctl->instances = dev_inst;
  133. dev_ctl->pvt_info = pvt;
  134. /* Default logging of CEs and UEs */
  135. dev_ctl->log_ce = 1;
  136. dev_ctl->log_ue = 1;
  137. /* Name of this edac device */
  138. snprintf(dev_ctl->name,sizeof(dev_ctl->name),"%s",edac_device_name);
  139. edac_dbg(4, "edac_dev=%p next after end=%p\n",
  140. dev_ctl, pvt + sz_private);
  141. /* Initialize every Instance */
  142. for (instance = 0; instance < nr_instances; instance++) {
  143. inst = &dev_inst[instance];
  144. inst->ctl = dev_ctl;
  145. inst->nr_blocks = nr_blocks;
  146. blk_p = &dev_blk[instance * nr_blocks];
  147. inst->blocks = blk_p;
  148. /* name of this instance */
  149. snprintf(inst->name, sizeof(inst->name),
  150. "%s%u", edac_device_name, instance);
  151. /* Initialize every block in each instance */
  152. for (block = 0; block < nr_blocks; block++) {
  153. blk = &blk_p[block];
  154. blk->instance = inst;
  155. snprintf(blk->name, sizeof(blk->name),
  156. "%s%d", edac_block_name, block+offset_value);
  157. edac_dbg(4, "instance=%d inst_p=%p block=#%d block_p=%p name='%s'\n",
  158. instance, inst, block, blk, blk->name);
  159. /* if there are NO attributes OR no attribute pointer
  160. * then continue on to next block iteration
  161. */
  162. if ((nr_attrib == 0) || (attrib_spec == NULL))
  163. continue;
  164. /* setup the attribute array for this block */
  165. blk->nr_attribs = nr_attrib;
  166. attrib_p = &dev_attrib[block*nr_instances*nr_attrib];
  167. blk->block_attributes = attrib_p;
  168. edac_dbg(4, "THIS BLOCK_ATTRIB=%p\n",
  169. blk->block_attributes);
  170. /* Initialize every user specified attribute in this
  171. * block with the data the caller passed in
  172. * Each block gets its own copy of pointers,
  173. * and its unique 'value'
  174. */
  175. for (attr = 0; attr < nr_attrib; attr++) {
  176. attrib = &attrib_p[attr];
  177. /* populate the unique per attrib
  178. * with the code pointers and info
  179. */
  180. attrib->attr = attrib_spec[attr].attr;
  181. attrib->show = attrib_spec[attr].show;
  182. attrib->store = attrib_spec[attr].store;
  183. attrib->block = blk; /* up link */
  184. edac_dbg(4, "alloc-attrib=%p attrib_name='%s' attrib-spec=%p spec-name=%s\n",
  185. attrib, attrib->attr.name,
  186. &attrib_spec[attr],
  187. attrib_spec[attr].attr.name
  188. );
  189. }
  190. }
  191. }
  192. /* Mark this instance as merely ALLOCATED */
  193. dev_ctl->op_state = OP_ALLOC;
  194. /*
  195. * Initialize the 'root' kobj for the edac_device controller
  196. */
  197. err = edac_device_register_sysfs_main_kobj(dev_ctl);
  198. if (err) {
  199. kfree(dev_ctl);
  200. return NULL;
  201. }
  202. /* at this point, the root kobj is valid, and in order to
  203. * 'free' the object, then the function:
  204. * edac_device_unregister_sysfs_main_kobj() must be called
  205. * which will perform kobj unregistration and the actual free
  206. * will occur during the kobject callback operation
  207. */
  208. return dev_ctl;
  209. }
  210. EXPORT_SYMBOL_GPL(edac_device_alloc_ctl_info);
  211. /*
  212. * edac_device_free_ctl_info()
  213. * frees the memory allocated by the edac_device_alloc_ctl_info()
  214. * function
  215. */
  216. void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info)
  217. {
  218. edac_device_unregister_sysfs_main_kobj(ctl_info);
  219. }
  220. EXPORT_SYMBOL_GPL(edac_device_free_ctl_info);
  221. /*
  222. * find_edac_device_by_dev
  223. * scans the edac_device list for a specific 'struct device *'
  224. *
  225. * lock to be held prior to call: device_ctls_mutex
  226. *
  227. * Return:
  228. * pointer to control structure managing 'dev'
  229. * NULL if not found on list
  230. */
  231. static struct edac_device_ctl_info *find_edac_device_by_dev(struct device *dev)
  232. {
  233. struct edac_device_ctl_info *edac_dev;
  234. struct list_head *item;
  235. edac_dbg(0, "\n");
  236. list_for_each(item, &edac_device_list) {
  237. edac_dev = list_entry(item, struct edac_device_ctl_info, link);
  238. if (edac_dev->dev == dev)
  239. return edac_dev;
  240. }
  241. return NULL;
  242. }
  243. /*
  244. * add_edac_dev_to_global_list
  245. * Before calling this function, caller must
  246. * assign a unique value to edac_dev->dev_idx.
  247. *
  248. * lock to be held prior to call: device_ctls_mutex
  249. *
  250. * Return:
  251. * 0 on success
  252. * 1 on failure.
  253. */
  254. static int add_edac_dev_to_global_list(struct edac_device_ctl_info *edac_dev)
  255. {
  256. struct list_head *item, *insert_before;
  257. struct edac_device_ctl_info *rover;
  258. insert_before = &edac_device_list;
  259. /* Determine if already on the list */
  260. rover = find_edac_device_by_dev(edac_dev->dev);
  261. if (unlikely(rover != NULL))
  262. goto fail0;
  263. /* Insert in ascending order by 'dev_idx', so find position */
  264. list_for_each(item, &edac_device_list) {
  265. rover = list_entry(item, struct edac_device_ctl_info, link);
  266. if (rover->dev_idx >= edac_dev->dev_idx) {
  267. if (unlikely(rover->dev_idx == edac_dev->dev_idx))
  268. goto fail1;
  269. insert_before = item;
  270. break;
  271. }
  272. }
  273. list_add_tail_rcu(&edac_dev->link, insert_before);
  274. return 0;
  275. fail0:
  276. edac_printk(KERN_WARNING, EDAC_MC,
  277. "%s (%s) %s %s already assigned %d\n",
  278. dev_name(rover->dev), edac_dev_name(rover),
  279. rover->mod_name, rover->ctl_name, rover->dev_idx);
  280. return 1;
  281. fail1:
  282. edac_printk(KERN_WARNING, EDAC_MC,
  283. "bug in low-level driver: attempt to assign\n"
  284. " duplicate dev_idx %d in %s()\n", rover->dev_idx,
  285. __func__);
  286. return 1;
  287. }
  288. /*
  289. * del_edac_device_from_global_list
  290. */
  291. static void del_edac_device_from_global_list(struct edac_device_ctl_info
  292. *edac_device)
  293. {
  294. list_del_rcu(&edac_device->link);
  295. /* these are for safe removal of devices from global list while
  296. * NMI handlers may be traversing list
  297. */
  298. synchronize_rcu();
  299. INIT_LIST_HEAD(&edac_device->link);
  300. }
  301. /*
  302. * edac_device_workq_function
  303. * performs the operation scheduled by a workq request
  304. *
  305. * this workq is embedded within an edac_device_ctl_info
  306. * structure, that needs to be polled for possible error events.
  307. *
  308. * This operation is to acquire the list mutex lock
  309. * (thus preventing insertation or deletion)
  310. * and then call the device's poll function IFF this device is
  311. * running polled and there is a poll function defined.
  312. */
  313. static void edac_device_workq_function(struct work_struct *work_req)
  314. {
  315. struct delayed_work *d_work = to_delayed_work(work_req);
  316. struct edac_device_ctl_info *edac_dev = to_edac_device_ctl_work(d_work);
  317. mutex_lock(&device_ctls_mutex);
  318. /* If we are being removed, bail out immediately */
  319. if (edac_dev->op_state == OP_OFFLINE) {
  320. mutex_unlock(&device_ctls_mutex);
  321. return;
  322. }
  323. /* Only poll controllers that are running polled and have a check */
  324. if ((edac_dev->op_state == OP_RUNNING_POLL) &&
  325. (edac_dev->edac_check != NULL)) {
  326. edac_dev->edac_check(edac_dev);
  327. }
  328. mutex_unlock(&device_ctls_mutex);
  329. /* Reschedule the workq for the next time period to start again
  330. * if the number of msec is for 1 sec, then adjust to the next
  331. * whole one second to save timers firing all over the period
  332. * between integral seconds
  333. */
  334. if (edac_dev->poll_msec == 1000)
  335. edac_queue_work(&edac_dev->work, round_jiffies_relative(edac_dev->delay));
  336. else
  337. edac_queue_work(&edac_dev->work, edac_dev->delay);
  338. }
  339. /*
  340. * edac_device_workq_setup
  341. * initialize a workq item for this edac_device instance
  342. * passing in the new delay period in msec
  343. */
  344. static void edac_device_workq_setup(struct edac_device_ctl_info *edac_dev,
  345. unsigned msec)
  346. {
  347. edac_dbg(0, "\n");
  348. /* take the arg 'msec' and set it into the control structure
  349. * to used in the time period calculation
  350. * then calc the number of jiffies that represents
  351. */
  352. edac_dev->poll_msec = msec;
  353. edac_dev->delay = msecs_to_jiffies(msec);
  354. INIT_DELAYED_WORK(&edac_dev->work, edac_device_workq_function);
  355. /* optimize here for the 1 second case, which will be normal value, to
  356. * fire ON the 1 second time event. This helps reduce all sorts of
  357. * timers firing on sub-second basis, while they are happy
  358. * to fire together on the 1 second exactly
  359. */
  360. if (edac_dev->poll_msec == 1000)
  361. edac_queue_work(&edac_dev->work, round_jiffies_relative(edac_dev->delay));
  362. else
  363. edac_queue_work(&edac_dev->work, edac_dev->delay);
  364. }
  365. /*
  366. * edac_device_workq_teardown
  367. * stop the workq processing on this edac_dev
  368. */
  369. static void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev)
  370. {
  371. if (!edac_dev->edac_check)
  372. return;
  373. edac_dev->op_state = OP_OFFLINE;
  374. edac_stop_work(&edac_dev->work);
  375. }
  376. /*
  377. * edac_device_reset_delay_period
  378. *
  379. * need to stop any outstanding workq queued up at this time
  380. * because we will be resetting the sleep time.
  381. * Then restart the workq on the new delay
  382. */
  383. void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
  384. unsigned long value)
  385. {
  386. unsigned long jiffs = msecs_to_jiffies(value);
  387. if (value == 1000)
  388. jiffs = round_jiffies_relative(value);
  389. edac_dev->poll_msec = value;
  390. edac_dev->delay = jiffs;
  391. edac_mod_work(&edac_dev->work, jiffs);
  392. }
  393. /*
  394. * edac_device_alloc_index: Allocate a unique device index number
  395. *
  396. * Return:
  397. * allocated index number
  398. */
  399. int edac_device_alloc_index(void)
  400. {
  401. static atomic_t device_indexes = ATOMIC_INIT(0);
  402. return atomic_inc_return(&device_indexes) - 1;
  403. }
  404. EXPORT_SYMBOL_GPL(edac_device_alloc_index);
  405. /**
  406. * edac_device_add_device: Insert the 'edac_dev' structure into the
  407. * edac_device global list and create sysfs entries associated with
  408. * edac_device structure.
  409. * @edac_device: pointer to the edac_device structure to be added to the list
  410. * 'edac_device' structure.
  411. *
  412. * Return:
  413. * 0 Success
  414. * !0 Failure
  415. */
  416. int edac_device_add_device(struct edac_device_ctl_info *edac_dev)
  417. {
  418. edac_dbg(0, "\n");
  419. #ifdef CONFIG_EDAC_DEBUG
  420. if (edac_debug_level >= 3)
  421. edac_device_dump_device(edac_dev);
  422. #endif
  423. mutex_lock(&device_ctls_mutex);
  424. if (add_edac_dev_to_global_list(edac_dev))
  425. goto fail0;
  426. /* set load time so that error rate can be tracked */
  427. edac_dev->start_time = jiffies;
  428. /* create this instance's sysfs entries */
  429. if (edac_device_create_sysfs(edac_dev)) {
  430. edac_device_printk(edac_dev, KERN_WARNING,
  431. "failed to create sysfs device\n");
  432. goto fail1;
  433. }
  434. /* If there IS a check routine, then we are running POLLED */
  435. if (edac_dev->edac_check != NULL) {
  436. /* This instance is NOW RUNNING */
  437. edac_dev->op_state = OP_RUNNING_POLL;
  438. /*
  439. * enable workq processing on this instance,
  440. * default = 1000 msec
  441. */
  442. edac_device_workq_setup(edac_dev, 1000);
  443. } else {
  444. edac_dev->op_state = OP_RUNNING_INTERRUPT;
  445. }
  446. /* Report action taken */
  447. edac_device_printk(edac_dev, KERN_INFO,
  448. "Giving out device to module %s controller %s: DEV %s (%s)\n",
  449. edac_dev->mod_name, edac_dev->ctl_name, edac_dev->dev_name,
  450. edac_op_state_to_string(edac_dev->op_state));
  451. mutex_unlock(&device_ctls_mutex);
  452. return 0;
  453. fail1:
  454. /* Some error, so remove the entry from the lsit */
  455. del_edac_device_from_global_list(edac_dev);
  456. fail0:
  457. mutex_unlock(&device_ctls_mutex);
  458. return 1;
  459. }
  460. EXPORT_SYMBOL_GPL(edac_device_add_device);
  461. /**
  462. * edac_device_del_device:
  463. * Remove sysfs entries for specified edac_device structure and
  464. * then remove edac_device structure from global list
  465. *
  466. * @dev:
  467. * Pointer to 'struct device' representing edac_device
  468. * structure to remove.
  469. *
  470. * Return:
  471. * Pointer to removed edac_device structure,
  472. * OR NULL if device not found.
  473. */
  474. struct edac_device_ctl_info *edac_device_del_device(struct device *dev)
  475. {
  476. struct edac_device_ctl_info *edac_dev;
  477. edac_dbg(0, "\n");
  478. mutex_lock(&device_ctls_mutex);
  479. /* Find the structure on the list, if not there, then leave */
  480. edac_dev = find_edac_device_by_dev(dev);
  481. if (edac_dev == NULL) {
  482. mutex_unlock(&device_ctls_mutex);
  483. return NULL;
  484. }
  485. /* mark this instance as OFFLINE */
  486. edac_dev->op_state = OP_OFFLINE;
  487. /* deregister from global list */
  488. del_edac_device_from_global_list(edac_dev);
  489. mutex_unlock(&device_ctls_mutex);
  490. /* clear workq processing on this instance */
  491. edac_device_workq_teardown(edac_dev);
  492. /* Tear down the sysfs entries for this instance */
  493. edac_device_remove_sysfs(edac_dev);
  494. edac_printk(KERN_INFO, EDAC_MC,
  495. "Removed device %d for %s %s: DEV %s\n",
  496. edac_dev->dev_idx,
  497. edac_dev->mod_name, edac_dev->ctl_name, edac_dev_name(edac_dev));
  498. return edac_dev;
  499. }
  500. EXPORT_SYMBOL_GPL(edac_device_del_device);
  501. static inline int edac_device_get_log_ce(struct edac_device_ctl_info *edac_dev)
  502. {
  503. return edac_dev->log_ce;
  504. }
  505. static inline int edac_device_get_log_ue(struct edac_device_ctl_info *edac_dev)
  506. {
  507. return edac_dev->log_ue;
  508. }
  509. static inline int edac_device_get_panic_on_ue(struct edac_device_ctl_info
  510. *edac_dev)
  511. {
  512. return edac_dev->panic_on_ue;
  513. }
  514. /*
  515. * edac_device_handle_ce
  516. * perform a common output and handling of an 'edac_dev' CE event
  517. */
  518. void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev,
  519. int inst_nr, int block_nr, const char *msg)
  520. {
  521. struct edac_device_instance *instance;
  522. struct edac_device_block *block = NULL;
  523. if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) {
  524. edac_device_printk(edac_dev, KERN_ERR,
  525. "INTERNAL ERROR: 'instance' out of range "
  526. "(%d >= %d)\n", inst_nr,
  527. edac_dev->nr_instances);
  528. return;
  529. }
  530. instance = edac_dev->instances + inst_nr;
  531. if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) {
  532. edac_device_printk(edac_dev, KERN_ERR,
  533. "INTERNAL ERROR: instance %d 'block' "
  534. "out of range (%d >= %d)\n",
  535. inst_nr, block_nr,
  536. instance->nr_blocks);
  537. return;
  538. }
  539. if (instance->nr_blocks > 0) {
  540. block = instance->blocks + block_nr;
  541. block->counters.ce_count++;
  542. }
  543. /* Propagate the count up the 'totals' tree */
  544. instance->counters.ce_count++;
  545. edac_dev->counters.ce_count++;
  546. if (edac_device_get_log_ce(edac_dev))
  547. edac_device_printk(edac_dev, KERN_WARNING,
  548. "CE: %s instance: %s block: %s '%s'\n",
  549. edac_dev->ctl_name, instance->name,
  550. block ? block->name : "N/A", msg);
  551. }
  552. EXPORT_SYMBOL_GPL(edac_device_handle_ce);
  553. /*
  554. * edac_device_handle_ue
  555. * perform a common output and handling of an 'edac_dev' UE event
  556. */
  557. void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev,
  558. int inst_nr, int block_nr, const char *msg)
  559. {
  560. struct edac_device_instance *instance;
  561. struct edac_device_block *block = NULL;
  562. if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) {
  563. edac_device_printk(edac_dev, KERN_ERR,
  564. "INTERNAL ERROR: 'instance' out of range "
  565. "(%d >= %d)\n", inst_nr,
  566. edac_dev->nr_instances);
  567. return;
  568. }
  569. instance = edac_dev->instances + inst_nr;
  570. if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) {
  571. edac_device_printk(edac_dev, KERN_ERR,
  572. "INTERNAL ERROR: instance %d 'block' "
  573. "out of range (%d >= %d)\n",
  574. inst_nr, block_nr,
  575. instance->nr_blocks);
  576. return;
  577. }
  578. if (instance->nr_blocks > 0) {
  579. block = instance->blocks + block_nr;
  580. block->counters.ue_count++;
  581. }
  582. /* Propagate the count up the 'totals' tree */
  583. instance->counters.ue_count++;
  584. edac_dev->counters.ue_count++;
  585. if (edac_device_get_log_ue(edac_dev))
  586. edac_device_printk(edac_dev, KERN_EMERG,
  587. "UE: %s instance: %s block: %s '%s'\n",
  588. edac_dev->ctl_name, instance->name,
  589. block ? block->name : "N/A", msg);
  590. if (edac_device_get_panic_on_ue(edac_dev))
  591. panic("EDAC %s: UE instance: %s block %s '%s'\n",
  592. edac_dev->ctl_name, instance->name,
  593. block ? block->name : "N/A", msg);
  594. }
  595. EXPORT_SYMBOL_GPL(edac_device_handle_ue);