aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/sk98lin/skdim.c
blob: 0fddf61047b495e4337a5c2991b601d38146286f (plain)
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
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
/******************************************************************************
 *
 * Name:	skdim.c
 * Project:	GEnesis, PCI Gigabit Ethernet Adapter
 * Version:	$Revision: 1.5 $
 * Date:	$Date: 2003/11/28 12:55:40 $
 * Purpose:	All functions to maintain interrupt moderation
 *
 ******************************************************************************/

/******************************************************************************
 *
 *	(C)Copyright 1998-2002 SysKonnect GmbH.
 *	(C)Copyright 2002-2003 Marvell.
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation; either version 2 of the License, or
 *	(at your option) any later version.
 *
 *	The information in this file is provided "AS IS" without warranty.
 *
 ******************************************************************************/

/******************************************************************************
 *
 * Description:
 *
 * This module is intended to manage the dynamic interrupt moderation on both   
 * GEnesis and Yukon adapters.
 *
 * Include File Hierarchy:
 *
 *	"skdrv1st.h"
 *	"skdrv2nd.h"
 *
 ******************************************************************************/

#ifndef	lint
static const char SysKonnectFileId[] =
	"@(#) $Id: skdim.c,v 1.5 2003/11/28 12:55:40 rroesler Exp $ (C) SysKonnect.";
#endif

#define __SKADDR_C

