2 * Copyright (c) 2001-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * Author: Hartmut Brandt <harti@freebsd.org>
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/types.h>
33 #include <sys/sysctl.h>
34 #include <sys/ioctl.h>
35 #include <sys/socket.h>
36 #include <sys/queue.h>
38 #include <net/if_mib.h>
39 #include <net/if_types.h>
40 #include <net/if_atm.h>
41 #include <net/if_media.h>
42 #include <netnatm/natm.h>
43 #include <dev/utopia/utopia.h>
44 #include <dev/utopia/suni.h>
45 #include <dev/utopia/idtphy.h>
47 #include "atmconfig.h"
51 static void diag_list(int, char *[]);
52 static void diag_config(int, char *[]);
53 static void diag_vcc(int, char *[]);
54 static void diag_phy_show(int, char *[]);
55 static void diag_phy_set(int, char *[]);
56 static void diag_phy_print(int, char *[]);
57 static void diag_phy_stats(int, char *[]);
58 static void diag_stats(int, char *[]);
60 static const struct cmdtab diag_phy_tab[] = {
61 { "show", NULL, diag_phy_show },
62 { "set", NULL, diag_phy_set },
63 { "stats", NULL, diag_phy_stats },
64 { "print", NULL, diag_phy_print },
68 const struct cmdtab diag_tab[] = {
69 { "list", NULL, diag_list },
70 { "config", NULL, diag_config },
71 { "phy", diag_phy_tab, NULL },
72 { "stats", NULL, diag_stats },
73 { "vcc", NULL, diag_vcc },
77 static const struct utopia_print suni_lite[] = { SUNI_PRINT_LITE };
78 static const struct utopia_print suni_ultra[] = { SUNI_PRINT_ULTRA };
79 static const struct utopia_print suni_622[] = { SUNI_PRINT_622 };
80 static const struct utopia_print idt77105[] = { IDTPHY_PRINT_77105 };
81 static const struct utopia_print idt77155[] = { IDTPHY_PRINT_77155 };
84 const struct utopia_print *tab;
88 { suni_lite, sizeof(suni_lite) / sizeof(suni_lite[0]),
90 { suni_ultra, sizeof(suni_ultra) / sizeof(suni_ultra[0]),
91 UTP_TYPE_SUNI_ULTRA },
92 { suni_622, sizeof(suni_622) / sizeof(suni_622[0]),
94 { idt77105, sizeof(idt77105) / sizeof(idt77105[0]),
96 { idt77155, sizeof(idt77155) / sizeof(idt77155[0]),
100 static const u_int utopia_addreg[] = { UTP_REG_ADD };
103 * Driver statistics printing
105 static const char *const print_stats_pca200e[] = {
112 "tx_queue_almost_full:",
127 static const char *const print_stats_he[] = {
158 static const char *const print_stats_eni[] = {
180 static const char *const print_stats_idt77211[] = {
189 static const char *const print_stats_idt77252[] = {
199 static const char *const print_stats_virtual[] = {
203 static const char *const *const print_stats[] = {
204 [ATM_DEVICE_UNKNOWN] = NULL,
205 [ATM_DEVICE_PCA200E] = print_stats_pca200e,
206 [ATM_DEVICE_HE155] = print_stats_he,
207 [ATM_DEVICE_HE622] = print_stats_he,
208 [ATM_DEVICE_ENI155P] = print_stats_eni,
209 [ATM_DEVICE_ADP155P] = print_stats_eni,
210 [ATM_DEVICE_FORELE25] = print_stats_idt77211,
211 [ATM_DEVICE_FORELE155] = print_stats_idt77211,
212 [ATM_DEVICE_NICSTAR25] = print_stats_idt77211,
213 [ATM_DEVICE_NICSTAR155] = print_stats_idt77211,
214 [ATM_DEVICE_IDTABR25] = print_stats_idt77252,
215 [ATM_DEVICE_IDTABR155] = print_stats_idt77252,
216 [ATM_DEVICE_PROATM25] = print_stats_idt77252,
217 [ATM_DEVICE_PROATM155] = print_stats_idt77252,
218 [ATM_DEVICE_VIRTUAL] = print_stats_virtual,
221 struct diagif_list diagif_list = TAILQ_HEAD_INITIALIZER(diagif_list);
227 phy_fetch(const char *ifname, const char *var, void *val, size_t len,
232 if (asprintf(&str, "hw.atm.%s.phy_%s", ifname, var) == -1)
234 if (sysctlbyname(str, val, &len, NULL, 0) == -1) {
235 if (err_fatal || errno != ENOENT)
245 * Fetch the list of all ATM network interfaces and their MIBs.
253 struct ifmibdata mib;
254 struct ifatm_mib atm;
258 while ((d = TAILQ_FIRST(&diagif_list)) != NULL) {
261 TAILQ_REMOVE(&diagif_list, d, link);
266 if (sysctlbyname("net.link.generic.system.ifcount", &count, &len,
272 name[2] = NETLINK_GENERIC;
273 name[3] = IFMIB_IFDATA;
275 for (idx = 1; idx <= count; idx++) {
277 name[5] = IFDATA_GENERAL;
279 if (sysctl(name, 6, &mib, &len, NULL, 0) == -1)
280 err(1, "interface %d: general mib", idx);
281 if (mib.ifmd_data.ifi_type == IFT_ATM) {
282 name[5] = IFDATA_LINKSPECIFIC;
284 if (sysctl(name, 6, &atm, &len, NULL, 0) == -1)
285 err(1, "interface %d: ATM mib", idx);
287 d = malloc(sizeof(*d));
290 bzero(d, sizeof(*d));
293 strcpy(d->ifname, mib.ifmd_name);
294 TAILQ_INSERT_TAIL(&diagif_list, d, link);
296 if (phy_fetch(d->ifname, "type", &d->phy_type,
297 sizeof(d->phy_type), 0) == 0) {
299 phy_fetch(d->ifname, "loopback",
301 sizeof(d->phy_loopback), 1);
302 phy_fetch(d->ifname, "name", &d->phy_name,
303 sizeof(d->phy_name), 1);
304 phy_fetch(d->ifname, "state", &d->phy_state,
305 sizeof(d->phy_state), 1);
306 phy_fetch(d->ifname, "carrier", &d->phy_carrier,
307 sizeof(d->phy_carrier), 1);
314 * "<radix><bit>STRING\011<mask><pattern>STRING\012<mask><radix>STRING"
317 printb8(uint32_t val, const char *descr)
319 static char buffer[1000];
322 u_char mask, pattern;
324 if (*descr++ == '\010')
325 sprintf(buffer, "%#o", val);
327 sprintf(buffer, "%#x", val);
328 ptr = buffer + strlen(buffer);
332 if (*descr == '\11') {
336 if ((val & mask) == pattern) {
339 while (*descr >= ' ')
342 while (*descr >= ' ')
345 } else if (*descr == '\12') {
351 while (*descr >= ' ')
356 (val & mask) >> (ffs(mask)-1));
357 else if (pattern == 10)
359 (val & mask) >> (ffs(mask)-1));
362 (val & mask) >> (ffs(mask)-1));
365 if (val & (1 << (*descr++ - 1))) {
368 while (*descr >= ' ')
371 while (*descr >= ' ')
383 * "<radix><bit>STRING<bit>STRING"
386 printb(uint32_t val, const char *descr)
388 static char buffer[1000];
392 if (*descr++ == '\010')
393 sprintf(buffer, "%#o", val);
395 sprintf(buffer, "%#x", val);
396 ptr = buffer + strlen(buffer);
400 if (val & (1 << (*descr++ - 1))) {
418 diag_loop(int argc, char *argv[], const char *text,
419 void (*func)(const struct diagif *))
426 for (i = 0; i < argc; i++) {
427 TAILQ_FOREACH(aif, &diagif_list, link) {
428 if (strcmp(argv[i], aif->ifname) == 0) {
435 warnx("%s: no such ATM interface", argv[i]);
438 TAILQ_FOREACH(aif, &diagif_list, link) {
446 * Print the config line for the given interface
449 config_line1(const struct diagif *aif)
451 printf("%-6u%-9s%-8u%-5u%-6u%-5u%-6u%02x:%02x:%02x:%02x:%02x:%02x\n",
452 aif->index, aif->ifname, aif->mib.pcr, (1 << aif->mib.vpi_bits) - 1,
453 (1 << aif->mib.vci_bits) - 1, aif->mib.max_vpcs, aif->mib.max_vccs,
454 aif->mib.esi[0], aif->mib.esi[1], aif->mib.esi[2],
455 aif->mib.esi[3], aif->mib.esi[4], aif->mib.esi[5]);
459 config_line2(const struct diagif *aif)
463 static const struct {
469 static const struct {
471 const char *const name;
472 } medias[] = IFM_SUBTYPE_ATM_DESCRIPTIONS;
474 for (i = 0; medias[i].name; i++)
475 if (aif->mib.media == medias[i].media)
478 if ((d = aif->mib.device) >= sizeof(devs) / sizeof(devs[0]))
481 printf("%-6u%-9s%-12.11s%-13.12s%-8u%-6x%-6x %s\n", aif->index,
482 aif->ifname, devs[d].vendor, devs[d].dev, aif->mib.serial,
483 aif->mib.hw_version, aif->mib.sw_version,
484 medias[i].name ? medias[i].name : "unknown");
488 diag_config(int argc, char *argv[])
495 static const struct option opts[] = {
496 { "hardware", OPT_SIMPLE, &hardware },
497 { "atm", OPT_SIMPLE, &atm },
501 static const char config_text1[] =
502 "Interface Max Max\n"
503 "Index Name PCR VPI VCI VPCs VCCs ESI\n";
504 static const char config_text2[] =
505 "Interface Version\n"
506 "Index Name Vendor Card "
507 "Serial HW SW Media\n";
509 while ((opt = parse_options(&argc, &argv, opts)) != -1)
514 if (TAILQ_EMPTY(&diagif_list))
515 errx(1, "no ATM interfaces found");
517 if (!atm && !hardware)
521 diag_loop(argc, argv, config_text1, config_line1);
523 diag_loop(argc, argv, config_text2, config_line2);
528 diag_list(int argc, char *argv[])
533 static const struct option opts[] = {
537 while ((opt = parse_options(&argc, &argv, opts)) != -1)
542 errx(1, "no arguments required for 'diag list'");
545 if (TAILQ_EMPTY(&diagif_list))
546 errx(1, "no ATM interfaces found");
548 TAILQ_FOREACH(aif, &diagif_list, link)
549 printf("%s ", aif->ifname);
554 * Print the config line for the given interface
557 phy_show_line(const struct diagif *aif)
559 printf("%-6u%-9s", aif->index, aif->ifname);
560 if (aif->phy_present)
561 printf("%-5u%-25s0x%-9x", aif->phy_type,
562 aif->phy_name, aif->phy_loopback);
567 diag_phy_show(int argc, char *argv[])
571 static const struct option opts[] = {
575 static const char phy_show_text[] =
577 "Index Name Type Name Loopback State\n";
579 while ((opt = parse_options(&argc, &argv, opts)) != -1)
584 if (TAILQ_EMPTY(&diagif_list))
585 errx(1, "no ATM interfaces found");
587 diag_loop(argc, argv, phy_show_text, phy_show_line);
591 * Make sure the interface exists and has a phy
593 static struct diagif *
594 diagif_get_phy(const char *arg)
599 TAILQ_FOREACH(aif, &diagif_list, link)
600 if (strcmp(aif->ifname, arg) == 0)
603 errx(1, "no such interface: %s", arg);
604 if (!aif->phy_present)
605 errx(1, "interface %s has no phy", arg);
611 diag_phy_set(int argc, char *argv[])
619 static const struct option opts[] = {
623 while ((opt = parse_options(&argc, &argv, opts)) != -1)
628 errx(1, "missing arguments for 'diag phy set'");
631 res = strtoul(argv[1], &end, 0);
633 err(1, "register number");
635 errx(1, "malformed register number '%s'", argv[1]);
637 errx(1, "register number too large");
641 res = strtoul(argv[2], &end, 0);
645 errx(1, "malformed mask '%s'", argv[1]);
647 errx(1, "mask too large");
651 res = strtoul(argv[3], &end, 0);
655 errx(1, "malformed value '%s'", argv[1]);
657 errx(1, "value too large");
660 (void)diagif_get_phy(argv[0]);
662 if (asprintf(&str, "hw.atm.%s.phy_regs", argv[0]) == -1)
665 if (sysctlbyname(str, NULL, NULL, reg, 3 * sizeof(uint8_t)))
672 diag_phy_print(int argc, char *argv[])
679 const struct utopia_print *p;
683 static const struct option opts[] = {
684 { "numeric", OPT_SIMPLE, &numeric },
688 while ((opt = parse_options(&argc, &argv, opts)) != -1)
693 errx(1, "need device name for 'diag phy print'");
695 (void)diagif_get_phy(argv[0]);
697 if (asprintf(&str, "hw.atm.%s.phy_regs", argv[0]) == -1)
700 if (sysctlbyname(str, NULL, &len, NULL, 0))
701 err(1, "'%s' not found", str);
707 if (sysctlbyname(str, regs, &len, NULL, 0))
708 err(1, "'%s' not found", str);
712 for (i = 0; i < len; i++) {
717 printf(" %02x", regs[i]);
724 if (asprintf(&str, "hw.atm.%s.phy_type", argv[0]) == -1)
727 if (sysctlbyname(str, &type, &len1, NULL, 0))
728 err(1, "'%s' not found", str);
731 for (i = 0; i < sizeof(phy_print) / sizeof(phy_print[0]); i++)
732 if (type == phy_print[i].type)
734 if (i == sizeof(phy_print) / sizeof(phy_print[0]))
735 errx(1, "unknown PHY chip type %u\n", type);
737 for (p = phy_print[i].tab;
738 p < phy_print[i].tab + phy_print[i].len;
740 if (p->reg + utopia_addreg[p->type] > len)
741 /* don't have this register */
744 printf("%s:%*s", p->name, 40 - (int)strlen(p->name),"");
749 printf("%s\n", printb8(regs[p->reg], p->fmt));
753 printf("%#x\n", regs[p->reg]);
756 case UTP_REGT_INT10BITS:
757 printf("%#x %s\n", regs[p->reg] |
758 ((regs[p->reg + 1] & 0x3) << 8),
759 printb8(regs[p->reg + 1], p->fmt));
763 printf("%#x\n", regs[p->reg] |
764 ((regs[p->reg + 1] & 0xf) << 8));
768 printf("%#x\n", regs[p->reg] |
769 (regs[p->reg + 1] << 8));
773 printf("%#x\n", regs[p->reg] |
774 (regs[p->reg + 1] << 8) |
775 ((regs[p->reg + 2] & 0x7) << 16));
779 printf("%#x\n", regs[p->reg] |
780 (regs[p->reg + 1] << 8) |
781 ((regs[p->reg + 2] & 0xf) << 16));
785 printf("%#x\n", regs[p->reg] |
786 (regs[p->reg + 1] << 8) |
787 ((regs[p->reg + 2] & 0x1f) << 16));
799 diag_phy_stats(int argc, char *argv[])
804 struct utopia_stats1 stats1;
809 static const struct option opts[] = {
810 { "clear", OPT_SIMPLE, &clear },
814 while ((opt = parse_options(&argc, &argv, opts)) != -1)
819 errx(1, "need device name for 'diag phy stats'");
821 (void)diagif_get_phy(argv[0]);
823 if (asprintf(&str, "hw.atm.%s.phy_stats", argv[0]) == -1)
826 len = sizeof(stats1);
827 if (sysctlbyname(str, &stats1, &len,
828 clear ? &foo : NULL, clear ? sizeof(foo) : 0))
829 err(1, "'%s' not found", str);
830 if (len < sizeof(stats1.version))
831 errx(1, "phy statistics too short %zu", len);
833 switch (stats1.version) {
836 if (len != sizeof(stats1))
837 errx(1, "bad phy stats length %zu (expecting %zu)",
838 len, sizeof(stats1));
842 errx(1, "unknown phy stats version %u", stats1.version);
847 printf("rx_sbip: %llu\n", (unsigned long long)stats1.rx_sbip);
848 printf("rx_lbip: %llu\n", (unsigned long long)stats1.rx_lbip);
849 printf("rx_lfebe: %llu\n", (unsigned long long)stats1.rx_lfebe);
850 printf("rx_pbip: %llu\n", (unsigned long long)stats1.rx_pbip);
851 printf("rx_pfebe: %llu\n", (unsigned long long)stats1.rx_pfebe);
852 printf("rx_cells: %llu\n", (unsigned long long)stats1.rx_cells);
853 printf("rx_corr: %llu\n", (unsigned long long)stats1.rx_corr);
854 printf("rx_uncorr: %llu\n", (unsigned long long)stats1.rx_uncorr);
855 printf("rx_symerr: %llu\n", (unsigned long long)stats1.rx_symerr);
856 printf("tx_cells: %llu\n", (unsigned long long)stats1.tx_cells);
860 * Fetch the table of open vccs
863 diagif_fetch_vcc(struct diagif *aif, int fd)
867 if (aif->vtab != NULL)
870 strncpy(ifr.ifr_name, aif->ifname, IFNAMSIZ);
871 ifr.ifr_name[IFNAMSIZ - 1] = '\0';
873 aif->vtab = malloc(sizeof(*aif->vtab) + sizeof(aif->vtab->vccs[0]) *
875 if (aif->vtab == NULL)
877 ifr.ifr_data = (caddr_t)aif->vtab;
879 if (ioctl(fd, SIOCATMGVCCS, &ifr) == -1)
880 err(1, "SIOCATMGVCCS");
884 * Print the VCC table for this interface.
887 print_channel(const struct diagif *aif)
889 const struct atmio_vcc *v;
891 static const char *const aal_tab[] = {
893 [ATMIO_AAL_34] = "3/4",
895 [ATMIO_AAL_RAW] = "raw",
897 static const char *const traffic_tab[] = {
898 [ATMIO_TRAFFIC_UBR] = "ubr",
899 [ATMIO_TRAFFIC_CBR] = "cbr",
900 [ATMIO_TRAFFIC_ABR] = "abr",
901 [ATMIO_TRAFFIC_VBR] = "vbr",
904 for (v = aif->vtab->vccs; v < &aif->vtab->vccs[aif->vtab->count]; v++) {
905 printf("%-6u%-9s%-4u%-6u", aif->index, aif->ifname,
908 if (v->aal >= sizeof(aal_tab)/sizeof(aal_tab[0]) ||
909 aal_tab[v->aal] == NULL)
912 printf("%-4s", aal_tab[v->aal]);
914 if (v->traffic >= sizeof(traffic_tab)/sizeof(traffic_tab[0]) ||
915 traffic_tab[v->traffic] == NULL)
918 printf("%-8s", traffic_tab[v->traffic]);
920 printf("%-6u%-6u%s\n", v->rmtu, v->tmtu,
921 printb(v->flags, ATMIO_FLAGS));
926 * Print the VCC table for this interface, traffic parameters.
929 print_traffic(const struct diagif *aif)
931 const struct atmio_vcc *v;
933 for (v = aif->vtab->vccs; v < &aif->vtab->vccs[aif->vtab->count]; v++) {
934 printf("%-6u%-9s%-4u%-6u", aif->index, aif->ifname,
937 switch (v->traffic) {
939 case ATMIO_TRAFFIC_CBR:
940 printf("%u", v->tparam.pcr);
943 case ATMIO_TRAFFIC_UBR:
944 printf("%-8u %u", v->tparam.pcr,
948 case ATMIO_TRAFFIC_VBR:
949 printf("%-8u%-8u%-8u", v->tparam.pcr, v->tparam.scr,
953 case ATMIO_TRAFFIC_ABR:
955 v->tparam.pcr, v->tparam.mcr);
963 * Print the VCC table for this interface, ABR traffic parameters.
966 print_abr(const struct diagif *aif)
968 const struct atmio_vcc *v;
970 for (v = aif->vtab->vccs; v < &aif->vtab->vccs[aif->vtab->count]; v++) {
971 printf("%-6u%-9s%-4u%-6u", aif->index, aif->ifname,
974 if (v->traffic == ATMIO_TRAFFIC_ABR) {
975 printf("%-8u%-8u%-4u%-4u%-5u%-5u%-5u%u",
976 v->tparam.icr, v->tparam.tbe, v->tparam.nrm,
977 v->tparam.trm, v->tparam.adtf, v->tparam.rif,
978 v->tparam.rdf, v->tparam.cdf);
985 diag_vcc_loop(void (*func)(const struct diagif *), const char *text,
986 int argc, char *argv[], int fd)
992 TAILQ_FOREACH(aif, &diagif_list, link) {
993 diagif_fetch_vcc(aif, fd);
994 if (aif->vtab->count != 0) {
1001 for (optind = 0; optind < argc; optind++) {
1002 TAILQ_FOREACH(aif, &diagif_list, link)
1003 if (strcmp(aif->ifname, argv[optind]) == 0) {
1004 diagif_fetch_vcc(aif, fd);
1005 if (aif->vtab->count != 0) {
1006 heading("%s", text);
1012 warnx("no such interface '%s'", argv[optind]);
1018 diag_vcc(int argc, char *argv[])
1022 static int channel, traffic, abr;
1023 static const struct option opts[] = {
1024 { "abr", OPT_SIMPLE, &abr },
1025 { "channel", OPT_SIMPLE, &channel },
1026 { "traffic", OPT_SIMPLE, &traffic },
1029 static const char head_channel[] =
1031 "Index Name VPI VCI AAL Traffic RxMTU TxMTU Flags\n";
1032 static const char head_traffic[] =
1033 "Interface Traffic parameters\n"
1034 "Index Name VPI VCI PCR SCR MBS MCR\n";
1035 static const char head_abr[] =
1036 "Interface ABR traffic parameters\n"
1037 "Index Name VPI VCI ICR TBE NRM TRM ADTF RIF RDF "
1040 while ((opt = parse_options(&argc, &argv, opts)) != -1)
1044 fd = socket(PF_NATM, SOCK_STREAM, PROTO_NATMAAL5);
1049 if (TAILQ_EMPTY(&diagif_list))
1050 errx(1, "no ATM interfaces found");
1052 if (!channel && !traffic && !abr)
1056 diag_vcc_loop(print_channel, head_channel, argc, argv, fd);
1058 diag_vcc_loop(print_traffic, head_traffic, argc, argv, fd);
1060 diag_vcc_loop(print_abr, head_abr, argc, argv, fd);
1064 * Print driver-internal statistics
1067 diag_stats(int argc, char *argv[])
1076 static const struct option opts[] = {
1080 while ((opt = parse_options(&argc, &argv, opts)) != -1)
1085 errx(1, "need one arg for 'diag stats'");
1088 TAILQ_FOREACH(aif, &diagif_list, link)
1089 if (strcmp(aif->ifname, argv[0]) == 0)
1093 errx(1, "interface '%s' not found", argv[0]);
1095 if (asprintf(&str, "hw.atm.%s.istats", argv[0]) == -1)
1098 if (sysctlbyname(str, NULL, &len, NULL, 0))
1099 err(1, "'%s' not found", str);
1101 stats = malloc(len);
1105 if (sysctlbyname(str, stats, &len, NULL, 0))
1106 err(1, "'%s' not found", str);
1109 if (aif->mib.device >= sizeof(print_stats) / sizeof(print_stats[0]) ||
1110 print_stats[aif->mib.device] == NULL)
1111 errx(1, "unknown stats format (%u)", aif->mib.device);
1113 for (i = 0; print_stats[aif->mib.device][i] != NULL; i++) {
1114 if (i * sizeof(uint32_t) >= len)
1115 errx(1, "debug info too short (version mismatch?)");
1116 printf("%-22s%u\n", print_stats[aif->mib.device][i], stats[i]);
1120 if (i != len / sizeof(uint32_t))
1121 errx(1, "debug info too long (version mismatch?)");