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