Also install the pam_tacplus(8) man page.
[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.4 2003/09/28 14:39:16 hmp 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/atm/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(char *intf, int argc, char **argv)
124 {
125         int     buf_len, stats_type;
126         struct atminfreq        air;
127         struct air_vinfo_rsp    *stats;
128
129         /*
130          * Get statistics type qualifier
131          */
132         if (!strcasecmp("phy", argv[0])) {
133                 stats_type = SHOW_PHY;
134         } else if (!strcasecmp("atm", argv[0])) {
135                 stats_type = SHOW_ATM;
136         } else if (!strcasecmp("aal0", argv[0])) {
137                 stats_type = SHOW_AAL0;
138         } else if (!strcasecmp("aal5", argv[0])) {
139                 stats_type = SHOW_AAL5;
140         } else if (!strcasecmp("driver", argv[0])) {
141                 stats_type = SHOW_DRIVER;
142         } else {
143                 fprintf(stderr, "%s: Illegal or unsupported statistics type\n", prog);
144                 exit(1);
145         }
146         argc--; argv++;
147
148         /*
149          * Get vendor-specific statistics from the kernel
150          */
151         UM_ZERO(&air, sizeof(air));
152         air.air_opcode = AIOCS_INF_VST;
153         strcpy(air.air_vinfo_intf, intf);
154         buf_len = do_info_ioctl(&air, sizeof(struct air_vinfo_rsp) + 1024);
155         if (buf_len < 0) {
156                 fprintf(stderr, "%s: ", prog);
157                 switch (errno) {
158                 case ENOPROTOOPT:
159                 case EOPNOTSUPP:
160                         perror("Internal error");
161                         break;
162                 case ENXIO:
163                         fprintf(stderr, "%s is not an ATM device\n",
164                                         intf);
165                         break;
166                 default:
167                         perror("ioctl (AIOCINFO)");
168                         break;
169                 }
170                 exit(1);
171         }
172         stats = (struct air_vinfo_rsp *) air.air_buf_addr;
173
174         /*
175          * Print the statistics
176          */
177         if (buf_len < sizeof(struct air_vinfo_rsp) +
178                         sizeof(Eni_stats)) {
179                 UM_FREE(stats);
180                 return;
181         }
182
183         switch (stats_type) {
184         case SHOW_PHY:
185                 print_eni_oc3(stats);
186                 break;
187         case SHOW_ATM:
188                 print_eni_atm(stats);
189                 break;
190         case SHOW_AAL0:
191                 print_eni_aal0(stats);
192                 break;
193         case SHOW_AAL5:
194                 print_eni_aal5(stats);
195                 break;
196         case SHOW_DRIVER:
197                 print_eni_driver(stats);
198                 break;
199         }
200
201         UM_FREE(stats);
202 }
203
204
205 /*
206  * Print ENI OC-3c statistics
207  * 
208  * Arguments:
209  *      vi      pointer to vendor-specific statistics to print
210  *
211  * Returns:
212  *      none
213  *
214  */
215 void
216 print_eni_oc3(struct air_vinfo_rsp *vi)
217 {
218         Eni_stats       *stats;
219
220         /*
221          * Bump stats pointer past header info
222          */
223         stats = (Eni_stats *)
224                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
225
226         /*
227          * Print a header
228          */
229         printf(OC3_STATS_HDR, get_adapter_name(vi->avsp_intf));
230         
231         /*
232          * Print the OC-3c info
233          */
234         printf("%7ld  %7ld  %7ld  %7ld  %7ld  %7ld  %7ld\n",
235                         stats->eni_st_oc3.oc3_sect_bip8,
236                         stats->eni_st_oc3.oc3_path_bip8,
237                         stats->eni_st_oc3.oc3_line_bip24,
238                         stats->eni_st_oc3.oc3_line_febe,
239                         stats->eni_st_oc3.oc3_path_febe,
240                         stats->eni_st_oc3.oc3_hec_corr,
241                         stats->eni_st_oc3.oc3_hec_uncorr);
242 }
243
244
245 /*
246  * Print ENI ATM statistics
247  * 
248  * Arguments:
249  *      vi      pointer to vendor-specific statistics to print
250  *
251  * Returns:
252  *      none
253  *
254  */
255 void
256 print_eni_atm(struct air_vinfo_rsp *vi)
257 {
258         Eni_stats       *stats;
259
260         /*
261          * Bump stats pointer past header info
262          */
263         stats = (Eni_stats *)
264                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
265
266         /*
267          * Print a header
268          */
269         printf(ATM_STATS_HDR, get_adapter_name(vi->avsp_intf));
270         
271         /*
272          * Print the ATM layer info
273          */
274         printf("%10ld  %10ld\n",
275                         stats->eni_st_atm.atm_rcvd,
276                         stats->eni_st_atm.atm_xmit);
277 }
278
279
280 /*
281  * Print ENI AAL 0 statistics
282  * 
283  * Arguments:
284  *      vi      pointer to vendor-specific statistics to print
285  *
286  * Returns:
287  *      none
288  *
289  */
290 void
291 print_eni_aal0(struct air_vinfo_rsp *vi)
292 {
293         Eni_stats       *stats;
294
295         /*
296          * Bump stats pointer past header info
297          */
298         stats = (Eni_stats *)
299                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
300
301         /*
302          * Print a header
303          */
304         printf(AAL0_STATS_HDR, get_adapter_name(vi->avsp_intf));
305         
306         /*
307          * Print the AAL 0 info
308          */
309         printf("%10ld  %10ld  %10ld\n",
310                         stats->eni_st_aal0.aal0_rcvd,
311                         stats->eni_st_aal0.aal0_xmit,
312                         stats->eni_st_aal0.aal0_drops);
313 }
314
315
316 /*
317  * Print ENI AAL 5 statistics
318  * 
319  * Arguments:
320  *      vi      pointer to vendor-specific statistics to print
321  *
322  * Returns:
323  *      none
324  *
325  */
326 void
327 print_eni_aal5(struct air_vinfo_rsp *vi)
328 {
329         Eni_stats       *stats;
330
331         /*
332          * Bump stats pointer past header info
333          */
334         stats = (Eni_stats *)
335                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
336
337         /*
338          * Print a header
339          */
340         printf(AAL5_STATS_HDR, get_adapter_name(vi->avsp_intf));
341         
342         /*
343          * Print the AAL 5 info
344          */
345         printf("%10ld  %10ld  %5ld  %5ld  %9ld  %9ld  %5ld  %5ld  %5ld\n",
346                         stats->eni_st_aal5.aal5_rcvd,
347                         stats->eni_st_aal5.aal5_xmit,
348                         stats->eni_st_aal5.aal5_crc_len,
349                         stats->eni_st_aal5.aal5_drops,
350                         stats->eni_st_aal5.aal5_pdu_rcvd,
351                         stats->eni_st_aal5.aal5_pdu_xmit,
352                         stats->eni_st_aal5.aal5_pdu_crc,
353                         stats->eni_st_aal5.aal5_pdu_errs,
354                         stats->eni_st_aal5.aal5_pdu_drops);
355 }
356
357 /*
358  * Print Efficient device driver statistics
359  *
360  * Arguments:
361  *      vi      pointer to vendor-specific statistics to print
362  *
363  * Returns:
364  *      none
365  *
366  */
367 void
368 print_eni_driver(struct air_vinfo_rsp *vi)
369 {
370         Eni_stats       *stats;
371
372         /*
373          * Bump stats pointer past header info
374          */
375         stats = (Eni_stats *)
376                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
377
378         /*
379          * Print 1st header
380          */
381         printf(DRIVER_STATS_HDR_1, get_adapter_name(vi->avsp_intf));
382
383         /*
384          * Print the driver info
385          */
386         printf ( "%5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %5ld\n",
387                 stats->eni_st_drv.drv_mm_toobig,
388                 stats->eni_st_drv.drv_mm_nodesc,
389                 stats->eni_st_drv.drv_mm_nobuf,
390                 stats->eni_st_drv.drv_mm_notuse,
391                 stats->eni_st_drv.drv_mm_notfnd,
392                 stats->eni_st_drv.drv_vc_maxpdu,
393                 stats->eni_st_drv.drv_vc_badrng,
394                 stats->eni_st_drv.drv_rv_norsc,
395                 stats->eni_st_drv.drv_rv_nobufs,
396                 stats->eni_st_drv.drv_rv_nodma,
397                 stats->eni_st_drv.drv_rv_rxq
398         );
399
400         /*
401          * Print 2nd header
402          */
403         printf(DRIVER_STATS_HDR_2, get_adapter_name(vi->avsp_intf));
404
405         /*
406          * Print the driver info
407          */
408         printf ( "%5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %5ld  %7ld  %5ld  %7ld\n",
409                 stats->eni_st_drv.drv_rv_novcc,
410                 stats->eni_st_drv.drv_rv_intrq,
411                 stats->eni_st_drv.drv_rv_segdma,
412                 stats->eni_st_drv.drv_xm_segdma,
413                 stats->eni_st_drv.drv_xm_segnoal,
414                 stats->eni_st_drv.drv_xm_seglen,
415                 stats->eni_st_drv.drv_xm_maxpdu,
416                 stats->eni_st_drv.drv_xm_nobuf,
417                 stats->eni_st_drv.drv_xm_norsc,
418                 stats->eni_st_drv.drv_xm_nodma
419         );
420
421
422 }
423