summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/sparc/shared/scrub/memscrub.c
blob: 2e4dfeeb0cc1b21a110a1cfe58adaddfd59e23e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
/*  Memory Scrubber register driver
 *
 *  COPYRIGHT (c) 2017.
 *  Cobham Gaisler AB.
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <rtems/bspIo.h>
#include <drvmgr/drvmgr.h>
#include <drvmgr/ambapp_bus.h>

#include <bsp/memscrub.h>

/*#define STATIC*/
#define STATIC static

#define UNUSED __attribute__((unused))

/*#define DEBUG 1*/

#ifdef DEBUG
#define DBG(x...) printf(x)
#else
#define DBG(x...) 
#endif

#define REG_WRITE(addr, val) (*(volatile uint32_t *)(addr) = (uint32_t)(val))
#define REG_READ(addr) (*(volatile uint32_t *)(addr))

/* 
 * MEMORYSCRUBBER AHBS register fields
 * DEFINED IN HEADER FILE
 */

/* 
 * MEMORYSCRUBBER AHBERC register fields
 * DEFINED IN HEADER FILE
 */

/* 
 * MEMORYSCRUBBER STAT register fields
 * DEFINED IN HEADER FILE
 */

/* 
 * MEMORYSCRUBBER CONFIG register fields
 * DEFINED IN HEADER FILE
 */

/* 
 * MEMORYSCRUBBER ETHRES register fields
 * DEFINED IN HEADER FILE
 */

/* MEMORYSCRUBBER Registers layout */
struct memscrub_regs {
	volatile uint32_t ahbstatus; /* 0x00 */
	volatile uint32_t ahbfailing; /* 0x04 */
	volatile uint32_t ahberc; /* 0x08 */
	volatile uint32_t resv1; /* 0x0c */
	volatile uint32_t status; /* 0x10 */
	volatile uint32_t config; /* 0x14 */
	volatile uint32_t rangel; /* 0x18 */
	volatile uint32_t rangeh; /* 0x1c */
	volatile uint32_t pos; /* 0x20 */
	volatile uint32_t ethres; /* 0x24 */
	volatile uint32_t init; /* 0x28 */
	volatile uint32_t rangel2; /* 0x2c */
	volatile uint32_t rangeh2; /* 0x30 */
};

#define DEVNAME_LEN 10
struct memscrub_priv {
	struct drvmgr_dev *dev;
	char devname[DEVNAME_LEN];
	struct memscrub_regs *regs;
	int minor;
	int burstlen;
	int blockmask;
	/* Cached error */
	uint32_t last_status;
	uint32_t last_address;
	/* User defined ISR */
	memscrub_isr_t isr;
	void *isr_arg;
};
static struct memscrub_priv * memscrubpriv = NULL;

STATIC int memscrub_init2(struct drvmgr_dev *dev);
STATIC int memscrub_init(struct memscrub_priv *priv);

void memscrub_isr(void *arg);

struct drvmgr_drv_ops memscrub_ops =
{
	.init = {NULL, memscrub_init2, NULL, NULL},
	.remove = NULL,
	.info = NULL
};

struct amba_dev_id memscrub_ids[] =
{
	{VENDOR_GAISLER, GAISLER_MEMSCRUB},
	{0, 0}		/* Mark end of table */
};

struct amba_drv_info memscrub_drv_info =
{
	{
		DRVMGR_OBJ_DRV,			/* Driver */
		NULL,				/* Next driver */
		NULL,				/* Device list */
		DRIVER_AMBAPP_GAISLER_MEMSCRUB_ID,/* Driver ID */
		"MEMSCRUB_DRV",			/* Driver Name */
		DRVMGR_BUS_TYPE_AMBAPP,		/* Bus Type */
		&memscrub_ops,
		NULL,				/* Funcs */
		0,				/* No devices yet */
		sizeof(struct memscrub_priv),
	},
	&memscrub_ids[0]
};

void memscrub_register_drv (void)
{
	drvmgr_drv_register(&memscrub_drv_info.general);
}

