Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / dev / atm / hea / eni_init.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_init.c,v 1.3 1999/08/28 00:41:44 peter Exp $
27  *
28  */
29
30 /*
31  * Efficient ENI Adapter Support
32  * -----------------------------
33  *
34  * Driver initialization support
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_var.h>
43
44 #ifndef lint
45 __RCSID("@(#) $FreeBSD: src/sys/dev/hea/eni_init.c,v 1.3 1999/08/28 00:41:44 peter Exp $");
46 #endif
47
48 /*
49  * Initialize adapter for PDU processing
50  *
51  * Enable interrupts, set master control, initialize TX buffer,
52  * set initial pointers, etc.
53  *
54  * Arguments:
55  *      eup             pointer to device unit structure
56  *
57  * Returns:
58  *      0               successful
59  *      error           error condition
60  */
61 int
62 eni_init ( eup )
63         Eni_unit *eup;
64 {
65         u_long  words, order;
66
67         /*
68          * Allocate one large TX buffer. Currently we use only one
69          * channel with full cell rate which all VCs will use.
70          * This will (probably) have to change (alot) when we
71          * implement QoS.
72          */
73         /*
74          * Server cards, which have more then 512KB of RAM, will
75          * allocate a 128KB TX buffer, while client cards, with
76          * 512KB or less will allocate a 32KB TX buffer.
77          */
78         words = ( eup->eu_ramsize > MAX_CLIENT_RAM * ENI_BUF_PGSZ ?
79                 TX_LARGE_BSIZE : TX_SMALL_BSIZE ) * ENI_BUF_PGSZ;
80         if ( ( eup->eu_txbuf = eni_allocate_buffer ( eup, &words ) ) ==
81             (caddr_t)NULL ) {
82                 return ENOMEM;
83         } 
84         eup->eu_txsize = words >> 2;            /* Bytes to words */
85         words >>= ENI_LOC_PREDIV;               /* Predivide by 256 words */
86         for ( order = -1; words; order++ )
87                 words >>= 1;
88         eup->eu_midway[MIDWAY_TXPLACE] =
89             (order << TXSIZE_SHIFT) | ((int)eup->eu_txbuf >> ENI_LOC_PREDIV);
90         eup->eu_txpos = eup->eu_midway[MIDWAY_DESCR] & 0x7FFF;
91         /*
92          * Set first word of unack'ed data to start
93          */
94         eup->eu_txfirst = eup->eu_txpos;
95         
96         /*
97          * Set initial values of local DMA pointer used to prevent wraps
98          */
99         eup->eu_txdmawr = 0;
100         eup->eu_rxdmawr = 0;
101
102         /*
103          * Initialize queue's for receive/transmit pdus
104          */
105         eup->eu_txqueue.ifq_maxlen = ENI_IFQ_MAXLEN;
106         eup->eu_rxqueue.ifq_maxlen = ENI_IFQ_MAXLEN;
107
108         /*
109          * Acknowledge any interrupts
110          */
111         (void) eup->eu_midway[MIDWAY_ISA];
112
113         /*
114          * "Zero" Sonet error counters
115          */
116         eni_zero_stats ( eup );
117
118         /*
119          * Set master control register
120          *
121          * IntSel1 | LOCK_MODE | DMA_ENABLE | TX_ENABLE | RX_ENABLE
122          *
123          */
124         eup->eu_midway[MIDWAY_MASTER] = 1 << ENI_ISEL_SHIFT |
125             ENI_M_DMAENABLE | ENI_M_TXENABLE | ENI_M_RXENABLE;
126
127         /*
128          * Enable interrupts
129          */
130         eup->eu_midway[MIDWAY_IE] = ENI_INT_SERVICE | ENI_INT_RX_DMA |
131                 ENI_INT_TX_DMA | ENI_INT_DMA_ERR | ENI_INT_DMA_LERR |
132                         ENI_INT_IDEN | ENI_INT_DMA_OVFL;
133
134         /*
135          * Last thing to do is to indicate that we've finished initializing
136          * this unit.
137          */
138         eup->eu_flags |= CUF_INITED;
139
140         return 0;
141 }
142