Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / dev / atm / hfa / fore_intr.c
1 /*
2  *
3  * ===================================
4  * HARP  |  Host ATM Research Platform
5  * ===================================
6  *
7  *
8  * This Host ATM Research Platform ("HARP") file (the "Software") is
9  * made available by Network Computing Services, Inc. ("NetworkCS")
10  * "AS IS".  NetworkCS does not provide maintenance, improvements or
11  * support of any kind.
12  *
13  * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14  * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15  * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16  * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17  * In no event shall NetworkCS be responsible for any damages, including
18  * but not limited to consequential damages, arising from or relating to
19  * any use of the Software or related support.
20  *
21  * Copyright 1994-1998 Network Computing Services, Inc.
22  *
23  * Copies of this Software may be made, however, the above copyright
24  * notice must be reproduced on all copies.
25  *
26  *      @(#) $FreeBSD: src/sys/dev/hfa/fore_intr.c,v 1.3 1999/08/28 00:41:50 peter Exp $
27  *
28  */
29
30 /*
31  * FORE Systems 200-Series Adapter Support
32  * ---------------------------------------
33  *
34  * Interrupt processing
35  *
36  */
37
38 #include <dev/hfa/fore_include.h>
39
40 #ifndef lint
41 __RCSID("@(#) $FreeBSD: src/sys/dev/hfa/fore_intr.c,v 1.3 1999/08/28 00:41:50 peter Exp $");
42 #endif
43
44 #if defined(sun)
45 /*
46  * Polling interrupt routine
47  * 
48  * Polling interrupts are handled by calling all interrupt service 
49  * routines for a given level until someone claims to have "handled" the 
50  * interrupt.
51  *
52  * Called at interrupt level.
53  *
54  * Arguments:
55  *      none
56  *
57  * Returns:
58  *      1               an interrupt has been serviced
59  *      0               no interrupts serviced
60  *
61  */
62 int
63 fore_poll()
64 {
65         int     serviced = 0;
66         int     unit;
67
68         /*
69          * See if any of our devices are interrupting
70          */
71         for ( unit = 0; unit < fore_nunits; unit++ )
72         {
73                 Fore_unit       *fup = fore_units[unit];
74
75                 if (fup == NULL)
76                         continue;
77
78                 serviced += fore_intr((void *)fup);
79         }
80
81         /*
82          * Indicate if we handled an interrupt
83          */
84         return (serviced ? 1 : 0);
85 }
86 #endif  /* defined(sun) */
87
88
89 /*
90  * Device interrupt routine
91  * 
92  * Called at interrupt level.
93  *
94  * Arguments:
95  *      arg             pointer to device unit structure
96  *
97  * Returns:
98  *      1               device interrupt was serviced
99  *      0               no interrupts serviced
100  *
101  */
102 #if (defined(BSD) && (BSD <= 199306))
103 int
104 #else
105 void
106 #endif
107 fore_intr(arg)
108         void    *arg;
109 {
110         Fore_unit       *fup = arg;
111         Aali    *aap;
112 #if (defined(BSD) && (BSD <= 199306))
113         int     serviced = 0;
114 #endif
115
116         /*
117          * Try to prevent stuff happening after we've paniced
118          */
119         if (panicstr) {
120                 goto done;
121         }
122
123         /*
124          * Get to the microcode shared memory interface
125          */
126         if ((aap = fup->fu_aali) == NULL)
127                 goto done;
128
129         /*
130          * Has this card issued an interrupt??
131          */
132 #ifdef FORE_PCI
133         if (*fup->fu_psr) {
134 #else
135         if (aap->aali_intr_sent) {
136 #endif
137
138                 /*
139                  * Indicate that we've serviced an interrupt. 
140                  */
141 #if (defined(BSD) && (BSD <= 199306))
142                 serviced = 1;
143 #endif
144
145                 /*
146                  * Clear the device interrupt
147                  */
148                 switch (fup->fu_config.ac_device) {
149
150 #ifdef FORE_SBUS
151                 case DEV_FORE_SBA200E:
152                         SBA200E_HCR_SET(*fup->fu_ctlreg, SBA200E_CLR_SBUS_INTR);
153                         break;
154
155                 case DEV_FORE_SBA200:
156                         *fup->fu_ctlreg = SBA200_CLR_SBUS_INTR;
157                         break;
158 #endif
159 #ifdef FORE_PCI
160                 case DEV_FORE_PCA200E:
161                         PCA200E_HCR_SET(*fup->fu_ctlreg, PCA200E_CLR_HBUS_INT);
162                         break;
163 #endif
164
165                 }
166                 aap->aali_intr_sent = CP_WRITE(0);
167
168                 /*
169                  * Reset the watchdog timer
170                  */
171                 fup->fu_timer = FORE_WATCHDOG;
172
173                 /*
174                  * Device initialization handled separately
175                  */
176                 if ((fup->fu_flags & CUF_INITED) == 0) {
177
178                         /*
179                          * We're just initializing device now, so see if
180                          * the initialization command has completed
181                          */
182                         if (CP_READ(aap->aali_init.init_status) & 
183                                                 QSTAT_COMPLETED)
184                                 fore_initialize_complete(fup);
185
186                         /*
187                          * If we're still not inited, none of the host
188                          * queues are setup yet
189                          */
190                         if ((fup->fu_flags & CUF_INITED) == 0)
191                                 goto done;
192                 }
193
194                 /*
195                  * Drain the queues of completed work
196                  */
197                 fore_cmd_drain(fup);
198                 fore_recv_drain(fup);
199                 fore_xmit_drain(fup);
200
201                 /*
202                  * Supply more buffers to the CP
203                  */
204                 fore_buf_supply(fup);
205         }
206
207 done:
208 #if (defined(BSD) && (BSD <= 199306))
209         return(serviced);
210 #else
211         return;
212 #endif
213 }
214
215
216 /*
217  * Watchdog timeout routine
218  * 
219  * Called when we haven't heard from the card in a while.  Just in case
220  * we missed an interrupt, we'll drain the queues and try to resupply the
221  * CP with more receive buffers.  If the CP is partially wedged, hopefully
222  * this will be enough to get it going again.
223  *
224  * Called with interrupts locked out.
225  *
226  * Arguments:
227  *      fup             pointer to device unit structure
228  *
229  * Returns:
230  *      none
231  *
232  */
233 void
234 fore_watchdog(fup)
235         Fore_unit       *fup;
236 {
237         /*
238          * Try to prevent stuff happening after we've paniced
239          */
240         if (panicstr) {
241                 return;
242         }
243
244         /*
245          * Reset the watchdog timer
246          */
247         fup->fu_timer = FORE_WATCHDOG;
248
249         /*
250          * If the device is initialized, nudge it (wink, wink)
251          */
252         if (fup->fu_flags & CUF_INITED) {
253
254                 /*
255                  * Drain the queues of completed work
256                  */
257                 fore_cmd_drain(fup);
258                 fore_recv_drain(fup);
259                 fore_xmit_drain(fup);
260
261                 /*
262                  * Supply more buffers to the CP
263                  */
264                 fore_buf_supply(fup);
265         }
266
267         return;
268 }