STATIC int memscrub_init(struct memscrub_priv *priv)
{
	struct ambapp_ahb_info *ahb;
	struct amba_dev_info *ainfo = priv->dev->businfo;
	unsigned int tmp;
	int i,j;

	/* Get device information from AMBA PnP information */
	if (ainfo == NULL){
		return MEMSCRUB_ERR_ERROR;
	}

	/* Find MEMSCRUB core from Plug&Play information */
	ahb = ainfo->info.ahb_slv;
	priv->regs = (struct memscrub_regs *)ahb->start[0];

	DBG("MEMSCRUB regs 0x%08x\n", (unsigned int) priv->regs);

	/* Find MEMSCRUB capabilities */
	tmp = REG_READ(&priv->regs->status);
	i = (tmp & STAT_BURSTLEN) >> STAT_BURSTLEN_BIT;
	for (j=1; i>0; i--) j <<= 1;
	priv->burstlen = j;


	/* If scrubber is active, we cannot stop it to read blockmask value */
	if (tmp & STAT_ACTIVE){
		priv->blockmask = 0;
	}else{
		/* Detect block size in bytes and burst length */
		tmp = REG_READ(&priv->regs->rangeh);
		REG_WRITE(&priv->regs->rangeh, 0);
		priv->blockmask = REG_READ(&priv->regs->rangeh);
		REG_WRITE(&priv->regs->rangeh, tmp);
	}

	/* DEBUG print */
	DBG("MEMSCRUB with following capabilities:\n");
	DBG(" -Burstlength: %d\n", priv->burstlen); 

	return MEMSCRUB_ERR_OK;
}

STATIC int memscrub_init2(struct drvmgr_dev *dev)
{
	struct memscrub_priv *priv = dev->priv;

	DBG("MEMSCRUB[%d] on bus %s\n", dev->minor_drv, dev->parent->dev->name);

	if (memscrubpriv) {
		DBG("Driver only supports one MEMSCRUB core\n");
		return DRVMGR_FAIL;
	}

	if (priv==NULL){
		return DRVMGR_NOMEM;
	}

	/* Assign priv */
	priv->dev = dev;
	strncpy(&priv->devname[0], "memscrub0", DEVNAME_LEN);
	memscrubpriv=priv;

	/* Initilize driver struct */
	if (memscrub_init(priv) != MEMSCRUB_ERR_OK){
		return DRVMGR_FAIL;
	}

	/* Startup Action:
	 *	- Clear status
	 *	- Register ISR
	 */

	/* Initialize hardware by clearing its status */
	REG_WRITE(&priv->regs->ahbstatus, 0);
	REG_WRITE(&priv->regs->status, 0);

	return DRVMGR_OK;
}


