3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
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.
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.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/sys/dev/hea/eni_if.c,v 1.5 1999/08/28 00:41:44 peter Exp $
27 * @(#) $DragonFly: src/sys/dev/atm/hea/eni_if.c,v 1.6 2006/12/20 18:14:38 dillon Exp $
31 * Efficient ENI Adapter Support
32 * -----------------------------
34 * Network interface layer support
38 #include <netproto/atm/kern_include.h>
40 #include "eni_stats.h"
45 static void eni_get_stats (Eni_unit *);
48 * SUNI statistics counters take one of three forms:
49 * single byte value (0x0 - 0xff)
50 * two byte value (0x0 - 0xffff)
51 * two + 1/2 (three) byte value
54 #define READ_ONE(x) ( (eup->eu_suni[(x)] & 0xff) )
56 #define READ_TWO(x) ( (eup->eu_suni[(x)+1] & 0xff) << 8 | \
57 (eup->eu_suni[(x)] & 0xff) )
59 #define READ_THREE(x) ( (eup->eu_suni[(x)+2] & 0xf) << 16 | \
60 (eup->eu_suni[(x)+1] & 0xff) << 8 | \
61 (eup->eu_suni[(x)] & 0xff) )
64 * Do an initial read of the error counters without saving them.
65 * In effect, this will "zero" our idea of the number of errors
66 * which have occurred since the driver was loaded.
69 * eup pointer to per unit structure
76 eni_zero_stats ( eup )
82 * Write the SUNI master control register which
83 * will cause all the statistics counters to be
86 eup->eu_suni[SUNI_MASTER_REG] = eup->eu_suni[SUNI_MASTER_REG];
89 * Delay to allow for counter load time...
94 * Statistics counters contain the number of events
95 * since the last time the counter was read.
97 val = READ_TWO ( SUNI_SECT_BIP_REG ); /* oc3_sect_bip8 */
98 val = READ_TWO ( SUNI_PATH_BIP_REG ); /* oc3_path_bip8 */
99 val = READ_THREE ( SUNI_LINE_BIP_REG ); /* oc3_line_bip24 */
100 val = READ_THREE ( SUNI_LINE_FEBE_REG ); /* oc3_line_febe */
101 val = READ_TWO ( SUNI_PATH_FEBE_REG ); /* oc3_path_febe */
102 val = READ_ONE ( SUNI_HECS_REG ); /* oc3_hec_corr */
103 val = READ_ONE ( SUNI_UHECS_REG ); /* oc3_hec_uncorr */
107 * Retrieve SUNI stats
110 * eup pointer to per unit structure
117 eni_get_stats ( eup )
121 * Write the SUNI master control register which
122 * will cause all the statistics counters to be
125 eup->eu_suni[SUNI_MASTER_REG] = eup->eu_suni[SUNI_MASTER_REG];
128 * Delay to allow for counter load time...
133 * Statistics counters contain the number of events
134 * since the last time the counter was read.
136 eup->eu_stats.eni_st_oc3.oc3_sect_bip8 +=
137 READ_TWO ( SUNI_SECT_BIP_REG );
138 eup->eu_stats.eni_st_oc3.oc3_path_bip8 +=
139 READ_TWO ( SUNI_PATH_BIP_REG );
140 eup->eu_stats.eni_st_oc3.oc3_line_bip24 +=
141 READ_THREE ( SUNI_LINE_BIP_REG );
142 eup->eu_stats.eni_st_oc3.oc3_line_febe +=
143 READ_THREE ( SUNI_LINE_FEBE_REG );
144 eup->eu_stats.eni_st_oc3.oc3_path_febe +=
145 READ_TWO ( SUNI_PATH_FEBE_REG );
146 eup->eu_stats.eni_st_oc3.oc3_hec_corr +=
147 READ_ONE ( SUNI_HECS_REG );
148 eup->eu_stats.eni_st_oc3.oc3_hec_uncorr +=
149 READ_ONE ( SUNI_UHECS_REG );
153 * Handle netatm core service interface ioctl requests
158 * code ioctl function (sub)code
159 * data data to/from ioctl
160 * arg optional code-specific argument
163 * 0 request processed successfully
164 * error request failed - reason code
168 eni_atm_ioctl ( code, data, arg )
173 struct atminfreq *aip = (struct atminfreq *)data;
174 struct atm_pif *pip = (struct atm_pif *)arg;
175 Eni_unit *eup = (Eni_unit *)pip;
176 caddr_t buf = aip->air_buf_addr;
177 struct air_vinfo_rsp *avr;
178 int count, len, buf_len = aip->air_buf_len;
180 char ifname[2*IFNAMSIZ];
182 ATM_DEBUG2("eni_atm_ioctl: code=%d, opcode=%d\n",
183 code, aip->air_opcode );
185 switch ( aip->air_opcode ) {
189 * Get vendor statistics
193 ksnprintf ( ifname, sizeof(ifname),
194 "%s%d", pip->pif_name, pip->pif_unit );
197 * Cast response structure onto user's buffer
199 avr = (struct air_vinfo_rsp *)buf;
202 * How large is the response structure
204 len = sizeof(struct air_vinfo_rsp);
207 * Sanity check - enough room for response structure?
213 * Copy interface name into response structure
215 if ((err = copyout(ifname, avr->avsp_intf, IFNAMSIZ)) != 0)
219 * Advance the buffer address and decrement the size
225 * Get the vendor stats (SUNI) from the hardware
227 eni_get_stats ( eup );
229 * Stick as much of it as we have room for
232 count = MIN ( sizeof(Eni_stats), buf_len );
235 * Copy stats into user's buffer. Return value is
236 * amount of data copied.
238 if ((err = copyout((void *)&eup->eu_stats, buf, count)) != 0)
242 if ( count < sizeof(Eni_stats) )
246 * Record amount we're returning as vendor info...
248 if ((err = copyout(&count, &avr->avsp_len, sizeof(int))) != 0)
252 * Update the reply pointers and length
254 aip->air_buf_addr = buf;
255 aip->air_buf_len = buf_len;
259 err = ENOSYS; /* Operation not supported */