Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sbin / atm / atm / atm_eni.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/sbin/atm/atm/atm_eni.c,v 1.3.2.1 2000/07/01 06:02:14 ps Exp $
27  *
28  */
29
30 /*
31  * User configuration and display program
32  * --------------------------------------
33  *
34  * Routines for Efficient-specific subcommands
35  *
36  */
37
38 #include <sys/param.h>  
39 #include <sys/socket.h> 
40 #include <net/if.h>
41 #include <netinet/in.h>
42 #include <netatm/port.h>
43 #include <netatm/atm.h>
44 #include <netatm/atm_if.h> 
45 #include <netatm/atm_sap.h>
46 #include <netatm/atm_sys.h>
47 #include <netatm/atm_ioctl.h>
48 #include <dev/hea/eni_stats.h>
49
50 #include <errno.h>
51 #include <libatm.h>
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55
56 #include "atm.h"
57
58 #ifndef lint
59 __RCSID("@(#) $FreeBSD: src/sbin/atm/atm/atm_eni.c,v 1.3.2.1 2000/07/01 06:02:14 ps Exp $");
60 #endif
61
62
63 /*
64  * Local constants
65  */
66 #define SHOW_PHY        1
67 #define SHOW_ATM        2
68 #define SHOW_AAL0       4
69 #define SHOW_AAL5       8
70 #define SHOW_DRIVER     64
71
72
73 /*
74  * Headers for statistics
75  */
76 #define ATM_STATS_HDR \
77 "%s ATM Layer Statistics\n\
78   Cells In   Cells Out\n"
79
80 #define AAL0_STATS_HDR \
81 "%s AAL 0 Statistics\n\
82   Cells In   Cells Out  Cell Drops\n"
83
84 #define AAL5_STATS_HDR \
85 "%s AAL 5 Statistics\n\
86                         CRC/Len                              CRC   Proto  PDU\n\
87   Cells In   Cells Out  Errs   Drops    PDUs In   PDUs Out   Errs  Errs   Drops\n"
88
89 #define DRIVER_STATS_HDR_1 \
90 "%s Device Driver Statistics\n\
91   Buf    Buf    Buf    Buf  Can't    VCC    VCC     No     No  No RX     RX\n\
92   Req     No     No  Alrdy   Find    PDU  Range  Resrc     RX    DMA  Queue\n\
93  Size  Descr    Mem   Free  Descr   Size  Error     In   Bufs   Room   Full\n"
94
95 #define DRIVER_STATS_HDR_2 \
96 "%s Device Driver Statistics\n\
97    No    ATM  No RX  No TX    Seg           Max       No     No    No TX\n\
98    RX  IntrQ    DMA    DMA    Not    Seg    Seg       TX  Resrc      DMA\n\
99   VCC   Full   Room   Addr  Align    Pad    Out      Buf    Out     Room\n"
100
101 #define OC3_STATS_HDR \
102 "%s OC-3c Statistics\n\
103 Section     Path    Line      Line     Path     Corr   Uncorr\n\
104 BIP8        BIP8    BIP24     FEBE     FEBE     HCS    HCS\n\
105 Errs        Errs    Errs      Errs     Errs     Errs   Errs\n"
106
107
108 /*
109  * Process show ENI statistics command
110  *
111  * The statistics printed are vendor-specific, depending on the brand of
112  * the interface card.
113  * 
114  * Command format: 
115  *      atm show stats interface [<interface-name> [phy | dev | atm |
116                 aal0 | aal5 | driver ]]
117  *
118  * Arguments:
119  *      intf    interface to print statistics for
120  *      argc    number of remaining arguments to command
121  *      argv    pointer to remaining argument strings
122  *
123  * Returns:
124  *      none
125  *
126  */
127 void
128 show_eni_stats(intf, argc, argv)
129         char            *intf;
130         int             argc;
131         char            **argv;
132 {
133         int     buf_len, stats_type;
134         struct atminfreq        air;
135         struct air_vinfo_rsp    *stats;
136
137         /*
138          * Get statistics type qualifier
139          */
140         if (!strcasecmp("phy", argv[0])) {
141                 stats_type = SHOW_PHY;
142         } else if (!strcasecmp("atm", argv[0])) {
143                 stats_type = SHOW_ATM;
144         } else if (!strcasecmp("aal0", argv[0])) {
145                 stats_type = SHOW_AAL0;
146         } else if (!strcasecmp("aal5", argv[0])) {
147                 stats_type = SHOW_AAL5;
148         } else if (!strcasecmp("driver", argv[0])) {
149                 stats_type = SHOW_DRIVER;
150         } else {
151                 fprintf(stderr, "%s: Illegal or unsupported statistics type\n", prog);
152                 exit(1);
153         }
154         argc--; argv++;
155
156         /*
157          * Get vendor-specific statistics from the kernel
158          */
159         UM_ZERO(&air, sizeof(air));
160         air.air_opcode = AIOCS_INF_VST;
161         strcpy(air.air_vinfo_intf, intf);
162         buf_len = do_info_ioctl(&air, sizeof(struct air_vinfo_rsp) + 1024);
163         if (buf_len < 0) {
164                 fprintf(stderr, "%s: ", prog);
165                 switch (errno) {
166                 case ENOPROTOOPT:
167                 case EOPNOTSUPP:
168                         perror("Internal error");
169                         break;
170                 case ENXIO:
171                         fprintf(stderr, "%s is not an ATM device\n",
172                                         intf);
173                         break;
174                 default:
175                         perror("ioctl (AIOCINFO)");
176                         break;
177                 }
178                 exit(1);
179         }
180         stats = (struct air_vinfo_rsp *) air.air_buf_addr;
181
182         /*
183          * Print the statistics
184          */
185         if (buf_len < sizeof(struct air_vinfo_rsp) +
186                         sizeof(Eni_stats)) {
187                 UM_FREE(stats);
188                 return;
189         }
190
191         switch (stats_type) {
192         case SHOW_PHY:
193                 print_eni_oc3(stats);
194                 break;
195         case SHOW_ATM:
196                 print_eni_atm(stats);
197                 break;
198         case SHOW_AAL0:
199                 print_eni_aal0(stats);
200                 break;
201         case SHOW_AAL5:
202                 print_eni_aal5(stats);
203                 break;
204         case SHOW_DRIVER:
205                 print_eni_driver(stats);
206                 break;
207         }
208
209         UM_FREE(stats);
210 }
211
212
213 /*
214  * Print ENI OC-3c statistics
215  * 
216  * Arguments:
217  *      vi      pointer to vendor-specific statistics to print
218  *
219  * Returns:
220  *      none
221  *
222  */
223 void
224 print_eni_oc3(vi)
225         struct air_vinfo_rsp    *vi;
226 {
227         Eni_stats       *stats;
228
229         /*
230          * Bump stats pointer past header info
231          */
232         stats = (Eni_stats *)
233                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
234
235         /*
236          * Print a header
237          */
238         printf(OC3_STATS_HDR, get_adapter_name(vi->avsp_intf));
239         
240         /*
241          * Print the OC-3c info
242          */
243         printf("%7ld  %7ld  %7ld  %7ld  %7ld  %7ld  %7ld\n",
244                         stats->eni_st_oc3.oc3_sect_bip8,
245                         stats->eni_st_oc3.oc3_path_bip8,
246                         stats->eni_st_oc3.oc3_line_bip24,
247                         stats->eni_st_oc3.oc3_line_febe,
248                         stats->eni_st_oc3.oc3_path_febe,
249                         stats->eni_st_oc3.oc3_hec_corr,
250                         stats->eni_st_oc3.oc3_hec_uncorr);
251 }
252
253
254 /*
255  * Print ENI ATM statistics
256  * 
257  * Arguments:
258  *      vi      pointer to vendor-specific statistics to print
259  *
260  * Returns:
261  *      none
262  *
263  */
264 void
265 print_eni_atm(vi)
266         struct air_vinfo_rsp    *vi;
267 {
268         Eni_stats       *stats;
269
270         /*
271          * Bump stats pointer past header info
272          */
273         stats = (Eni_stats *)
274                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
275
276         /*
277          * Print a header
278          */
279         printf(ATM_STATS_HDR, get_adapter_name(vi->avsp_intf));
280         
281         /*
282          * Print the ATM layer info
283          */
284         printf("%10ld  %10ld\n",
285                         stats->eni_st_atm.atm_rcvd,
286                         stats->eni_st_atm.atm_xmit);
287 }
288
289
290 /*
291  * Print ENI AAL 0 statistics
292  * 
293  * Arguments:
294  *      vi      pointer to vendor-specific statistics to print
295  *
296  * Returns:
297  *      none
298  *
299  */
300 void
301 print_eni_aal0(vi)
302         struct air_vinfo_rsp    *vi;
303 {
304         Eni_stats       *stats;
305
306         /*
307          * Bump stats pointer past header info
308          */
309         stats = (Eni_stats *)
310                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
311
312         /*
313          * Print a header
314          */
315         printf(AAL0_STATS_HDR, get_adapter_name(vi->avsp_intf));
316         
317         /*
318          * Print the AAL 0 info
319          */
320         printf("%10ld  %10ld  %10ld\n",
321                         stats->eni_st_aal0.aal0_rcvd,
322                         stats->eni_st_aal0.aal0_xmit,
323                         stats->eni_st_aal0.aal0_drops);
324 }
325
326
327 /*
328  * Print ENI AAL 5 statistics
329  * 
330  * Arguments:
331  *      vi      pointer to vendor-specific statistics to print
332  *
333  * Returns:
334  *      none
335  *
336  */
337 void
338 print_eni_aal5(vi)
339         struct air_vinfo_rsp    *vi;
340 {
341         Eni_stats       *stats;
342
343         /*
344          * Bump stats pointer past header info
345          */
346         stats = (Eni_stats *)
347                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
348
349         /*
350          * Print a header
351          */
352         printf(AAL5_STATS_HDR, get_adapter_name(vi->avsp_intf));
353         
354         /*
355          * Print the AAL 5 info
356          */
357         printf("%10ld  %10ld  %5ld  %5ld  %9ld  %9ld  %5ld  %5ld  %5ld\n",
358                         stats->eni_st_aal5.aal5_rcvd,
359                         stats->eni_st_aal5.aal5_xmit,
360                         stats->eni_st_aal5.aal5_crc_len,
361                         stats->eni_st_aal5.aal5_drops,
362                         stats->eni_st_aal5.aal5_pdu_rcvd,
363                         stats->eni_st_aal5.aal5_pdu_xmit,
364                         stats->eni_st_aal5.aal5_pdu_crc,
365                         stats->eni_st_aal5.aal5_pdu_errs,
366                         stats->eni_st_aal5.aal5_pdu_drops);
367 }
368
369 /*
370  * Print Efficient device driver statistics
371  *
372  * Arguments:
373  *      vi      pointer to vendor-specific statistics to print
374  *
375  * Returns:
376  *      none
377  *
378  */
379 void
380 print_eni_driver(vi)
381         struct air_vinfo_rsp    *vi;
382 {
383         Eni_stats       *stats;
384
385         /*
386          * Bump stats pointer past header info
387          */
388         stats = (Eni_stats *)
389                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
390
391         /*
392          * Print 1st header
393          */
394         printf(DRIVER_STATS_HDR_1, get_adapter_name(vi->avsp_intf));
395
396         /*
397          * Print the driver info
398          */
399         printf ( "%5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %5ld\n",
400                 stats->eni_st_drv.drv_mm_toobig,
401                 stats->eni_st_drv.drv_mm_nodesc,
402                 stats->eni_st_drv.drv_mm_nobuf,
403                 stats->eni_st_drv.drv_mm_notuse,
404                 stats->eni_st_drv.drv_mm_notfnd,
405                 stats->eni_st_drv.drv_vc_maxpdu,
406                 stats->eni_st_drv.drv_vc_badrng,
407                 stats->eni_st_drv.drv_rv_norsc,
408                 stats->eni_st_drv.drv_rv_nobufs,
409                 stats->eni_st_drv.drv_rv_nodma,
410                 stats->eni_st_drv.drv_rv_rxq
411         );
412
413         /*
414          * Print 2nd header
415          */
416         printf(DRIVER_STATS_HDR_2, get_adapter_name(vi->avsp_intf));
417
418         /*
419          * Print the driver info
420          */
421         printf ( "%5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %7ld  %5ld  %7ld\n",
422                 stats->eni_st_drv.drv_rv_novcc,
423                 stats->eni_st_drv.drv_rv_intrq,
424                 stats->eni_st_drv.drv_rv_segdma,
425                 stats->eni_st_drv.drv_xm_segdma,
426                 stats->eni_st_drv.drv_xm_segnoal,
427                 stats->eni_st_drv.drv_xm_seglen,
428                 stats->eni_st_drv.drv_xm_maxpdu,
429                 stats->eni_st_drv.drv_xm_nobuf,
430                 stats->eni_st_drv.drv_xm_norsc,
431                 stats->eni_st_drv.drv_xm_nodma
432         );
433
434
435 }
436