#ifdef __cplusplus
#error C++ is not yet supported.
extern "C" {
#endif

/*******************************************************************************
**
** Includes
**
*******************************************************************************/

#ifndef __INC_SKDRV1ST_H
#include "h/skdrv1st.h"
#endif

#ifndef __INC_SKDRV2ND_H
#include "h/skdrv2nd.h"
#endif

#include	<linux/kernel_stat.h>

/*******************************************************************************
**
** Defines
**
*******************************************************************************/

/*******************************************************************************
**
** Typedefs
**
*******************************************************************************/

/*******************************************************************************
**
** Local function prototypes 
**
*******************************************************************************/

static unsigned int GetCurrentSystemLoad(SK_AC *pAC);
static SK_U64       GetIsrCalls(SK_AC *pAC);
static SK_BOOL      IsIntModEnabled(SK_AC *pAC);
static void         SetCurrIntCtr(SK_AC *pAC);
static void         EnableIntMod(SK_AC *pAC); 
static void         DisableIntMod(SK_AC *pAC);
static void         ResizeDimTimerDuration(SK_AC *pAC);
static void         DisplaySelectedModerationType(SK_AC *pAC);
static void         DisplaySelectedModerationMask(SK_AC *pAC);
static void         DisplayDescrRatio(SK_AC *pAC);

/*******************************************************************************
**
** Global variables
**
*******************************************************************************/

/*******************************************************************************
**
** Local variables
**
*******************************************************************************/

/*******************************************************************************
**
** Global functions 
**
*******************************************************************************/

/*******************************************************************************
** Function     : SkDimModerate
** Description  : Called in every ISR to check if moderation is to be applied
**                or not for the current number of interrupts
** Programmer   : Ralph Roesler
** Last Modified: 22-mar-03
** Returns      : void (!)
** Notes        : -
*******************************************************************************/

void 
SkDimModerate(SK_AC *pAC) {
    unsigned int CurrSysLoad    = 0;  /* expressed in percent */
    unsigned int LoadIncrease   = 0;  /* expressed in percent */
    SK_U64       ThresholdInts  = 0;
    SK_U64       IsrCallsPerSec = 0;

#define M_DIMINFO pAC->DynIrqModInfo

    if (!IsIntModEnabled(pAC)) {
        if (M_DIMINFO.IntModTypeSelect == C_INT_MOD_DYNAMIC) {
            CurrSysLoad = GetCurrentSystemLoad(pAC);
            if (CurrSysLoad > 75) {
                    /* 
                    ** More than 75% total system load! Enable the moderation 
                    ** to shield the system against too many interrupts.
                    */
                    EnableIntMod(pAC);
            } else if (CurrSysLoad > M_DIMINFO.PrevSysLoad) {
                LoadIncrease = (CurrSysLoad - M_DIMINFO.PrevSysLoad);
                if (LoadIncrease > ((M_DIMINFO.PrevSysLoad *
                                         C_INT_MOD_ENABLE_PERCENTAGE) / 100)) {
                    if (CurrSysLoad > 10) {
                        /* 
                        ** More than 50% increase with respect to the 
                        ** previous load of the system. Most likely this 
                        ** is due to our ISR-proc...
                        */
                        EnableIntMod(pAC);
                    }
                }
            } else {
                /*
                ** Neither too much system load at all nor too much increase
                ** with respect to the previous system load. Hence, we can leave
                ** the ISR-handling like it is without enabling moderation.
                */
            }
            M_DIMINFO.PrevSysLoad = CurrSysLoad;
        }   
    } else {
        if (M_DIMINFO.IntModTypeSelect == C_INT_MOD_DYNAMIC) {
            ThresholdInts  = ((M_DIMINFO.MaxModIntsPerSec *
                                   C_INT_MOD_DISABLE_PERCENTAGE) / 100);
            IsrCallsPerSec = GetIsrCalls(pAC);
            if (IsrCallsPerSec <= ThresholdInts) {
                /* 
                ** The number of interrupts within the last second is 
                ** lower than the disable_percentage of the desried 
                ** maxrate. Therefore we can disable the moderation.
                */
                DisableIntMod(pAC);
                M_DIMINFO.MaxModIntsPerSec = 
                   (M_DIMINFO.MaxModIntsPerSecUpperLimit +
                    M_DIMINFO.MaxModIntsPerSecLowerLimit) / 2;
            } else {
                /*
                ** The number of interrupts per sec is the same as expected.
                ** Evalulate the descriptor-ratio. If it has changed, a resize 
                ** in the moderation timer might be usefull
                */
                if (M_DIMINFO.AutoSizing) {
                    ResizeDimTimerDuration(pAC);
                }
            }
        }
    }

    /*
    ** Some information to the log...
    */
    if (M_DIMINFO.DisplayStats) {
        DisplaySelectedModerationType(pAC);
        DisplaySelectedModerationMask(pAC);
        DisplayDescrRatio(pAC);
    }

    M_DIMINFO.NbrProcessedDescr = 0; 
    SetCurrIntCtr(pAC);
}

/*******************************************************************************
** Function     : SkDimStartModerationTimer
** Description  : Starts the audit-timer for the dynamic interrupt moderation
** Programmer   : Ralph Roesler
** Last Modified: 22-mar-03
** Returns      : void (!)
** Notes        : -
*******************************************************************************/

void 
SkDimStartModerationTimer(SK_AC *pAC) {
    SK_EVPARA    EventParam;   /* Event struct for timer event */
 
    SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
    EventParam.Para32[0] = SK_DRV_MODERATION_TIMER;
    SkTimerStart(pAC, pAC->IoBase, &pAC->DynIrqModInfo.ModTimer,
                 SK_DRV_MODERATION_TIMER_LENGTH,
                 SKGE_DRV, SK_DRV_TIMER, EventParam);
}

/*******************************************************************************
** Function     : SkDimEnableModerationIfNeeded
** Description  : Either enables or disables moderation
** Programmer   : Ralph Roesler
** Last Modified: 22-mar-03
** Returns      : void (!)
** Notes        : This function is called when a particular adapter is opened
**                There is no Disable function, because when all interrupts 
**                might be disable, the moderation timer has no meaning at all
******************************************************************************/

void
SkDimEnableModerationIfNeeded(SK_AC *pAC) {

    if (M_DIMINFO.IntModTypeSelect == C_INT_MOD_STATIC) {
        EnableIntMod(pAC);   /* notification print in this function */
    } else if (M_DIMINFO.IntModTypeSelect == C_INT_MOD_DYNAMIC) {
        SkDimStartModerationTimer(pAC);
        if (M_DIMINFO.DisplayStats) {
            printk("Dynamic moderation has been enabled\n");
        }
    } else {
        if (M_DIMINFO.DisplayStats) {
            printk("No moderation has been enabled\n");
        }
    }
}

/*******************************************************************************
** Function     : SkDimDisplayModerationSettings
** Description  : Displays the current settings regaring interrupt moderation
** Programmer   : Ralph Roesler
** Last Modified: 22-mar-03
** Returns      : void (!)
** Notes        : -
*******************************************************************************/

void 
SkDimDisplayModerationSettings(SK_AC *pAC) {
    DisplaySelectedModerationType(pAC);
    DisplaySelectedModerationMask(pAC);
}

/*******************************************************************************
**
** Local functions 
**
*******************************************************************************/

/*******************************************************************************
** Function     : GetCurrentSystemLoad
** Description  : Retrieves the current system load of the system. This load
**                is evaluated for all processors within the system.
** Programmer   : Ralph Roesler
** Last Modified: 22-mar-03
** Returns      : unsigned int: load expressed in percentage
** Notes        : The possible range being returned is from 0 up to 100.
**                Whereas 0 means 'no load at all' and 100 'system fully loaded'
**                It is impossible to determine what actually causes the system
**                to be in 100%, but maybe that is due to too much interrupts.
*******************************************************************************/

static unsigned int
GetCurrentSystemLoad(SK_AC *pAC) {
	unsigned long jif         = jiffies;
	unsigned int  UserTime    = 0;
	unsigned int  SystemTime  = 0;
	unsigned int  NiceTime    = 0;
	unsigned int  IdleTime    = 0;
	unsigned int  TotalTime   = 0;
	unsigned int  UsedTime    = 0;
	unsigned int  SystemLoad  = 0;

	/* unsigned int  NbrCpu      = 0; */

	/*
	** The following lines have been commented out, because
	** from kernel 2.5.44 onwards, the kernel-owned structure
	**
	**      struct kernel_stat kstat
	**
	** is not marked as an exported symbol in the file
	**
	**      kernel/ksyms.c 
	**
	** As a consequence, using this driver as KLM is not possible
	** and any access of the structure kernel_stat via the 
	** dedicated macros kstat_cpu(i).cpustat.xxx is to be avoided.
	**
	** The kstat-information might be added again in future 
	** versions of the 2.5.xx kernel, but for the time being, 
	** number of interrupts will serve as indication how much 
	** load we currently have... 
	**
	** for (NbrCpu = 0; NbrCpu < num_online_cpus(); NbrCpu++) {
	**	UserTime   = UserTime   + kstat_cpu(NbrCpu).cpustat.user;
	**	NiceTime   = NiceTime   + kstat_cpu(NbrCpu).cpustat.nice;
	**	SystemTime = SystemTime + kstat_cpu(NbrCpu).cpustat.system;
	** }
	*/
	SK_U64 ThresholdInts  = 0;
	SK_U64 IsrCallsPerSec = 0;

	ThresholdInts  = ((M_DIMINFO.MaxModIntsPerSec *
			   C_INT_MOD_ENABLE_PERCENTAGE) + 100);
	IsrCallsPerSec = GetIsrCalls(pAC);
	if (IsrCallsPerSec >= ThresholdInts) {
	    /*
	    ** We do not know how much the real CPU-load is!
	    ** Return 80% as a default in order to activate DIM
	    */
	    SystemLoad = 80;
	    return (SystemLoad);  
	} 

	UsedTime  = UserTime + NiceTime + SystemTime;

	IdleTime  = jif * num_online_cpus() - UsedTime;
	TotalTime = UsedTime + IdleTime;

	SystemLoad = ( 100 * (UsedTime  - M_DIMINFO.PrevUsedTime) ) /
						(TotalTime - M_DIMINFO.PrevTotalTime);

	if (M_DIMINFO.DisplayStats) {
		printk("Current system load is: %u\n", SystemLoad);
	}

	M_DIMINFO.PrevTotalTime = TotalTime;
	M_DIMINFO.PrevUsedTime  = UsedTime;

	return (SystemLoad);
}

/*******************************************************************************
** Function     : GetIsrCalls
** Description  : Depending on the selected moderation mask, this function will
**                return the number of interrupts handled in the previous time-
**                frame. This evaluated number is based on the current number 
**                of interrupts stored in PNMI-context and the previous stored 
**                interrupts.
** Programmer   : Ralph Roesler
** Last Modified: 23-mar-03
** Returns      : int:   the number of interrupts being executed in the last
**                       timeframe
** Notes        : It makes only sense to call this function, when dynamic 
**                interrupt moderation is applied
*******************************************************************************/

static SK_U64
GetIsrCalls(SK_AC *pAC) {
    SK_U64   RxPort0IntDiff = 0;
    SK_U64   RxPort1IntDiff = 0;
    SK_U64   TxPort0IntDiff = 0;
    SK_U64   TxPort1IntDiff = 0;

    if (pAC->DynIrqModInfo.MaskIrqModeration == IRQ_MASK_TX_ONLY) {
        if (pAC->GIni.GIMacsFound == 2) {
            TxPort1IntDiff = pAC->Pnmi.Port[1].TxIntrCts - 
                             pAC->DynIrqModInfo.PrevPort1TxIntrCts;
        }
        TxPort0IntDiff = pAC->Pnmi.Port[0].TxIntrCts - 
                         pAC->DynIrqModInfo.PrevPort0TxIntrCts;
    } else if (pAC->DynIrqModInfo.MaskIrqModeration == IRQ_MASK_RX_ONLY) {
        if (pAC->GIni.GIMacsFound == 2) {
            RxPort1IntDiff = pAC->Pnmi.Port[1].RxIntrCts - 
                             pAC->DynIrqModInfo.PrevPort1RxIntrCts;
        }
        RxPort0IntDiff = pAC->Pnmi.Port[0].RxIntrCts - 
                         pAC->DynIrqModInfo.PrevPort0RxIntrCts;
    } else {
        if (pAC->GIni.GIMacsFound == 2) {
            RxPort1IntDiff = pAC->Pnmi.Port[1].RxIntrCts - 
                             pAC->DynIrqModInfo.PrevPort1RxIntrCts;
            TxPort1IntDiff = pAC->Pnmi.Port[1].TxIntrCts - 
                             pAC->DynIrqModInfo.PrevPort1TxIntrCts;
        } 
        RxPort0IntDiff = pAC->Pnmi.Port[0].RxIntrCts - 
                         pAC->DynIrqModInfo.PrevPort0RxIntrCts;
        TxPort0IntDiff = pAC->Pnmi.Port[0].TxIntrCts - 
                         pAC->DynIrqModInfo.PrevPort0TxIntrCts;
    }

    return (RxPort0IntDiff + RxPort1IntDiff + TxPort0IntDiff + TxPort1IntDiff);
}

/*******************************************************************************
** Function     : GetRxCalls
** Description  : This function will return the number of times a receive inter-
**                rupt was processed. This is needed to evaluate any resizing 
**                factor.
** Programmer   : Ralph Roesler
** Last Modified: 23-mar-03
** Returns      : SK_U64: the number of RX-ints being processed
** Notes        : It makes only sense to call this function, when dynamic 
**                interrupt moderation is applied
*******************************************************************************/

static SK_U64
GetRxCalls(SK_AC *pAC) {
    SK_U64   RxPort0IntDiff = 0;
    SK_U64   RxPort1IntDiff = 0;

    if (pAC->GIni.GIMacsFound == 2) {
        RxPort1IntDiff = pAC->Pnmi.Port[1].RxIntrCts - 
                         pAC->DynIrqModInfo.PrevPort1RxIntrCts;
    }
    RxPort0IntDiff = pAC->Pnmi.Port[0].RxIntrCts - 
                     pAC->DynIrqModInfo.PrevPort0RxIntrCts;

    return (RxPort0IntDiff + RxPort1IntDiff);
}

/*******************************************************************************
** Function     : SetCurrIntCtr
** Description  : Will store the current number orf occured interrupts in the 
**                adapter context. This is needed to evaluated the number of 
**                interrupts within a current timeframe.
** Programmer   : Ralph Roesler
** Last Modified: 23-mar-03
** Returns      : void (!)
** Notes        : -
*******************************************************************************/

static void
SetCurrIntCtr(SK_AC *pAC) {
    if (pAC->GIni.GIMacsFound == 2) {
        pAC->DynIrqModInfo.PrevPort1RxIntrCts = pAC->Pnmi.Port[1].RxIntrCts;
        pAC->DynIrqModInfo.PrevPort1TxIntrCts = pAC->Pnmi.Port[1].TxIntrCts;
    } 
    pAC->DynIrqModInfo.PrevPort0RxIntrCts = pAC->Pnmi.Port[0].RxIntrCts;
    pAC->DynIrqModInfo.PrevPort0TxIntrCts = pAC->Pnmi.Port[0].TxIntrCts;
}

/*******************************************************************************
** Function     : IsIntModEnabled()
** Description  : Retrieves the current value of the interrupts moderation
**                command register. Its content determines whether any 
**                moderation is running or not.
** Programmer   : Ralph Roesler
** Last Modified: 23-mar-03
** Returns      : SK_TRUE  : if mod timer running
**                SK_FALSE : if no moderation is being performed
** Notes        : -
*******************************************************************************/

static SK_BOOL
IsIntModEnabled(SK_AC *pAC) {
    unsigned long CtrCmd;

    SK_IN32(pAC->IoBase, B2_IRQM_CTRL, &CtrCmd);
    if ((CtrCmd & TIM_START) == TIM_START) {
       return SK_TRUE;
    } else {
       return SK_FALSE;
    }
}

/*******************************************************************************
** Function     : EnableIntMod()
** Description  : Enables the interrupt moderation using the values stored in
**                in the pAC->DynIntMod data structure
** Programmer   : Ralph Roesler
** Last Modified: 22-mar-03
** Returns      : -
** Notes        : -
*******************************************************************************/

static void
EnableIntMod(SK_AC *pAC) {
    unsigned long ModBase;

    if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
       ModBase = C_CLK_FREQ_GENESIS / pAC->DynIrqModInfo.MaxModIntsPerSec;
    } else {
       ModBase = C_CLK_FREQ_YUKON / pAC->DynIrqModInfo.MaxModIntsPerSec;
    }

    SK_OUT32(pAC->IoBase, B2_IRQM_INI,  ModBase);
    SK_OUT32(pAC->IoBase, B2_IRQM_MSK,  pAC->DynIrqModInfo.MaskIrqModeration);
    SK_OUT32(pAC->IoBase, B2_IRQM_CTRL, TIM_START);
    if (M_DIMINFO.DisplayStats) {
        printk("Enabled interrupt moderation (%i ints/sec)\n",
               M_DIMINFO.MaxModIntsPerSec);
    }
}

