c64f9cd3e4bb018ac26ef847ce01a18ee93616a2
[linux-flexiantxendom0-3.2.10.git] / drivers / net / sk98lin / skqueue.c
1 /******************************************************************************
2  *
3  * Name:        skqueue.c
4  * Project:     Gigabit Ethernet Adapters, Event Scheduler Module
5  * Purpose:     Management of an event queue.
6  *
7  ******************************************************************************/
8
9 /******************************************************************************
10  *
11  *      (C)Copyright 1998-2002 SysKonnect GmbH.
12  *      (C)Copyright 2002-2003 Marvell.
13  *
14  *      This program is free software; you can redistribute it and/or modify
15  *      it under the terms of the GNU General Public License as published by
16  *      the Free Software Foundation; either version 2 of the License, or
17  *      (at your option) any later version.
18  *
19  *      The information in this file is provided "AS IS" without warranty.
20  *
21  ******************************************************************************/
22
23 /*
24  *      Event queue and dispatcher
25  */
26 #if (defined(DEBUG) || ((!defined(LINT)) && (!defined(SK_SLIM))))
27 static const char SysKonnectFileId[] =
28         "@(#) $Id: skqueue.c,v 1.20 2003/09/16 13:44:00 rschmidt Exp $ (C) Marvell.";
29 #endif
30
31 #include "h/skdrv1st.h"         /* Driver Specific Definitions */
32 #include "h/skqueue.h"          /* Queue Definitions */
33 #include "h/skdrv2nd.h"         /* Adapter Control- and Driver specific Def. */
34
35 #ifdef __C2MAN__
36 /*
37         Event queue management.
38
39         General Description:
40
41  */
42 intro()
43 {}
44 #endif
45
46 #define PRINTF(a,b,c)
47
48 /*
49  * init event queue management
50  *
51  * Must be called during init level 0.
52  */
53 void    SkEventInit(
54 SK_AC   *pAC,   /* Adapter context */
55 SK_IOC  Ioc,    /* IO context */
56 int             Level)  /* Init level */
57 {
58         switch (Level) {
59         case SK_INIT_DATA:
60                 pAC->Event.EvPut = pAC->Event.EvGet = pAC->Event.EvQueue;
61                 break;
62         default:
63                 break;
64         }
65 }
66
67 /*
68  * add event to queue
69  */
70 void    SkEventQueue(
71 SK_AC           *pAC,   /* Adapters context */
72 SK_U32          Class,  /* Event Class */
73 SK_U32          Event,  /* Event to be queued */
74 SK_EVPARA       Para)   /* Event parameter */
75 {
76         pAC->Event.EvPut->Class = Class;
77         pAC->Event.EvPut->Event = Event;
78         pAC->Event.EvPut->Para = Para;
79         
80         if (++pAC->Event.EvPut == &pAC->Event.EvQueue[SK_MAX_EVENT])
81                 pAC->Event.EvPut = pAC->Event.EvQueue;
82
83         if (pAC->Event.EvPut == pAC->Event.EvGet) {
84                 SK_ERR_LOG(pAC, SK_ERRCL_NORES, SKERR_Q_E001, SKERR_Q_E001MSG);
85         }
86 }
87
88 /*
89  * event dispatcher
90  *      while event queue is not empty
91  *              get event from queue
92  *              send command to state machine
93  *      end
94  *      return error reported by individual Event function
95  *              0 if no error occured.
96  */
97 int     SkEventDispatcher(
98 SK_AC   *pAC,   /* Adapters Context */
99 SK_IOC  Ioc)    /* Io context */
100 {
101         SK_EVENTELEM    *pEv;   /* pointer into queue */
102         SK_U32                  Class;
103         int                     Rtv;
104
105         pEv = pAC->Event.EvGet;
106         
107         PRINTF("dispatch get %x put %x\n", pEv, pAC->Event.ev_put);
108         
109         while (pEv != pAC->Event.EvPut) {
110                 PRINTF("dispatch Class %d Event %d\n", pEv->Class, pEv->Event);
111
112                 switch (Class = pEv->Class) {
113 #ifndef SK_USE_LAC_EV
114 #ifndef SK_SLIM
115                 case SKGE_RLMT:         /* RLMT Event */
116                         Rtv = SkRlmtEvent(pAC, Ioc, pEv->Event, pEv->Para);
117                         break;
118                 case SKGE_I2C:          /* I2C Event */
119                         Rtv = SkI2cEvent(pAC, Ioc, pEv->Event, pEv->Para);
120                         break;
121                 case SKGE_PNMI:         /* PNMI Event */
122                         Rtv = SkPnmiEvent(pAC, Ioc, pEv->Event, pEv->Para);
123                         break;
124 #endif  /* not SK_SLIM */
125 #endif  /* not SK_USE_LAC_EV */
126                 case SKGE_DRV:          /* Driver Event */
127                         Rtv = SkDrvEvent(pAC, Ioc, pEv->Event, pEv->Para);
128                         break;
129 #ifndef SK_USE_SW_TIMER
130                 case SKGE_HWAC:
131                         Rtv = SkGeSirqEvent(pAC, Ioc, pEv->Event, pEv->Para);
132                         break;
133 #else /* !SK_USE_SW_TIMER */
134         case SKGE_SWT :
135                         Rtv = SkSwtEvent(pAC, Ioc, pEv->Event, pEv->Para);
136                         break;
137 #endif /* !SK_USE_SW_TIMER */
138 #ifdef SK_USE_LAC_EV
139                 case SKGE_LACP :
140                         Rtv = SkLacpEvent(pAC, Ioc, pEv->Event, pEv->Para);
141                         break;
142                 case SKGE_RSF :
143                         Rtv = SkRsfEvent(pAC, Ioc, pEv->Event, pEv->Para);
144                         break;
145                 case SKGE_MARKER :
146                         Rtv = SkMarkerEvent(pAC, Ioc, pEv->Event, pEv->Para);
147                         break;
148                 case SKGE_FD :
149                         Rtv = SkFdEvent(pAC, Ioc, pEv->Event, pEv->Para);
150                         break;
151 #endif /* SK_USE_LAC_EV */
152 #ifdef  SK_USE_CSUM
153                 case SKGE_CSUM :
154                         Rtv = SkCsEvent(pAC, Ioc, pEv->Event, pEv->Para);
155                         break;
156 #endif  /* SK_USE_CSUM */
157                 default :
158                         SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_Q_E002, SKERR_Q_E002MSG);
159                         Rtv = 0;
160                 }
161
162                 if (Rtv != 0) {
163                         return(Rtv);
164                 }
165
166                 if (++pEv == &pAC->Event.EvQueue[SK_MAX_EVENT])
167                         pEv = pAC->Event.EvQueue;
168
169                 /* Renew get: it is used in queue_events to detect overruns */
170                 pAC->Event.EvGet = pEv;
171         }
172
173         return(0);
174 }
175
176 /* End of file */