edac_device.c 21 KB

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