/*******************************************************************************
** Function     : DisableIntMod()
** Description  : Disbles the interrupt moderation independent of what inter-
**                rupts are running or not
** Programmer   : Ralph Roesler
** Last Modified: 23-mar-03
** Returns      : -
** Notes        : -
*******************************************************************************/

static void 
DisableIntMod(SK_AC *pAC) {

    SK_OUT32(pAC->IoBase, B2_IRQM_CTRL, TIM_STOP);
    if (M_DIMINFO.DisplayStats) {
        printk("Disabled interrupt moderation\n");
    }
} 

/*******************************************************************************
** Function     : ResizeDimTimerDuration();
** Description  : Checks the current used descriptor ratio and resizes the 
**                duration timer (longer/smaller) if possible. 
** Programmer   : Ralph Roesler
** Last Modified: 23-mar-03
** Returns      : -
** Notes        : There are both maximum and minimum timer duration value. 
**                This function assumes that interrupt moderation is already
**                enabled!
*******************************************************************************/

static void 
ResizeDimTimerDuration(SK_AC *pAC) {
    SK_BOOL IncreaseTimerDuration;
    int     TotalMaxNbrDescr;
    int     UsedDescrRatio;
    int     RatioDiffAbs;
    int     RatioDiffRel;
    int     NewMaxModIntsPerSec;
    int     ModAdjValue;
    long    ModBase;

    /*
    ** Check first if we are allowed to perform any modification
    */
    if (IsIntModEnabled(pAC)) { 
        if (M_DIMINFO.IntModTypeSelect != C_INT_MOD_DYNAMIC) {
            return; 
        } else {
            if (M_DIMINFO.ModJustEnabled) {
                M_DIMINFO.ModJustEnabled = SK_FALSE;
                return;
            }
        }
    }

    /*
    ** If we got until here, we have to evaluate the amount of the
    ** descriptor ratio change...
    */
    TotalMaxNbrDescr = pAC->RxDescrPerRing * GetRxCalls(pAC);
    UsedDescrRatio   = (M_DIMINFO.NbrProcessedDescr * 100) / TotalMaxNbrDescr;

    if (UsedDescrRatio > M_DIMINFO.PrevUsedDescrRatio) {
        RatioDiffAbs = (UsedDescrRatio - M_DIMINFO.PrevUsedDescrRatio);
        RatioDiffRel = (RatioDiffAbs * 100) / UsedDescrRatio;
        M_DIMINFO.PrevUsedDescrRatio = UsedDescrRatio;
        IncreaseTimerDuration = SK_FALSE;  /* in other words: DECREASE */
    } else if (UsedDescrRatio < M_DIMINFO.PrevUsedDescrRatio) {
        RatioDiffAbs = (M_DIMINFO.PrevUsedDescrRatio - UsedDescrRatio);
        RatioDiffRel = (RatioDiffAbs * 100) / M_DIMINFO.PrevUsedDescrRatio;
        M_DIMINFO.PrevUsedDescrRatio = UsedDescrRatio;
        IncreaseTimerDuration = SK_TRUE;   /* in other words: INCREASE */
    } else {
        RatioDiffAbs = (M_DIMINFO.PrevUsedDescrRatio - UsedDescrRatio);
        RatioDiffRel = (RatioDiffAbs * 100) / M_DIMINFO.PrevUsedDescrRatio;
        M_DIMINFO.PrevUsedDescrRatio = UsedDescrRatio;
        IncreaseTimerDuration = SK_TRUE;   /* in other words: INCREASE */
    }

    /*
    ** Now we can determine the change in percent
    */
    if ((RatioDiffRel >= 0) && (RatioDiffRel <= 5) ) {
       ModAdjValue = 1;  /*  1% change - maybe some other value in future */
    } else if ((RatioDiffRel > 5) && (RatioDiffRel <= 10) ) {
       ModAdjValue = 1;  /*  1% change - maybe some other value in future */
    } else if ((RatioDiffRel > 10) && (RatioDiffRel <= 15) ) {
       ModAdjValue = 1;  /*  1% change - maybe some other value in future */
    } else {
       ModAdjValue = 1;  /*  1% change - maybe some other value in future */
    }

    if (IncreaseTimerDuration) {
       NewMaxModIntsPerSec =  M_DIMINFO.MaxModIntsPerSec +
                             (M_DIMINFO.MaxModIntsPerSec * ModAdjValue) / 100;
    } else {
       NewMaxModIntsPerSec =  M_DIMINFO.MaxModIntsPerSec -
                             (M_DIMINFO.MaxModIntsPerSec * ModAdjValue) / 100;
    }

    /* 
    ** Check if we exceed boundaries...
    */
    if ( (NewMaxModIntsPerSec > M_DIMINFO.MaxModIntsPerSecUpperLimit) ||
         (NewMaxModIntsPerSec < M_DIMINFO.MaxModIntsPerSecLowerLimit)) {
        if (M_DIMINFO.DisplayStats) {
            printk("Cannot change ModTim from %i to %i ints/sec\n",
                   M_DIMINFO.MaxModIntsPerSec, NewMaxModIntsPerSec);
        }
        return;
    } else {
        if (M_DIMINFO.DisplayStats) {
            printk("Resized ModTim from %i to %i ints/sec\n",
                   M_DIMINFO.MaxModIntsPerSec, NewMaxModIntsPerSec);
        }
    }

    M_DIMINFO.MaxModIntsPerSec = NewMaxModIntsPerSec;

    if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
        ModBase = C_CLK_FREQ_GENESIS / pAC->DynIrqModInfo.MaxModIntsPerSec;
    } else {
        ModBase = C_CLK_FREQ_YUKON / pAC->DynIrqModInfo.MaxModIntsPerSec;
    }

    /* 
    ** We do not need to touch any other registers
    */
    SK_OUT32(pAC->IoBase, B2_IRQM_INI, ModBase);
} 

