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