WARNS6 cleanups.
[dragonfly.git] / sbin / atm / atm / atm_fore200.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_fore200.c,v 1.3.2.1 2000/07/01 06:02:14 ps Exp $
27  *      @(#) $DragonFly: src/sbin/atm/atm/atm_fore200.c,v 1.5 2006/10/16 00:15:35 pavalos Exp $
28  */
29
30 /*
31  * User configuration and display program
32  * --------------------------------------
33  *
34  * Routines for Fore SBA-200-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/hfa/fore_aali.h>
49 #include <dev/atm/hfa/fore_slave.h>
50 #include <dev/atm/hfa/fore_stats.h>
51
52 #include <errno.h>
53 #include <libatm.h>
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57
58 #include "atm.h"
59
60 /*
61  * Local constants
62  */
63 #define SHOW_PHY        1
64 #define SHOW_DEV        2
65 #define SHOW_ATM        4
66 #define SHOW_AAL0       8
67 #define SHOW_AAL4       16
68 #define SHOW_AAL5       32
69 #define SHOW_DRIVER     64
70
71
72 /*
73  * Headers for statistics
74  */
75 #define TAXI_STATS_HDR \
76 "%s TAXI Statistics\n\
77   CRC Errs  Framing Errs\n"
78
79 #define DEV_STATS_HDR \
80 "%s Device Statistics\n\
81 Type 1      Type 1      Type 2      Type 2\n\
82 Small Buff  Large Buff  Small Buff  Large Buff  Receive     Receive\n\
83 Alloc Fail  Alloc Fail  Alloc Fail  Alloc Fail  Queue Full  Carrier\n"
84
85 #define ATM_STATS_HDR \
86 "%s ATM Layer Statistics\n\
87   Cells In   Cells Out   VPI Range  VPI NoConn   VCI Range  VCI NoConn\n"
88
89 #define AAL0_STATS_HDR \
90 "%s AAL 0 Statistics\n\
91   Cells In   Cells Out  Cell Drops\n"
92
93 #define AAL4_STATS_HDR \
94 "%s AAL 4 Statistics\n\
95                          CRC   Proto  Cell                          PDU   PDU\n\
96   Cells In   Cells Out   Errs  Errs   Drops    PDUs In   PDUs Out   Errs  Drops\n"
97
98 #define AAL5_STATS_HDR \
99 "%s AAL 5 Statistics\n\
100                         CRC/Len                              CRC   Proto  PDU\n\
101   Cells In   Cells Out  Errs   Drops    PDUs In   PDUs Out   Errs  Errs   Drops\n"
102
103 #define DRIVER_STATS_HDR \
104 "%s Device Driver Statistics\n\
105   No  Xmit   Max   Seg          No    No          No    IQ    No   Cmd    No\n\
106  VCC Queue   Seg   Not   Seg   DMA   VCC    No  Mbuf  Full   DMA Queue   DMA\n\
107  Out  Full  Size Align   Pad   Out    In  Buff    In    In   Sup  Full   Cmd\n"
108
109 #define OC3_STATS_HDR \
110 "%s OC-3c Statistics\n\
111 Section     Path    Line      Line     Path     Corr   Uncorr\n\
112 BIP8        BIP8    BIP24     FEBE     FEBE     HCS    HCS\n\
113 Errs        Errs    Errs      Errs     Errs     Errs   Errs\n"
114
115 static void     print_fore200_taxi(struct air_vinfo_rsp *);
116 static void     print_fore200_oc3(struct air_vinfo_rsp *);
117 static void     print_fore200_dev(struct air_vinfo_rsp *);
118 static void     print_fore200_atm(struct air_vinfo_rsp *);
119 static void     print_fore200_aal0(struct air_vinfo_rsp *);
120 static void     print_fore200_aal4(struct air_vinfo_rsp *);
121 static void     print_fore200_aal5(struct air_vinfo_rsp *);
122 static void     print_fore200_driver(struct air_vinfo_rsp *);
123
124 /*
125  * Process show Fore SBA-200 statistics command
126  *
127  * The statistics printed are vendor-specific, depending on the brand of
128  * the interface card.
129  * 
130  * Command format: 
131  *      atm show stats interface [<interface-name> [phy | dev | atm |
132  *              aal0 | aal4 | aal5 | driver]]
133  *
134  * Arguments:
135  *      intf    interface statistics are for
136  *      argc    number of remaining arguments to command
137  *      argv    pointer to remaining argument strings
138  *
139  * Returns:
140  *      none
141  *
142  */
143 void
144 show_fore200_stats(char *intf, int argc, char **argv)
145 {
146         int                     buf_len, stats_type;
147         struct air_cfg_rsp      *cfg;
148         struct air_vinfo_rsp    *stats;
149         struct atminfreq        air;
150
151         /*
152          * Get statistics type qualifier
153          */
154         if (!strcasecmp("phy", argv[0])) {
155                 stats_type = SHOW_PHY;
156         } else if (!strcasecmp("dev", argv[0])) {
157                 stats_type = SHOW_DEV;
158         } else if (!strcasecmp("atm", argv[0])) {
159                 stats_type = SHOW_ATM;
160         } else if (!strcasecmp("aal0", argv[0])) {
161                 stats_type = SHOW_AAL0;
162         } else if (!strcasecmp("aal4", argv[0])) {
163                 stats_type = SHOW_AAL4;
164         } else if (!strcasecmp("aal5", argv[0])) {
165                 stats_type = SHOW_AAL5;
166         } else if (!strcasecmp("driver", argv[0])) {
167                 stats_type = SHOW_DRIVER;
168         } else {
169                 fprintf(stderr, "%s: Illegal statistics type\n", prog);
170                 exit(1);
171         }
172         argc--; argv++;
173
174         /*
175          * Get adapter configuration from the kernel
176          */
177         UM_ZERO(&air, sizeof(air));
178         air.air_opcode = AIOCS_INF_CFG;
179         strcpy(air.air_cfg_intf, intf);
180         buf_len = do_info_ioctl(&air, sizeof(struct air_cfg_rsp));
181         if (buf_len < 0) {
182                 fprintf(stderr, "%s: ", prog);
183                 switch (errno) {
184                 case ENOPROTOOPT:
185                 case EOPNOTSUPP:
186                         perror("Internal error");
187                         break;
188                 case ENXIO:
189                         fprintf(stderr, "%s is not an ATM device\n",
190                                         intf);
191                         break;
192                 default:
193                         perror("ioctl (AIOCINFO)");
194                         break;
195                 }
196                 exit(1);
197         }
198         cfg = (struct air_cfg_rsp *) air.air_buf_addr;
199
200         /*
201          * Get vendor-specific statistics from the kernel
202          */
203         UM_ZERO(&air, sizeof(air));
204         air.air_opcode = AIOCS_INF_VST;
205         strcpy(air.air_vinfo_intf, intf);
206         buf_len = do_info_ioctl(&air, sizeof(struct air_vinfo_rsp) + 1024);
207         if (buf_len < 0) {
208                 fprintf(stderr, "%s: ", prog);
209                 switch (errno) {
210                 case ENOPROTOOPT:
211                 case EOPNOTSUPP:
212                         perror("Internal error");
213                         break;
214                 case ENXIO:
215                         fprintf(stderr, "%s is not an ATM device\n",
216                                         intf);
217                         break;
218                 default:
219                         perror("ioctl (AIOCINFO)");
220                         break;
221                 }
222                 exit(1);
223         }
224         stats = (struct air_vinfo_rsp *) air.air_buf_addr;
225
226         /*
227          * Print the statistics
228          */
229         if ((size_t)buf_len < sizeof(struct air_vinfo_rsp) +
230                         sizeof(Fore_stats)) {
231                 UM_FREE(stats);
232                 UM_FREE(cfg);
233                 return;
234         }
235
236         switch (stats_type) {
237         case SHOW_PHY:
238                 switch (cfg->acp_media) {
239                 case MEDIA_TAXI_100:
240                 case MEDIA_TAXI_140:
241                         print_fore200_taxi(stats);
242                         break;
243                 case MEDIA_OC3C:
244                         print_fore200_oc3(stats);
245                         break;
246                 case MEDIA_OC12C:
247                         break;
248                 default:
249                         break;
250                 }
251                 break;
252         case SHOW_DEV:
253                 print_fore200_dev(stats);
254                 break;
255         case SHOW_ATM:
256                 print_fore200_atm(stats);
257                 break;
258         case SHOW_AAL0:
259                 print_fore200_aal0(stats);
260                 break;
261         case SHOW_AAL4:
262                 print_fore200_aal4(stats);
263                 break;
264         case SHOW_AAL5:
265                 print_fore200_aal5(stats);
266                 break;
267         case SHOW_DRIVER:
268                 print_fore200_driver(stats);
269                 break;
270         }
271
272         UM_FREE(stats);
273         UM_FREE(cfg);
274 }
275
276
277 /*
278  * Print Fore ASX-200 TAXI statistics
279  * 
280  * Arguments:
281  *      vi      pointer to vendor-specific statistics to print
282  *
283  * Returns:
284  *      none
285  *
286  */
287 static void
288 print_fore200_taxi(struct air_vinfo_rsp *vi)
289 {
290         Fore_stats      *stats;
291
292         /*
293          * Bump stats pointer past header info
294          */
295         stats = (Fore_stats *) 
296                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
297
298         /*
299          * Print a header
300          */
301         printf(TAXI_STATS_HDR, get_adapter_name(vi->avsp_intf));
302         
303         /*
304          * Print the physical layer info
305          */
306         printf("%10ld  %12ld\n",
307                         stats->st_taxi.taxi_bad_crc,
308                         stats->st_taxi.taxi_framing);
309 }
310
311
312 /*
313  * Print Fore ASX-200 OC-3c statistics
314  * 
315  * Arguments:
316  *      vi      pointer to vendor-specific statistics to print
317  *
318  * Returns:
319  *      none
320  *
321  */
322 static void
323 print_fore200_oc3(struct air_vinfo_rsp *vi)
324 {
325         Fore_stats      *stats;
326
327         /*
328          * Bump stats pointer past header info
329          */
330         stats = (Fore_stats *)
331                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
332
333         /*
334          * Print a header
335          */
336         printf(OC3_STATS_HDR, get_adapter_name(vi->avsp_intf));
337         
338         /*
339          * Print the OC-3c info
340          */
341         printf("%7ld  %7ld  %7ld  %7ld  %7ld  %7ld  %7ld\n",
342                         stats->st_oc3.oc3_sect_bip8,
343                         stats->st_oc3.oc3_path_bip8,
344                         stats->st_oc3.oc3_line_bip24,
345                         stats->st_oc3.oc3_line_febe,
346                         stats->st_oc3.oc3_path_febe,
347                         stats->st_oc3.oc3_hec_corr,
348                         stats->st_oc3.oc3_hec_uncorr);
349 }
350
351
352 /*
353  * Print Fore ASX-200 device statistics
354  * 
355  * Arguments:
356  *      vi      pointer to vendor-specific statistics to print
357  *
358  * Returns:
359  *      none
360  *
361  */
362 static void
363 print_fore200_dev(struct air_vinfo_rsp *vi)
364 {
365         Fore_stats      *stats;
366
367         /*
368          * Bump stats pointer past header info
369          */
370         stats = (Fore_stats *)
371                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
372
373         /*
374          * Print a header
375          */
376         printf(DEV_STATS_HDR, get_adapter_name(vi->avsp_intf));
377         
378         /*
379          * Print the device info
380          */
381         printf("%10ld  %10ld  %10ld  %10ld  %10ld  %s\n",
382                         stats->st_misc.buf1_sm_fail,
383                         stats->st_misc.buf1_lg_fail,
384                         stats->st_misc.buf2_sm_fail,
385                         stats->st_misc.buf2_lg_fail,
386                         stats->st_misc.rcvd_pdu_fail,
387                         (stats->st_misc.carrier_status ? "On" : "Off"));
388 }
389
390
391 /*
392  * Print Fore ASX-200 ATM statistics
393  * 
394  * Arguments:
395  *      vi      pointer to vendor-specific statistics to print
396  *
397  * Returns:
398  *      none
399  *
400  */
401 static void
402 print_fore200_atm(struct air_vinfo_rsp *vi)
403 {
404         Fore_stats      *stats;
405
406         /*
407          * Bump stats pointer past header info
408          */
409         stats = (Fore_stats *)
410                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
411
412         /*
413          * Print a header
414          */
415         printf(ATM_STATS_HDR, get_adapter_name(vi->avsp_intf));
416         
417         /*
418          * Print the ATM layer info
419          */
420         printf("%10ld  %10ld  %10ld  %10ld  %10ld  %10ld\n",
421                         stats->st_atm.atm_rcvd,
422                         stats->st_atm.atm_xmit,
423                         stats->st_atm.atm_vpi_range,
424                         stats->st_atm.atm_vpi_noconn,
425                         stats->st_atm.atm_vci_range,
426                         stats->st_atm.atm_vci_noconn);
427 }
428
429
430 /*
431  * Print Fore ASX-200 AAL 0 statistics
432  * 
433  * Arguments:
434  *      vi      pointer to vendor-specific statistics to print
435  *
436  * Returns:
437  *      none
438  *
439  */
440 static void
441 print_fore200_aal0(struct air_vinfo_rsp *vi)
442 {
443         Fore_stats      *stats;
444
445         /*
446          * Bump stats pointer past header info
447          */
448         stats = (Fore_stats *)
449                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
450
451         /*
452          * Print a header
453          */
454         printf(AAL0_STATS_HDR, get_adapter_name(vi->avsp_intf));
455         
456         /*
457          * Print the AAL 0 info
458          */
459         printf("%10ld  %10ld  %10ld\n",
460                         stats->st_aal0.aal0_rcvd,
461                         stats->st_aal0.aal0_xmit,
462                         stats->st_aal0.aal0_drops);
463 }
464
465
466 /*
467  * Print Fore ASX-200 AAL 4 statistics
468  * 
469  * Arguments:
470  *      vi      pointer to vendor-specific statistics to print
471  *
472  * Returns:
473  *      none
474  *
475  */
476 static void
477 print_fore200_aal4(struct air_vinfo_rsp *vi)
478 {
479         Fore_stats      *stats;
480
481         /*
482          * Bump stats pointer past header info
483          */
484         stats = (Fore_stats *)
485                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
486
487         /*
488          * Print a header
489          */
490         printf(AAL4_STATS_HDR, get_adapter_name(vi->avsp_intf));
491         
492         /*
493          * Print the AAL 4 info
494          */
495         printf("%10ld  %10ld  %5ld  %5ld  %5ld  %9ld  %9ld  %5ld  %5ld\n",
496                         stats->st_aal4.aal4_rcvd,
497                         stats->st_aal4.aal4_xmit,
498                         stats->st_aal4.aal4_crc,
499                         stats->st_aal4.aal4_sar_cs,
500                         stats->st_aal4.aal4_drops,
501                         stats->st_aal4.aal4_pdu_rcvd,
502                         stats->st_aal4.aal4_pdu_xmit,
503                         stats->st_aal4.aal4_pdu_errs,
504                         stats->st_aal4.aal4_pdu_drops);
505 }
506
507
508 /*
509  * Print Fore ASX-200 AAL 5 statistics
510  * 
511  * Arguments:
512  *      vi      pointer to vendor-specific statistics to print
513  *
514  * Returns:
515  *      none
516  *
517  */
518 static void
519 print_fore200_aal5(struct air_vinfo_rsp *vi)
520 {
521         Fore_stats      *stats;
522
523         /*
524          * Bump stats pointer past header info
525          */
526         stats = (Fore_stats *)
527                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
528
529         /*
530          * Print a header
531          */
532         printf(AAL5_STATS_HDR, get_adapter_name(vi->avsp_intf));
533         
534         /*
535          * Print the AAL 5 info
536          */
537         printf("%10ld  %10ld  %5ld  %5ld  %9ld  %9ld  %5ld  %5ld  %5ld\n",
538                         stats->st_aal5.aal5_rcvd,
539                         stats->st_aal5.aal5_xmit,
540                         stats->st_aal5.aal5_crc_len,
541                         stats->st_aal5.aal5_drops,
542                         stats->st_aal5.aal5_pdu_rcvd,
543                         stats->st_aal5.aal5_pdu_xmit,
544                         stats->st_aal5.aal5_pdu_crc,
545                         stats->st_aal5.aal5_pdu_errs,
546                         stats->st_aal5.aal5_pdu_drops);
547 }
548
549
550 /*
551  * Print Fore ASX-200 device driver statistics
552  * 
553  * Arguments:
554  *      vi      pointer to vendor-specific statistics to print
555  *
556  * Returns:
557  *      none
558  *
559  */
560 static void
561 print_fore200_driver(struct air_vinfo_rsp *vi)
562 {
563         Fore_stats      *stats;
564
565         /*
566          * Bump stats pointer past header info
567          */
568         stats = (Fore_stats *)
569                         ((u_long) vi + sizeof(struct air_vinfo_rsp));
570
571         /*
572          * Print a header
573          */
574         printf(DRIVER_STATS_HDR, get_adapter_name(vi->avsp_intf));
575         
576         /*
577          * Print the driver info
578          */
579         printf("%4ld  %4ld  %4ld  %4ld  %4ld  %4ld  %4ld  %4ld  %4ld  %4ld  %4ld  %4ld  %4ld\n",
580                         stats->st_drv.drv_xm_notact,
581                         stats->st_drv.drv_xm_full,
582                         stats->st_drv.drv_xm_maxpdu,
583                         stats->st_drv.drv_xm_segnoal,
584                         stats->st_drv.drv_xm_seglen,
585                         stats->st_drv.drv_xm_segdma,
586                         stats->st_drv.drv_rv_novcc,
587                         stats->st_drv.drv_rv_nosbf,
588                         stats->st_drv.drv_rv_nomb,
589                         stats->st_drv.drv_rv_ifull,
590                         stats->st_drv.drv_bf_segdma,
591                         stats->st_drv.drv_cm_full,
592                         stats->st_drv.drv_cm_nodma);
593
594 }