edac_device.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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. debugf3("\tedac_dev = %p dev_idx=%d \n", edac_dev, edac_dev->dev_idx);
  39. debugf4("\tedac_dev->edac_check = %p\n", edac_dev->edac_check);
  40. debugf3("\tdev = %p\n", edac_dev->dev);
  41. debugf3("\tmod_name:ctl_name = %s:%s\n",
  42. edac_dev->mod_name, edac_dev->ctl_name);
  43. debugf3("\tpvt_info = %p\n\n", edac_dev->pvt_info);
  44. }
  45. #endif /* CONFIG_EDAC_DEBUG */
  46. /*
  47. * edac_device_alloc_ctl_info()
  48. * Allocate a new edac device control info structure
  49. *
  50. * The control structure is allocated in complete chunk
  51. * from the OS. It is in turn sub allocated to the
  52. * various objects that compose the structure
  53. *
  54. * The structure has a 'nr_instance' array within itself.
  55. * Each instance represents a major component
  56. * Example: L1 cache and L2 cache are 2 instance components
  57. *
  58. * Within each instance is an array of 'nr_blocks' blockoffsets
  59. */
  60. struct edac_device_ctl_info *edac_device_alloc_ctl_info(
  61. unsigned sz_private,
  62. char *edac_device_name, unsigned nr_instances,
  63. char *edac_block_name, unsigned nr_blocks,
  64. unsigned offset_value, /* zero, 1, or other based offset */
  65. struct edac_dev_sysfs_block_attribute *attrib_spec, unsigned nr_attrib,
  66. int device_index)
  67. {
  68. struct edac_device_ctl_info *dev_ctl;
  69. struct edac_device_instance *dev_inst, *inst;
  70. struct edac_device_block *dev_blk, *blk_p, *blk;
  71. struct edac_dev_sysfs_block_attribute *dev_attrib, *attrib_p, *attrib;
  72. unsigned total_size;
  73. unsigned count;
  74. unsigned instance, block, attr;
  75. void *pvt, *p;
  76. int err;
  77. debugf4("%s() instances=%d blocks=%d\n",
  78. __func__, 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. debugf4("%s() edac_dev=%p next after end=%p\n",
  140. __func__, 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. debugf4("%s() instance=%d inst_p=%p block=#%d "
  158. "block_p=%p name='%s'\n",
  159. __func__, instance, inst, block,
  160. blk, blk->name);
  161. /* if there are NO attributes OR no attribute pointer
  162. * then continue on to next block iteration
  163. */
  164. if ((nr_attrib == 0) || (attrib_spec == NULL))
  165. continue;
  166. /* setup the attribute array for this block */
  167. blk->nr_attribs = nr_attrib;
  168. attrib_p = &dev_attrib[block*nr_instances*nr_attrib];
  169. blk->block_attributes = attrib_p;
  170. debugf4("%s() THIS BLOCK_ATTRIB=%p\n",
  171. __func__, blk->block_attributes);
  172. /* Initialize every user specified attribute in this
  173. * block with the data the caller passed in
  174. * Each block gets its own copy of pointers,
  175. * and its unique 'value'
  176. */
  177. for (attr = 0; attr < nr_attrib; attr++) {
  178. attrib = &attrib_p[attr];
  179. /* populate the unique per attrib
  180. * with the code pointers and info
  181. */
  182. attrib->attr = attrib_spec[attr].attr;
  183. attrib->show = attrib_spec[attr].show;
  184. attrib->store = attrib_spec[attr].store;
  185. attrib->block = blk; /* up link */
  186. debugf4("%s() alloc-attrib=%p attrib_name='%s' "
  187. "attrib-spec=%p spec-name=%s\n",
  188. __func__, attrib, attrib->attr.name,
  189. &attrib_spec[attr],
  190. attrib_spec[attr].attr.name
  191. );
  192. }
  193. }
  194. }
  195. /* Mark this instance as merely ALLOCATED */
  196. dev_ctl->op_state = OP_ALLOC;
  197. /*
  198. * Initialize the 'root' kobj for the edac_device controller
  199. */
  200. err = edac_device_register_sysfs_main_kobj(dev_ctl);
  201. if (err) {
  202. kfree(dev_ctl);
  203. return NULL;
  204. }
  205. /* at this point, the root kobj is valid, and in order to
  206. * 'free' the object, then the function:
  207. * edac_device_unregister_sysfs_main_kobj() must be called
  208. * which will perform kobj unregistration and the actual free
  209. * will occur during the kobject callback operation
  210. */
  211. return dev_ctl;
  212. }
  213. EXPORT_SYMBOL_GPL(edac_device_alloc_ctl_info);
  214. /*
  215. * edac_device_free_ctl_info()
  216. * frees the memory allocated by the edac_device_alloc_ctl_info()
  217. * function
  218. */
  219. void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info)
  220. {
  221. edac_device_unregister_sysfs_main_kobj(ctl_info);
  222. }
  223. EXPORT_SYMBOL_GPL(edac_device_free_ctl_info);
  224. /*
  225. * find_edac_device_by_dev
  226. * scans the edac_device list for a specific 'struct device *'
  227. *
  228. * lock to be held prior to call: device_ctls_mutex
  229. *
  230. * Return:
  231. * pointer to control structure managing 'dev'
  232. * NULL if not found on list
  233. */
  234. static struct edac_device_ctl_info *find_edac_device_by_dev(struct device *dev)
  235. {
  236. struct edac_device_ctl_info *edac_dev;
  237. struct list_head *item;
  238. debugf0("%s()\n", __func__);
  239. list_for_each(item, &edac_device_list) {
  240. edac_dev = list_entry(item, struct edac_device_ctl_info, link);
  241. if (edac_dev->dev == dev)
  242. return edac_dev;
  243. }
  244. return NULL;
  245. }
  246. /*
  247. * add_edac_dev_to_global_list
  248. * Before calling this function, caller must
  249. * assign a unique value to edac_dev->dev_idx.
  250. *
  251. * lock to be held prior to call: device_ctls_mutex
  252. *
  253. * Return:
  254. * 0 on success
  255. * 1 on failure.
  256. */
  257. static int add_edac_dev_to_global_list(struct edac_device_ctl_info *edac_dev)
  258. {
  259. struct list_head *item, *insert_before;
  260. struct edac_device_ctl_info *rover;
  261. insert_before = &edac_device_list;
  262. /* Determine if already on the list */
  263. rover = find_edac_device_by_dev(edac_dev->dev);
  264. if (unlikely(rover != NULL))
  265. goto fail0;
  266. /* Insert in ascending order by 'dev_idx', so find position */
  267. list_for_each(item, &edac_device_list) {
  268. rover = list_entry(item, struct edac_device_ctl_info, link);
  269. if (rover->dev_idx >= edac_dev->dev_idx) {
  270. if (unlikely(rover->dev_idx == edac_dev->dev_idx))
  271. goto fail1;
  272. insert_before = item;
  273. break;
  274. }
  275. }
  276. list_add_tail_rcu(&edac_dev->link, insert_before);
  277. return 0;
  278. fail0:
  279. edac_printk(KERN_WARNING, EDAC_MC,
  280. "%s (%s) %s %s already assigned %d\n",
  281. dev_name(rover->dev), edac_dev_name(rover),
  282. rover->mod_name, rover->ctl_name, rover->dev_idx);
  283. return 1;
  284. fail1:
  285. edac_printk(KERN_WARNING, EDAC_MC,
  286. "bug in low-level driver: attempt to assign\n"
  287. " duplicate dev_idx %d in %s()\n", rover->dev_idx,
  288. __func__);
  289. return 1;
  290. }
  291. /*
  292. * del_edac_device_from_global_list
  293. */
  294. static void del_edac_device_from_global_list(struct edac_device_ctl_info
  295. *edac_device)
  296. {
  297. list_del_rcu(&edac_device->link);
  298. /* these are for safe removal of devices from global list while
  299. * NMI handlers may be traversing list
  300. */
  301. synchronize_rcu();
  302. INIT_LIST_HEAD(&edac_device->link);
  303. }
  304. /*
  305. * edac_device_workq_function
  306. * performs the operation scheduled by a workq request
  307. *
  308. * this workq is embedded within an edac_device_ctl_info
  309. * structure, that needs to be polled for possible error events.
  310. *
  311. * This operation is to acquire the list mutex lock
  312. * (thus preventing insertation or deletion)
  313. * and then call the device's poll function IFF this device is
  314. * running polled and there is a poll function defined.
  315. */
  316. static void edac_device_workq_function(struct work_struct *work_req)
  317. {
  318. struct delayed_work *d_work = to_delayed_work(work_req);
  319. struct edac_device_ctl_info *edac_dev = to_edac_device_ctl_work(d_work);
  320. mutex_lock(&device_ctls_mutex);
  321. /* If we are being removed, bail out immediately */
  322. if (edac_dev->op_state == OP_OFFLINE) {
  323. mutex_unlock(&device_ctls_mutex);
  324. return;
  325. }
  326. /* Only poll controllers that are running polled and have a check */
  327. if ((edac_dev->op_state == OP_RUNNING_POLL) &&
  328. (edac_dev->edac_check != NULL)) {
  329. edac_dev->edac_check(edac_dev);
  330. }
  331. mutex_unlock(&device_ctls_mutex);
  332. /* Reschedule the workq for the next time period to start again
  333. * if the number of msec is for 1 sec, then adjust to the next
  334. * whole one second to save timers firing all over the period
  335. * between integral seconds
  336. */
  337. if (edac_dev->poll_msec == 1000)
  338. queue_delayed_work(edac_workqueue, &edac_dev->work,
  339. round_jiffies_relative(edac_dev->delay));
  340. else
  341. queue_delayed_work(edac_workqueue, &edac_dev->work,
  342. edac_dev->delay);
  343. }
  344. /*
  345. * edac_device_workq_setup
  346. * initialize a workq item for this edac_device instance
  347. * passing in the new delay period in msec
  348. */
  349. void edac_device_workq_setup(struct edac_device_ctl_info *edac_dev,
  350. unsigned msec)
  351. {
  352. debugf0("%s()\n", __func__);
  353. /* take the arg 'msec' and set it into the control structure
  354. * to used in the time period calculation
  355. * then calc the number of jiffies that represents
  356. */
  357. edac_dev->poll_msec = msec;
  358. edac_dev->delay = msecs_to_jiffies(msec);
  359. INIT_DELAYED_WORK(&edac_dev->work, edac_device_workq_function);
  360. /* optimize here for the 1 second case, which will be normal value, to
  361. * fire ON the 1 second time event. This helps reduce all sorts of
  362. * timers firing on sub-second basis, while they are happy
  363. * to fire together on the 1 second exactly
  364. */
  365. if (edac_dev->poll_msec == 1000)
  366. queue_delayed_work(edac_workqueue, &edac_dev->work,
  367. round_jiffies_relative(edac_dev->delay));
  368. else
  369. queue_delayed_work(edac_workqueue, &edac_dev->work,
  370. edac_dev->delay);
  371. }
  372. /*
  373. * edac_device_workq_teardown
  374. * stop the workq processing on this edac_dev
  375. */
  376. void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev)
  377. {
  378. int status;
  379. status = cancel_delayed_work(&edac_dev->work);
  380. if (status == 0) {
  381. /* workq instance might be running, wait for it */
  382. flush_workqueue(edac_workqueue);
  383. }
  384. }
  385. /*
  386. * edac_device_reset_delay_period
  387. *
  388. * need to stop any outstanding workq queued up at this time
  389. * because we will be resetting the sleep time.
  390. * Then restart the workq on the new delay
  391. */
  392. void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
  393. unsigned long value)
  394. {
  395. /* cancel the current workq request, without the mutex lock */
  396. edac_device_workq_teardown(edac_dev);
  397. /* acquire the mutex before doing the workq setup */
  398. mutex_lock(&device_ctls_mutex);
  399. /* restart the workq request, with new delay value */
  400. edac_device_workq_setup(edac_dev, value);
  401. mutex_unlock(&device_ctls_mutex);
  402. }
  403. /*
  404. * edac_device_alloc_index: Allocate a unique device index number
  405. *
  406. * Return:
  407. * allocated index number
  408. */
  409. int edac_device_alloc_index(void)
  410. {
  411. static atomic_t device_indexes = ATOMIC_INIT(0);
  412. return atomic_inc_return(&device_indexes) - 1;
  413. }
  414. EXPORT_SYMBOL_GPL(edac_device_alloc_index);
  415. /**
  416. * edac_device_add_device: Insert the 'edac_dev' structure into the
  417. * edac_device global list and create sysfs entries associated with
  418. * edac_device structure.
  419. * @edac_device: pointer to the edac_device structure to be added to the list
  420. * 'edac_device' structure.
  421. *
  422. * Return:
  423. * 0 Success
  424. * !0 Failure
  425. */
  426. int edac_device_add_device(struct edac_device_ctl_info *edac_dev)
  427. {
  428. debugf0("%s()\n", __func__);
  429. #ifdef CONFIG_EDAC_DEBUG
  430. if (edac_debug_level >= 3)
  431. edac_device_dump_device(edac_dev);
  432. #endif
  433. mutex_lock(&device_ctls_mutex);
  434. if (add_edac_dev_to_global_list(edac_dev))
  435. goto fail0;
  436. /* set load time so that error rate can be tracked */
  437. edac_dev->start_time = jiffies;
  438. /* create this instance's sysfs entries */
  439. if (edac_device_create_sysfs(edac_dev)) {
  440. edac_device_printk(edac_dev, KERN_WARNING,
  441. "failed to create sysfs device\n");
  442. goto fail1;
  443. }
  444. /* If there IS a check routine, then we are running POLLED */
  445. if (edac_dev->edac_check != NULL) {
  446. /* This instance is NOW RUNNING */
  447. edac_dev->op_state = OP_RUNNING_POLL;
  448. /*
  449. * enable workq processing on this instance,
  450. * default = 1000 msec
  451. */
  452. edac_device_workq_setup(edac_dev, 1000);
  453. } else {
  454. edac_dev->op_state = OP_RUNNING_INTERRUPT;
  455. }
  456. /* Report action taken */
  457. edac_device_printk(edac_dev, KERN_INFO,
  458. "Giving out device to module '%s' controller "
  459. "'%s': DEV '%s' (%s)\n",
  460. edac_dev->mod_name,
  461. edac_dev->ctl_name,
  462. edac_dev_name(edac_dev),
  463. edac_op_state_to_string(edac_dev->op_state));
  464. mutex_unlock(&device_ctls_mutex);
  465. return 0;
  466. fail1:
  467. /* Some error, so remove the entry from the lsit */
  468. del_edac_device_from_global_list(edac_dev);
  469. fail0:
  470. mutex_unlock(&device_ctls_mutex);
  471. return 1;
  472. }
  473. EXPORT_SYMBOL_GPL(edac_device_add_device);
  474. /**
  475. * edac_device_del_device:
  476. * Remove sysfs entries for specified edac_device structure and
  477. * then remove edac_device structure from global list
  478. *
  479. * @dev:
  480. * Pointer to 'struct device' representing edac_device
  481. * structure to remove.
  482. *
  483. * Return:
  484. * Pointer to removed edac_device structure,
  485. * OR NULL if device not found.
  486. */
  487. struct edac_device_ctl_info *edac_device_del_device(struct device *dev)
  488. {
  489. struct edac_device_ctl_info *edac_dev;
  490. debugf0("%s()\n", __func__);
  491. mutex_lock(&device_ctls_mutex);
  492. /* Find the structure on the list, if not there, then leave */
  493. edac_dev = find_edac_device_by_dev(dev);
  494. if (edac_dev == NULL) {
  495. mutex_unlock(&device_ctls_mutex);
  496. return NULL;
  497. }
  498. /* mark this instance as OFFLINE */
  499. edac_dev->op_state = OP_OFFLINE;
  500. /* deregister from global list */
  501. del_edac_device_from_global_list(edac_dev);
  502. mutex_unlock(&device_ctls_mutex);
  503. /* clear workq processing on this instance */
  504. edac_device_workq_teardown(edac_dev);
  505. /* Tear down the sysfs entries for this instance */
  506. edac_device_remove_sysfs(edac_dev);
  507. edac_printk(KERN_INFO, EDAC_MC,
  508. "Removed device %d for %s %s: DEV %s\n",
  509. edac_dev->dev_idx,
  510. edac_dev->mod_name, edac_dev->ctl_name, edac_dev_name(edac_dev));
  511. return edac_dev;
  512. }
  513. EXPORT_SYMBOL_GPL(edac_device_del_device);
  514. static inline int edac_device_get_log_ce(struct edac_device_ctl_info *edac_dev)
  515. {
  516. return edac_dev->log_ce;
  517. }
  518. static inline int edac_device_get_log_ue(struct edac_device_ctl_info *edac_dev)
  519. {
  520. return edac_dev->log_ue;
  521. }
  522. static inline int edac_device_get_panic_on_ue(struct edac_device_ctl_info
  523. *edac_dev)
  524. {
  525. return edac_dev->panic_on_ue;
  526. }
  527. /*
  528. * edac_device_handle_ce
  529. * perform a common output and handling of an 'edac_dev' CE event
  530. */
  531. void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev,
  532. int inst_nr, int block_nr, const char *msg)
  533. {
  534. struct edac_device_instance *instance;
  535. struct edac_device_block *block = NULL;
  536. if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) {
  537. edac_device_printk(edac_dev, KERN_ERR,
  538. "INTERNAL ERROR: 'instance' out of range "
  539. "(%d >= %d)\n", inst_nr,
  540. edac_dev->nr_instances);
  541. return;
  542. }
  543. instance = edac_dev->instances + inst_nr;
  544. if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) {
  545. edac_device_printk(edac_dev, KERN_ERR,
  546. "INTERNAL ERROR: instance %d 'block' "
  547. "out of range (%d >= %d)\n",
  548. inst_nr, block_nr,
  549. instance->nr_blocks);
  550. return;
  551. }
  552. if (instance->nr_blocks > 0) {
  553. block = instance->blocks + block_nr;
  554. block->counters.ce_count++;
  555. }
  556. /* Propagate the count up the 'totals' tree */
  557. instance->counters.ce_count++;
  558. edac_dev->counters.ce_count++;
  559. if (edac_device_get_log_ce(edac_dev))
  560. edac_device_printk(edac_dev, KERN_WARNING,
  561. "CE: %s instance: %s block: %s '%s'\n",
  562. edac_dev->ctl_name, instance->name,
  563. block ? block->name : "N/A", msg);
  564. }
  565. EXPORT_SYMBOL_GPL(edac_device_handle_ce);
  566. /*
  567. * edac_device_handle_ue
  568. * perform a common output and handling of an 'edac_dev' UE event
  569. */
  570. void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev,
  571. int inst_nr, int block_nr, const char *msg)
  572. {
  573. struct edac_device_instance *instance;
  574. struct edac_device_block *block = NULL;
  575. if ((inst_nr >= edac_dev->nr_instances) || (inst_nr < 0)) {
  576. edac_device_printk(edac_dev, KERN_ERR,
  577. "INTERNAL ERROR: 'instance' out of range "
  578. "(%d >= %d)\n", inst_nr,
  579. edac_dev->nr_instances);
  580. return;
  581. }
  582. instance = edac_dev->instances + inst_nr;
  583. if ((block_nr >= instance->nr_blocks) || (block_nr < 0)) {
  584. edac_device_printk(edac_dev, KERN_ERR,
  585. "INTERNAL ERROR: instance %d 'block' "
  586. "out of range (%d >= %d)\n",
  587. inst_nr, block_nr,
  588. instance->nr_blocks);
  589. return;
  590. }
  591. if (instance->nr_blocks > 0) {
  592. block = instance->blocks + block_nr;
  593. block->counters.ue_count++;
  594. }
  595. /* Propagate the count up the 'totals' tree */
  596. instance->counters.ue_count++;
  597. edac_dev->counters.ue_count++;
  598. if (edac_device_get_log_ue(edac_dev))
  599. edac_device_printk(edac_dev, KERN_EMERG,
  600. "UE: %s instance: %s block: %s '%s'\n",
  601. edac_dev->ctl_name, instance->name,
  602. block ? block->name : "N/A", msg);
  603. if (edac_device_get_panic_on_ue(edac_dev))
  604. panic("EDAC %s: UE instance: %s block %s '%s'\n",
  605. edac_dev->ctl_name, instance->name,
  606. block ? block->name : "N/A", msg);
  607. }
  608. EXPORT_SYMBOL_GPL(edac_device_handle_ue);