int memscrub_init_start(uint32_t value, uint8_t delay, int options)
{
	struct memscrub_priv *priv = memscrubpriv;
	uint32_t sts, tmp;
	int i;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	/* Check if scrubber is active */
	sts = REG_READ(&priv->regs->status);
	if (sts & STAT_ACTIVE){
		DBG("MEMSCRUB running.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	/* Check if we need to probe blockmask */
	if (priv->blockmask == 0){
		/* Detect block size in bytes and burst length */
		tmp = REG_READ(&priv->regs->rangeh);
		REG_WRITE(&priv->regs->rangeh, 0);
		priv->blockmask = REG_READ(&priv->regs->rangeh);
		REG_WRITE(&priv->regs->rangeh, tmp);
	}

	/* Set data value */
	for (i=0; i<priv->blockmask; i+=4){
		REG_WRITE(&priv->regs->init,value);
	}

	/* Clear unused bits */
	options = options & ~(CONFIG_MODE | CONFIG_DELAY);

	/* Enable scrubber */
	REG_WRITE(&priv->regs->config, options | 
			((delay << CONFIG_DELAY_BIT) & CONFIG_DELAY) | 
			CONFIG_MODE_INIT | CONFIG_SCEN);

	DBG("MEMSCRUB INIT STARTED\n");

	return MEMSCRUB_ERR_OK;
}

int memscrub_scrub_start(uint8_t delay, int options)
{
	struct memscrub_priv *priv = memscrubpriv;
	uint32_t ctrl,sts;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	/* Check if scrubber is active */
	sts = REG_READ(&priv->regs->status);
	if (sts & STAT_ACTIVE){
		/* Check if mode is not init */
		ctrl = REG_READ(&priv->regs->config);
		if ((ctrl & CONFIG_MODE)==CONFIG_MODE_INIT){
			DBG("MEMSCRUB init running.\n");
			return MEMSCRUB_ERR_ERROR;
		}
	}

	/* Clear unused bits */
	options = options & ~(CONFIG_MODE | CONFIG_DELAY);

	/* Enable scrubber */
	REG_WRITE(&priv->regs->config, options | 
			((delay << CONFIG_DELAY_BIT) & CONFIG_DELAY) | 
			CONFIG_MODE_SCRUB | CONFIG_SCEN);

	DBG("MEMSCRUB SCRUB STARTED\n");

	return MEMSCRUB_ERR_OK;
}

int memscrub_regen_start(uint8_t delay, int options)
{
	struct memscrub_priv *priv = memscrubpriv;
	uint32_t ctrl,sts;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	/* Check if scrubber is active */
	sts = REG_READ(&priv->regs->status);
	if (sts & STAT_ACTIVE){
		/* Check if mode is not init */
		ctrl = REG_READ(&priv->regs->config);
		if ((ctrl & CONFIG_MODE)==CONFIG_MODE_INIT){
			DBG("MEMSCRUB init running.\n");
			return MEMSCRUB_ERR_ERROR;
		}
	}

	/* Clear unused bits */
	options = options & ~(CONFIG_MODE | CONFIG_DELAY);

	/* Enable scrubber */
	REG_WRITE(&priv->regs->config, options | 
			((delay << CONFIG_DELAY_BIT) & CONFIG_DELAY) | 
			CONFIG_MODE_REGEN | CONFIG_SCEN);

	DBG("MEMSCRUB REGEN STARTED\n");

	return MEMSCRUB_ERR_OK;
}

int memscrub_stop(void)
{
	struct memscrub_priv *priv = memscrubpriv;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	/* Disable scrubber */
	REG_WRITE(&priv->regs->config, 0);

	/* Wait until finished */
	while(REG_READ(&priv->regs->status) & STAT_ACTIVE){};

	DBG("MEMSCRUB STOPPED\n");

	return MEMSCRUB_ERR_OK;
}

int memscrub_range_set(uint32_t start, uint32_t end)
{
	struct memscrub_priv *priv = memscrubpriv;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	if (end <= start){
		DBG("MEMSCRUB wrong address.\n");
		return MEMSCRUB_ERR_EINVAL;
	}

	/* Check if scrubber is active */
	if (REG_READ(&priv->regs->status) & STAT_ACTIVE){
		DBG("MEMSCRUB running.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	/* Set range */
	REG_WRITE(&priv->regs->rangel, start);
	REG_WRITE(&priv->regs->rangeh, end);

	DBG("MEMSCRUB range: 0x%08x-0x%08x\n",
			(unsigned int) start,
			(unsigned int) end);

	return MEMSCRUB_ERR_OK;
}

int memscrub_secondary_range_set(uint32_t start, uint32_t end)
{
	struct memscrub_priv *priv = memscrubpriv;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	if (end <= start){
		DBG("MEMSCRUB wrong address.\n");
		return MEMSCRUB_ERR_EINVAL;
	}

	/* Check if scrubber is active */
	if (REG_READ(&priv->regs->status) & STAT_ACTIVE){
		DBG("MEMSCRUB running.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	/* Set range */
	REG_WRITE(&priv->regs->rangel2, start);
	REG_WRITE(&priv->regs->rangeh2, end);

	DBG("MEMSCRUB 2nd range: 0x%08x-0x%08x\n",
			(unsigned int) start,
			(unsigned int) end);

	return MEMSCRUB_ERR_OK;
}

int memscrub_range_get(uint32_t * start, uint32_t * end)
{
	struct memscrub_priv *priv = memscrubpriv;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	if ((start==NULL) || (end == NULL)){
		DBG("MEMSCRUB wrong pointer.\n");
		return MEMSCRUB_ERR_EINVAL;
	}

	/* Get range */
	*start = REG_READ(&priv->regs->rangel);
	*end = REG_READ(&priv->regs->rangeh);

	return MEMSCRUB_ERR_OK;
}

int memscrub_secondary_range_get(uint32_t * start, uint32_t * end)
{
	struct memscrub_priv *priv = memscrubpriv;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	if ((start==NULL) || (end == NULL)){
		DBG("MEMSCRUB wrong pointer.\n");
		return MEMSCRUB_ERR_EINVAL;
	}

	/* Get range */
	*start = REG_READ(&priv->regs->rangel2);
	*end = REG_READ(&priv->regs->rangeh2);

	return MEMSCRUB_ERR_OK;
}

int memscrub_ahberror_setup(int uethres, int cethres, int options)
{
	struct memscrub_priv *priv = memscrubpriv;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	/* Set AHBERR */
	REG_WRITE(&priv->regs->ahberc, 
			((cethres << AHBERC_CECNTT_BIT) & AHBERC_CECNTT) |
			((uethres << AHBERC_UECNTT_BIT) & AHBERC_UECNTT) |
			(options & (AHBERC_CECTE | AHBERC_UECTE)));

	DBG("MEMSCRUB ahb err: UE[%d]:%s, CE[%d]:%s\n",
			(unsigned int) uethres,
			(options & AHBERC_UECTE)? "enabled":"disabled",
			(unsigned int) cethres,
			(options & AHBERC_CECTE)? "enabled":"disabled"
			);

	return MEMSCRUB_ERR_OK;
}

int memscrub_scruberror_setup(int blkthres, int runthres, int options)
{
	struct memscrub_priv *priv = memscrubpriv;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	/* Set ETHRES */
	REG_WRITE(&priv->regs->ethres, 
			((blkthres << ETHRES_BECT_BIT) & ETHRES_BECT) |
			((runthres << ETHRES_RECT_BIT) & ETHRES_RECT) |
			(options & (ETHRES_RECTE | ETHRES_BECTE)));

	DBG("MEMSCRUB scrub err: BLK[%d]:%s, RUN[%d]:%s\n",
			(unsigned int) blkthres,
			(options & ETHRES_BECTE)? "enabled":"disabled",
			(unsigned int) runthres,
			(options & ETHRES_RECTE)? "enabled":"disabled"
			);

	return MEMSCRUB_ERR_OK;
}

int memscrub_scrub_position(uint32_t * position)
{
	struct memscrub_priv *priv = memscrubpriv;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	if (position==NULL){
		DBG("MEMSCRUB wrong pointer.\n");
		return MEMSCRUB_ERR_EINVAL;
	}

	*position = REG_READ(&priv->regs->pos);

	return MEMSCRUB_ERR_OK;
}

int memscrub_isr_register(memscrub_isr_t isr, void * data)
{
	struct memscrub_priv *priv = memscrubpriv;
	unsigned int ethres, ahberc, config;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	if (isr==NULL){
		DBG("MEMSCRUB wrong pointer.\n");
		return MEMSCRUB_ERR_EINVAL;
	}

	/* Mask interrupts */
	ethres = REG_READ(&priv->regs->ethres);
	REG_WRITE(&priv->regs->ethres, ethres & ~(ETHRES_RECTE | ETHRES_BECTE));

	ahberc = REG_READ(&priv->regs->ahberc);
	REG_WRITE(&priv->regs->ahberc, ahberc & ~(AHBERC_CECTE | AHBERC_UECTE));

	config = REG_READ(&priv->regs->config);
	REG_WRITE(&priv->regs->config, config & ~(CONFIG_IRQD));

	/* Install IRQ handler if needed */
	if (priv->isr == NULL){
		drvmgr_interrupt_register(priv->dev, 0, priv->devname, memscrub_isr,
				priv);
	}

	/* Install user ISR */
	priv->isr=isr;
	priv->isr_arg=data;

	/* Unmask interrupts */
	REG_WRITE(&priv->regs->ethres, ethres);

	REG_WRITE(&priv->regs->ahberc, ahberc);

	REG_WRITE(&priv->regs->config, config);

	return MEMSCRUB_ERR_OK;
}

int memscrub_isr_unregister(void)
{
	struct memscrub_priv *priv = memscrubpriv;
	unsigned int ethres, ahberc, config;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	if (priv->isr==NULL){
		DBG("MEMSCRUB wrong pointer.\n");
		return MEMSCRUB_ERR_EINVAL;
	}

	/* Mask interrupts */
	ethres = REG_READ(&priv->regs->ethres);
	REG_WRITE(&priv->regs->ethres, ethres & ~(ETHRES_RECTE | ETHRES_BECTE));

	ahberc = REG_READ(&priv->regs->ahberc);
	REG_WRITE(&priv->regs->ahberc, ahberc & ~(AHBERC_CECTE | AHBERC_UECTE));

	config = REG_READ(&priv->regs->config);
	REG_WRITE(&priv->regs->config, config & ~(CONFIG_IRQD));

	/* Uninstall IRQ handler if needed */
	drvmgr_interrupt_unregister(priv->dev, 0, memscrub_isr, priv);

	/* Uninstall user ISR */
	priv->isr=NULL;
	priv->isr_arg=NULL;

	return MEMSCRUB_ERR_OK;
}

int memscrub_error_status(uint32_t *ahbaccess, uint32_t *ahbstatus, 
		uint32_t *scrubstatus)
{
	struct memscrub_priv *priv = memscrubpriv;
	uint32_t mask, ahbstatus_val;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	if ((ahbaccess==NULL) || (ahbstatus==NULL) || (scrubstatus == NULL)){
		DBG("MEMSCRUB wrong pointer.\n");
		return MEMSCRUB_ERR_EINVAL;
	}

	/* Get hardware status */
	*ahbaccess = REG_READ(&priv->regs->ahbfailing);
	*ahbstatus = ahbstatus_val = REG_READ(&priv->regs->ahbstatus);
	*scrubstatus = REG_READ(&priv->regs->status);

	/* Clear error status */
	mask = 0;
	/* Clear CECNT only if we crossed the CE threshold*/
	if ((ahbstatus_val & AHBS_CE) == 0){
		/* Don't clear the CECNT */
		mask |= AHBS_CECNT;
	}
	/* Clear UECNT only if we crossed the UE threshold*/
	if ((ahbstatus_val & (AHBS_NE|AHBS_CE|AHBS_SBC|AHBS_SEC)) != AHBS_NE){
		/* Don't clear the UECNT */
		mask |= AHBS_UECNT;
	}
	REG_WRITE(&priv->regs->ahbstatus, ahbstatus_val & mask);
	REG_WRITE(&priv->regs->status,0);

	return MEMSCRUB_ERR_OK;
}

int memscrub_active(void)
{
	struct memscrub_priv *priv = memscrubpriv;

	if (priv==NULL){
		DBG("MEMSCRUB not init.\n");
		return MEMSCRUB_ERR_ERROR;
	}

	return REG_READ(&priv->regs->status) & STAT_ACTIVE;
}

void memscrub_isr(void *arg)
{
	struct memscrub_priv *priv = arg;
	uint32_t fadr, ahbstatus, status, mask;

	/* Get hardware status */
	ahbstatus = REG_READ(&priv->regs->ahbstatus);
	if ((ahbstatus & (AHBS_NE|AHBS_DONE)) == 0){
		return;
	}

	/* IRQ generated by MEMSCRUB core... handle it here */

	/* Get Failing address */
	fadr = REG_READ(&priv->regs->ahbfailing);

	/* Get Status */
	status = REG_READ(&priv->regs->status);

	/* Clear error status */
	mask = 0;
	/* Clear CECNT only if we crossed the CE threshold*/
	if ((ahbstatus & AHBS_CE) == 0){
		/* Don't clear the CECNT */
		mask |= AHBS_CECNT;
	}
	/* Clear UECNT only if we crossed the UE threshold*/
	if ((ahbstatus & (AHBS_NE|AHBS_CE|AHBS_SBC|AHBS_SEC)) != AHBS_NE){
		/* Don't clear the UECNT */
		mask |= AHBS_UECNT;
	}
	REG_WRITE(&priv->regs->ahbstatus, ahbstatus & mask);
	REG_WRITE(&priv->regs->status,0);

	/* Let user handle error */
	(priv->isr)(priv->isr_arg, fadr, ahbstatus, status);

	return;
}