Initial import from FreeBSD RELENG_4:
[games.git] / sys / dev / atm / hea / eni_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/hea/eni_intr.c,v 1.4 1999/08/28 00:41:44 peter Exp $
27  *
28  */
29
30 /*
31  * Efficient ENI Adapter Support
32  * -----------------------------
33  *
34  * Interrupt processing
35  *
36  */
37
38 #include <netatm/kern_include.h>
39
40 #include <dev/hea/eni_stats.h>
41 #include <dev/hea/eni.h>
42 #include <dev/hea/eni_suni.h>
43 #include <dev/hea/eni_var.h>
44
45 #ifndef lint
46 __RCSID("@(#) $FreeBSD: src/sys/dev/hea/eni_intr.c,v 1.4 1999/08/28 00:41:44 peter Exp $");
47 #endif
48
49 static void     eni_suni_intr __P((Eni_unit *));
50
51 /*
52  * SUNI Interrupt processing
53  *
54  * Currently, we don't do anything more then clear the interrupt
55  * for the SUNI chip.
56  *
57  * Arguments:
58  *      eup             pointer to device unit structure
59  *
60  * Returns:
61  *      none
62  *
63  */
64 static void
65 eni_suni_intr ( eup )
66         Eni_unit *eup;
67 {
68         int     SuniInt;
69         int     val;
70
71         SuniInt = eup->eu_suni[SUNI_IS_REG];
72         
73         /* RSOPI */
74         if ( SuniInt & SUNI_RSOPI )
75                 val = eup->eu_suni[SUNI_RSOP_REG];
76
77         /* RLOPI */
78         if ( SuniInt & SUNI_RLOPI )
79                 val = eup->eu_suni[SUNI_RLOP_REG];
80
81         /* RPOPI */
82         if ( SuniInt & SUNI_RPOPI )
83                 val = eup->eu_suni[SUNI_RPOP_IS_REG];
84
85         /* RACPI */
86         if ( SuniInt & SUNI_RACPI )
87                 val = eup->eu_suni[SUNI_RACP_REG];
88
89         /* TACPI */
90         if ( SuniInt & SUNI_TACPI )
91                 val = eup->eu_suni[SUNI_TACP_REG];
92
93         /* TROOLI */
94         if ( SuniInt & SUNI_TROOLI )
95                 val = eup->eu_suni[SUNI_CLOCK_REG];
96
97         /* LCDI */
98                 /* Cleared when reading Master Interrupt Status Reg */
99
100         /* RDOOLI */
101         if ( SuniInt & SUNI_RDOOLI )
102                 val = eup->eu_suni[SUNI_CLOCK_REG];
103
104         return;
105 }
106
107 /*
108  * Device interrupt routine
109  *
110  * Service an interrupt from this device
111  *
112  * Arguments:
113  *      eup             pointer to device unit structure
114  *
115  * Returns:
116  *      none
117  *
118  */
119 #if defined(BSD) && BSD < 199506
120 int
121 #else
122 void
123 #endif
124 eni_intr ( arg )
125         void *arg;
126 {
127         Eni_unit        *eup = (Eni_unit *)arg;
128 #if defined(BSD) && BSD < 199506
129         int             serviced = 1;
130 #endif  /* BSD < 199506 */
131
132         /*
133          * Read and acknowledge any interrupts
134          */
135         u_long  mask = eup->eu_midway[MIDWAY_ISA];
136         /*
137          * Read the error statistics counter
138          */
139         u_long  sval = eup->eu_midway[MIDWAY_STAT];
140
141         /*
142          * Update statistics from adapter
143          */
144         eup->eu_trash += ( sval >> 16 );
145         eup->eu_ovfl += ( sval & 0xffff );
146
147         /*
148          * We handle any DMA completes first so
149          * that we can free resources for use
150          * during transmit and especially receive
151          */
152         /*
153          * Handle RX DMA Complete
154          */
155         if ( mask & ENI_INT_RX_DMA ) {
156                 eni_recv_drain ( eup );
157         }
158
159         /*
160          * Handle TX DMA Complete
161          */
162         if ( mask & ENI_INT_TX_DMA ) {
163                 eni_xmit_drain ( eup );
164         }
165
166         /*
167          * Look for any PDUs in service list
168          */
169         if ( mask & ENI_INT_SERVICE ) {
170                 eni_do_service ( eup );
171         }
172
173         /*
174          * Handle miscelaneous interrupts
175          */
176         if ( mask & ENI_INT_STAT ) {                    /* STAT_OVFL */
177                 log ( LOG_INFO, "eni_intr: stat_ovfl: 0x%lx\n", sval );
178         }
179         if ( mask & ENI_INT_SUNI ) {                    /* SUNI_INTR */
180                 eni_suni_intr ( eup );
181         }
182         if ( mask & ENI_INT_DMA_ERR ) {                 /* DMA Error */
183                 log ( LOG_ERR,
184                         "eni_intr: DMA Error\n" );
185                 /*
186                  * We don't know how to recover from DMA errors
187                  * yet. The adapter has disabled any further
188                  * processing and we're going to leave it like
189                  * that.
190                  */
191 #if defined(BSD) && BSD < 199506
192                 return serviced;                        /* Leave now */
193 #else
194                 return;                                 /* Leave now */
195 #endif
196         }
197         if ( mask & ENI_INT_IDEN ) {
198                 log ( LOG_ERR,
199                         "eni_intr: TX DMA Ident mismatch\n" );
200                 /*
201                  * Something in the TX buffer has really gotten messed
202                  * up. Since this is most likely a driver bug, and
203                  * the adapter has shut everything down, leave it
204                  * like that.
205                  */
206 #if BSD < 199506
207                 return 0;                               /* Leave now */
208 #else
209                 return;                                 /* Leave now */
210 #endif
211         }
212         if ( mask & ENI_INT_DMA_OVFL )
213                 eup->eu_stats.eni_st_drv.drv_xm_dmaovfl++;
214         if ( mask & ENI_INT_DMA_LERR ) {
215                 log ( LOG_ERR,
216                         "eni_intr: DMA LERR\n" );
217 #if BSD < 199506
218                 return 0;
219 #else
220                 return;
221 #endif
222         }
223
224 #if BSD < 199506
225         return 0;
226 #else
227         return;
228 #endif
229 }
230