/*******************************************************************************
** Function     : DisplaySelectedModerationType()
** Description  : Displays what type of moderation we have
** Programmer   : Ralph Roesler
** Last Modified: 23-mar-03
** Returns      : void!
** Notes        : -
*******************************************************************************/

static void
DisplaySelectedModerationType(SK_AC *pAC) {

    if (pAC->DynIrqModInfo.DisplayStats) {
        if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC) {
             printk("Static int moderation runs with %i INTS/sec\n",
                    pAC->DynIrqModInfo.MaxModIntsPerSec);
        } else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC) {
             if (IsIntModEnabled(pAC)) {
                printk("Dynamic int moderation runs with %i INTS/sec\n",
                       pAC->DynIrqModInfo.MaxModIntsPerSec);
             } else {
                printk("Dynamic int moderation currently not applied\n");
             }
        } else {
             printk("No interrupt moderation selected!\n");
        }
    }
}

/*******************************************************************************
** Function     : DisplaySelectedModerationMask()
** Description  : Displays what interrupts are moderated
** Programmer   : Ralph Roesler
** Last Modified: 23-mar-03
** Returns      : void!
** Notes        : -
*******************************************************************************/

static void
DisplaySelectedModerationMask(SK_AC *pAC) {

    if (pAC->DynIrqModInfo.DisplayStats) {
        if (pAC->DynIrqModInfo.IntModTypeSelect != C_INT_MOD_NONE) {
            switch (pAC->DynIrqModInfo.MaskIrqModeration) {
                case IRQ_MASK_TX_ONLY: 
                   printk("Only Tx-interrupts are moderated\n");
                   break;
                case IRQ_MASK_RX_ONLY: 
                   printk("Only Rx-interrupts are moderated\n");
                   break;
                case IRQ_MASK_SP_ONLY: 
                   printk("Only special-interrupts are moderated\n");
                   break;
                case IRQ_MASK_TX_RX: 
                   printk("Tx- and Rx-interrupts are moderated\n");
                   break;
                case IRQ_MASK_SP_RX: 
                   printk("Special- and Rx-interrupts are moderated\n");
                   break;
                case IRQ_MASK_SP_TX: 
                   printk("Special- and Tx-interrupts are moderated\n");
                   break;
                case IRQ_MASK_RX_TX_SP:
                   printk("All Rx-, Tx and special-interrupts are moderated\n");
                   break;
                default:
                   printk("Don't know what is moderated\n");
                   break;
            }
        } else {
            printk("No specific interrupts masked for moderation\n");
        }
    } 
}

/*******************************************************************************
** Function     : DisplayDescrRatio
** Description  : Like the name states...
** Programmer   : Ralph Roesler
** Last Modified: 23-mar-03
** Returns      : void!
** Notes        : -
*******************************************************************************/

static void
DisplayDescrRatio(SK_AC *pAC) {
    int TotalMaxNbrDescr = 0;

    if (pAC->DynIrqModInfo.DisplayStats) {
        TotalMaxNbrDescr = pAC->RxDescrPerRing * GetRxCalls(pAC);
        printk("Ratio descriptors: %i/%i\n",
               M_DIMINFO.NbrProcessedDescr, TotalMaxNbrDescr);
    }
}

/*******************************************************************************
**
** End of file
**
*******************************************************************************/