3260624b6b0656c5f646e616f5124f1001fda3ee
[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  *      @(#) $DragonFly: src/sys/dev/atm/hfa/fore_intr.c,v 1.5 2005/02/01 00:51:50 joerg Exp $
28  */
29
30 /*
31  * FORE Systems 200-Series Adapter Support
32  * ---------------------------------------
33  *
34  * Interrupt processing
35  *
36  */
37
38 #include "fore_include.h"
39
40 /*
41  * Device interrupt routine
42  * 
43  * Called at interrupt level.
44  *
45  * Arguments:
46  *      arg             pointer to device unit structure
47  *
48  * Returns:
49  *      1               device interrupt was serviced
50  *      0               no interrupts serviced
51  *
52  */
53 void
54 fore_intr(arg)
55         void    *arg;
56 {
57         Fore_unit       *fup = arg;
58         Aali    *aap;
59
60         /*
61          * Try to prevent stuff happening after we've paniced
62          */
63         if (panicstr)
64                 return;
65
66         /*
67          * Get to the microcode shared memory interface
68          */
69         if ((aap = fup->fu_aali) == NULL)
70                 return;
71
72         /*
73          * Has this card issued an interrupt??
74          */
75         if (*fup->fu_psr) {
76                 /*
77                  * Clear the device interrupt
78                  */
79                 switch (fup->fu_config.ac_device) {
80
81                 case DEV_FORE_PCA200E:
82                         PCA200E_HCR_SET(*fup->fu_ctlreg, PCA200E_CLR_HBUS_INT);
83                         break;
84                 default:
85                         panic("fore_intr: unknown device type");
86                 }
87                 aap->aali_intr_sent = CP_WRITE(0);
88
89                 /*
90                  * Reset the watchdog timer
91                  */
92                 fup->fu_timer = FORE_WATCHDOG;
93
94                 /*
95                  * Device initialization handled separately
96                  */
97                 if ((fup->fu_flags & CUF_INITED) == 0) {
98
99                         /*
100                          * We're just initializing device now, so see if
101                          * the initialization command has completed
102                          */
103                         if (CP_READ(aap->aali_init.init_status) & 
104                                                 QSTAT_COMPLETED)
105                                 fore_initialize_complete(fup);
106
107                         /*
108                          * If we're still not inited, none of the host
109                          * queues are setup yet
110                          */
111                         if ((fup->fu_flags & CUF_INITED) == 0)
112                                 return;
113                 }
114
115                 /*
116                  * Drain the queues of completed work
117                  */
118                 fore_cmd_drain(fup);
119                 fore_recv_drain(fup);
120                 fore_xmit_drain(fup);
121
122                 /*
123                  * Supply more buffers to the CP
124                  */
125                 fore_buf_supply(fup);
126         }
127 }
128
129
130 /*
131  * Watchdog timeout routine
132  * 
133  * Called when we haven't heard from the card in a while.  Just in case
134  * we missed an interrupt, we'll drain the queues and try to resupply the
135  * CP with more receive buffers.  If the CP is partially wedged, hopefully
136  * this will be enough to get it going again.
137  *
138  * Called with interrupts locked out.
139  *
140  * Arguments:
141  *      fup             pointer to device unit structure
142  *
143  * Returns:
144  *      none
145  *
146  */
147 void
148 fore_watchdog(fup)
149         Fore_unit       *fup;
150 {
151         /*
152          * Try to prevent stuff happening after we've paniced
153          */
154         if (panicstr) {
155                 return;
156         }
157
158         /*
159          * Reset the watchdog timer
160          */
161         fup->fu_timer = FORE_WATCHDOG;
162
163         /*
164          * If the device is initialized, nudge it (wink, wink)
165          */
166         if (fup->fu_flags & CUF_INITED) {
167
168                 /*
169                  * Drain the queues of completed work
170                  */
171                 fore_cmd_drain(fup);
172                 fore_recv_drain(fup);
173                 fore_xmit_drain(fup);
174
175                 /*
176                  * Supply more buffers to the CP
177                  */
178                 fore_buf_supply(fup);
179         }
180
181         return;
182 }